Highlighted
Occasional Contributor

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/883833FE74FA4CE58969A... --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

6 REPLIES 6
Highlighted
New Contributor

Re: Anaplan REST - issue uploading file

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/75A40874E6B64FA3AE074... --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/{...} --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!

Highlighted
New Contributor

Re: Anaplan REST - issue uploading file

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)

Highlighted
Community Boss

Re: Anaplan REST - issue uploading file

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!



Jesse Wilson
Solution Architect - Data Integrations
Singapore
Highlighted
Community Boss

Re: Anaplan REST - issue uploading file

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.
Highlighted
New Contributor

Re: Anaplan REST - issue uploading file

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.

 

Highlighted
New Contributor

Re: Anaplan REST - issue uploading file

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.