Uploading file via REST API/Python
Hi, I am working on an item that uploads .csv file into Anaplan. I'm not sure why the upload doesn't work even if the response of API is successful. I've tried using some codes posted here but seems the upload does not work (download, import seems okay)
I'm using basic authentication and 1.3 version of the API.
Here is a snippet of the code
user = AnaplanUtils.create_auth_session() file_id = '123' file_name = 'test.csv' url_file = api_url + 'files/' url_complete = url_file + "/complete" file_metadata_start = { "id": file_id, "chunkCount": -1 } file_metadata_complete = { "id": file_id, "chunkCount": -1 } start_upload_post = requests.post(url_file, headers=build_headers(user, 'application/json') , json=file_metadata_start) file_data = open(file_name, "r").read().encode('utf-8') if start_upload_post.ok: file_upload = requests.put(url_file, headers=build_headers(user, 'application/octet-stream'), data=file_data) if file_upload.ok: complete_upload = requests.post(url_complete, headers=build_headers(user, 'application/json') , json=file_metadata_complete) if complete_upload.ok: print('success') else: print('There was an issue with your file upload: ' + str(complete_upload.status_code)) else: print('There was an issue with your file upload: ' + str(file_upload.status_code))
Comments
-
Hi Nathan,
Because the data on the file is not being reflected on Anaplan (I always check on UI after executing the code but no change is happening).
I'm not sure if I'm doing it correctly on my code.
0 -
The target table is already created(created by another user) but the import is created using my account and the credentials in the API is the same.
I tried to print the text response of the complete API, seems it returned the details of the import data source which is expected and http response is 200
0
Categories
- All Categories
- 2.3K Anaplan Community
- Academy
- Anaplan Talent Builder
- Model Design Course
- The Anaplan Way
- Archive
- 2 Idea exchange
- 62 Enterprise Scale
- 1.1K Extensibility
- 21 Intelligence
- 1.6K Planning & Modeling
- 331 Security
- Community Connections
- Connections
- Experiences
- Groups
- Personas
- Employees
- CS Toolkit
- Customer Care Center
- Forums
- Academy & Training
- Community Feedback & Updates
- Japan
- Anaplan Community Japan
- Anaplan Community Japan Knowledge Base
- HyperCare Japan
- JP-Central
- Support-Japanese
- Partners
- Partner Leadership Council
- Partner Product Council
- 724 Platform
- Anapedia
- App Hub
- Centers Of Excellence
- Extensions
- Planual
- Platform Updates
- 724 User Experience
- Profile Builder
- Resources
- Anaplan Advocates
- Anaplan Live!
- Community
- Community Advancement
- Community Connections
- Partner Program
- The Official Master Anaplanner Program
- Videos
- Welcome to the Anaplan Community!
- Success Central
- Support
- Case Portal Link
- Common Support Questions
- HyperCare Redirect
- Known Issues and Workarounds
- Support test page
- SupportFAQ
- Survey
- 2 Training Day Takeaways