Contributor

Requesting File ID from Rest API Throws 500 Internal Server Error

Hello,

 

I've been attempting to get the file ID from a model using the following curl code adapted from the Anaplan API docs in Apiary.

 

 

curl -v --include --header "Authorization: Basic encoded_username:password"
--header "Content-Type: application/json" "https://api.anaplan.com/1/3/workspaces/8a81b09c637a13f70163989092ab080f/models/BB491FD8A9342FF815249BCD6C58B7A/files"

 

 

Note: I am actually using the Base64 encoded form of my login credentials, only left the pseudo-code in there for obvious reasons.

 

When running this script I've only been able to get a 500 Internal Server Error and the HTML code for the webpage that I would imagine the error is intended to take the user to. I noticed the HTML code contains an additional piece of information that the error is caused by an "Illegal Argument".

 

I've adapted the script many many times now to try and parse out if there's something in this little bit of code that's triggering the error and the script is taken straight from the API doc so I'm at a loss for what this error is and how to get around it.

 

Has anyone else run into this at all and can provide some assistance/clarification?

 

Thank you!

4 REPLIES 4
Expert

Re: Requesting File ID from Rest API Throws 500 Internal Server Error

Most likely you're encoding the Authorization header incorrectly. Curl can do that for you, so replace that --header with 

--user username:password

and see if it works. The Content-Type header is only relevant if you're providing content in a PUT/POST request; perhaps "Accept: application/json" is what you wanted?

Contributor

Re: Requesting File ID from Rest API Throws 500 Internal Server Error

Hey Ben,

 

I tried using the --user tag instead of the --header "Authorization" and using "Accept: application/json" but they both return with an invalid authentication error so it would seem the Authorization field is required to get the File ID. I also noticed when I inspect the request process (adding -v to the cURL script) the data being returned from the server says Content-type is text/html rather than the application/json that's returned with the Workspace and Model ID requests.

 

What stands out is the cURL script in the API docs to get a File ID through the API is different than getting IDs for other objects like Workspaces and Models. I thought this might have had something to do with whether a file is classed as private or default but after testing on that it still returns the 500 Internal Server Error.

Expert

Re: Requesting File ID from Rest API Throws 500 Internal Server Error

The "--user myemail@address.com" switch causes an Authorization header to be added - just one encoded by curl. Just specify your user ID and it should prompt for a password. By "invalid authentication error" do you mean a 401/403 instead of a 500 status? It's possible that it got further than the one that gave a 500. The text/html content type happens when there's a generic (500) error. If you can get a list of models but not a list of model objects (files, imports, processes etc) inside a model then you're right to look at differences between these scripts - the API should be reasonably consistent between these endpoints.
Contributor

Re: Requesting File ID from Rest API Throws 500 Internal Server Error

Well it looks like it's working now without any changes to my original script. I don't know if there was a change on the server's side but I'm able to bring the File ID data in now so we're good to go! 

 

As far as the cURL encoded approach using the --user tag, you're right, I probably had it formatted wrong when using it in the request to get the File ID's. I was passing in both my username and password as can be done with the scripts requesting Workspace/Model IDs and it looks like the File ID request would require only the email address in order to prompt the user for their password.

 

Either way, I'm just glad it works now!