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.

Answers

  • 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-workspaces-as-a-json-array

     

    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.

  • 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

  • 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-chunk?console=1

     

    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

     

     

  • 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.
  • 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

  • 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

  • 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.
  • With binary I got:

    404404

  • 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.
  • Hi,

     

    aah, you are very perspicacious. So the 112's are Imports and 113's are files. 

    Now I have probably uploaded the file. Next I'll try to import it

    Postman3.JPG

     

     

  • Hi,

     

    Now the whole path works! To document whole path, here is the Import task. That went trough without any complications. Thank you @ben_speight

      ImportImport

     

     

     

  • Hi All,

     

    I am getting the same error. I repeated the steps as suggested by Henri. 

    Below is the URL I am using. 


    https://api.anaplan.com/2/0/workspaces/8a81b09e63c2cc250163ff2e7b4241f7/models/8AF6BC4728714882B6DB09A13246F867/files/113000000009/

    This is what I am doing to upload the file. This is Postman tool.

    CommunityMember128681_0-1586786761185.png