Anaplan REST - issue uploading file
Hi,
I'm not Anaplan guy but doing an integation with Anaplan through the REST API.
Export of data works fine.
Issues come with the import. As first step, we have to upload the file.
We are using PowerShell but any feedback if other language is also welcome.
My question is: shall we use --upload-file in the url. In the API guide I can see xxx is the import file name. This is what we get from files REST resource:
id : 113000000010
name : Import to FDMEE template
chunkCount : 1
delimiter : "
encoding : ISO-8859-1
firstDataRow : 2
format : txt
headerRow : 1
separator : ,
Error when uploading
https://api.anaplan.com/1/3/workspaces/8a81b08e4f13b5e3014f281bcca564e9/models/883833FE74FA4CE58969ADD043C630CA/files/113000000010 --upload-file xxx
Invoke-RestMethod :
Anaplan
@import "lib/dojo/resources/dojo.css";
html {
overflow: auto;
}
An error has occurred whilst processing your request:
Not Found
Please close your browser window and try again.
If the problem persists then please contact Anaplan Support.
At C:\REST_Tester_Import.ps1:199 char:17
+ ... tResponse = Invoke-RestMethod -Uri $uri -Method Put -InFile $csvImpor ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Answers
-
An answer to this would be great. Following along in the apiary docs... there are two URLs listed in the Python example for the mock workspace:
values = """ curl https://api.anaplan.com/1/3/workspaces/8a8196b15b7dbae6015b8694411d13fe/models/75A40874E6B64FA3AE0743278996850F/files/113000000008 --upload-file Tests.txt"""
headers = { 'Authorization': 'Basic encoded_username:password',
'Content-Type': 'application/octet-stream'
}
request = Request('https://private-3a7075-anaplan.apiary-mock.com/1/3/workspaces/{workspaceID}/models/{modelID}/files/{fileId} --upload-file Tests.txt', data=values, headers=headers) request.get_method = lambda: 'PUT'
response_body = urlopen(request).read()
print response_body
Do we ping the api.anaplan.com/1/3 site twice? Or as shown here?
Can't get it to work in my script because only have an us1a.app.anaplan.com. So am I pinging my us1a server twice? Or api.anaplan.com and then us1a?
Does the --upload-file Test.txt belong in both url calls?
@famores, have you solved this?
For Anaplan: an upgrade to urllib3 would be great in the docs as urllib2 is no longer the hotness.Thanks!
0 -
I couldn't get it to work either.
Finally resolved to go the curl route
def uploadFileCurl(workspaceId, modelId, fileId, localFileName, remoteFileName) :
curlcmd = """
curl -v --include \
--request PUT \
--header "Authorization: $cer" \
--header "Content-Type: application/octet-stream" \
--data-binary '@$localfile' \
"https://api.anaplan.com/1/3/workspaces/$workspaceId/models/$modelId/files/$fileId --upload-file $filename"
"""
s = Template(curlcmd)
cmdstr = s.substitute( cer=cer, localfile=localFileName, workspaceId=workspaceId, modelId=modelId, fileId=fileId, filename=remoteFileName )
print("Command to execute is [" + cmdstr + "]")
os.system(cmdstr)0 -
I wanted to note on this, I checked our Apiary documentation and I see syntax for cURL requests for uploading files is not what I would expect. As noted above, --data-binary is the correct option to use for local files; altnernatively, if you're passing in raw data you would use --data.
I will follow up with our documentation team to ensure this is corrected as soon as possible.
Thanks for pointing this out!
0 -
No. --upload-file is a parameter specific to the cURL utility to tell it to use the specified file as the request body. It looks like you're acheiving this using "-Method Put -InFile <file>" with the tool you're using.0
-
Hello
I am sharing blog URL of informatica read rest api task, where the complete task is discussed in proper way with step by step. Check it out here,
https://zappysys.com/blog/read-json-informatica-import-rest-api-json-file/
Hope it will be helpful.
0 -
Hello
I am sharing blog URL of Informatica read rest API task, where the complete task is discussed in proper way with step by step. Check it out here,
https://zappysys.com/blog/read-json-informatica-import-rest-api-json-file/
Hope it will be helpful.
0