Understanding the APIs of Anaplan particulary using the Upload API from http client

Highlighted
New Contributor

Understanding the APIs of Anaplan particulary using the Upload API from http client

I am looking to integrate Oracle SOA with Anaplan, specifically my requirement is to feed data from a Oracle SOA BPEL to Anaplan.

I have gone through the Anaplan API documentation and looking to use Upload and Import APIs.Approach I am planning to follow is write the content from Oracle SOA to a file and then upload that file to the Anaplan server.I have created a sample file from the Anaplan UI.

My questions are:

1.Is it possible to use these APIs from http client, to start with I am testing these APIs using Postman.I could call the Get File ID API to get the file Id of the sample file I have created in Anaplan.But I am not successful in executing  the Upload API to upload the file from local.

2.How to specify the local file path in the Upload API.As I see the format of the API as 'https://api.anaplan.com/1/3/workspaces/workspaceID/models/modelID/files/fileId --upload-file Tests.txt' , how can the upload file name can be specified like this  --upload-file Tests.txt from http client. If I run it, I get error 

<div id="pageWrap" class="pageWrap">
<div class="banner">
<h1>An error has occurred whilst processing your request:</h1>
</div>
<div>
<pre class="original">Not Found</pre>
</div>
<div>Please close your browser window and try again.</div>
<div>If the problem persists then please contact Anaplan Support.</div>
</div>

 

Please help in getting this implemented.

12 REPLIES 12
Highlighted
Community Boss

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

Hi,

 

1: yes it does work from postman.

In the documentation you also have an incorporated web client

https://anaplan.docs.apiary.io/#reference/workspaces/list-the-workspaces-as-a-json-array/list-the-wo...

 

2: I don't know if it's the only solution but when I upload a file I do open the content of that file in my script and then send it as the body of the http request.


Nathan Rudman, Anaplan Model Builder
Highlighted
New Contributor

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

Thanks Nathan for the response.

 

The link you shared for the incorporated webclient is taking me to the API that lists the workspace ID and not to the information about the webclient.

 

As I have a little knoweldge about Anaplan and the scripts, I am assuming from your response that when we send the Upload request from Postman, the https://api.anaplan.com/1/3/workspaces/workspaceID/models/modelID/files/fileId  has to be called with the content of file added in some format in the body.

I would be great if you can share me a sample script which send the content(in the expected format) as the body of the request

 

Thanks,

Divya

Highlighted
Community Boss

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

yes, I was just point to my own bookmark, upload is here:

https://anaplan.docs.apiary.io/#reference/upload-files/upload-file-as-a-single-chunk/upload-a-single...

 

If you want to run that upload from POSTMAN, I believe you need to put the actual content of the file inside the body.

It's probably a CSV so just copy in there the text

 

 


Nathan Rudman, Anaplan Model Builder
Highlighted
Community Boss

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

The key things you need to know are: 1. The HTTP request must be a PUT request, not a GET or POST. 2. The workspaceID, modelID and fileID in the URL path must all be valid and accessible to you. 3. The body of the request must contain the content you want to upload. How you achieve this depends on the tools you're using. The "--upload-file Tests.txt" bit is what you what pass on the command line when using the cURL utility to tell it to include the file in the request body (and also to use a PUT) - but only cURL understands that. If you can tell us exactly what your "http client" is then I'll try to give more specific advice.
Highlighted
New Contributor

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

I am currently using Postman to try out these APIs.I have the valid workspace Id and Model ID and using which I could call the GetFileID API and I could see the fileID of the file I am looking to upload.

As you mentioned ' The body of the request must contain the content you want to upload', this is what I am not clear with, should the file be send as attchment to the Upload API(PUT operation) or if the content has to be in the body what should be the content type and the format of the content.

As Nathan suggested, I tried to paste the content in body but it threw htpp 415 error, Unsupported Media Type.

 

Thanks,

Divya

Highlighted
Occasional Contributor

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

Hi @ben_speight and @DivyaHabin

I'm trying to understand the same thing and here is what I did
1.) I have my Workspace, Model and File defined in request 

2.) In headers I have Authorization and Content-Type defined (Basic and application/octet-stream)

3) In body I put --upload -file to key and attached file as value since in Postman you can do that

End result looks like this:
PostmanPostman

 

Any ideas what I can try next?

 

By the way, I am trying to upload material from 102 Introduction to Model Building (1.0) to its workspace, so if we can get ths working, it will be nice example for new Anaplanners

Community Boss

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

Ah ok. Here you're telling it to send it as if it were a HTML form submitted by a browser. Either the raw (if you're entering/pasting CSV data directly into Postman) or binary (if you're sending a file) radio option needs to be selected. The --upload-file option is used by cURL, not Postman.
Highlighted
Occasional Contributor

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

With binary I got:

404404

Highlighted
Community Boss

Re: Understanding the APIs of Anaplan particulary using the Upload API from http client

You're getting closer. Your file ID is incorrect - you need to pass in the ID of the file as given by the /files endpoint. It looks like you've passed in an import ID from /imports instead. If you're uploading the file in one go, you should remove the /chunks/0 part and perform the upload as a single PUT. Chunked uploads are good for resumable and/or compressed uploads, but have a more complex API.