0

I plan on using cloudconverts API API for converting docx files to pdf but im stuck with a File not found (upload failed) error each time i have started a conversion process and request the status of the conversion.

To make sure the file can be reached, i ran a test using their API and executing my request which was a success.

Im testing the conversion using Googles Advanced Rest Client and my header og payload is as follows:

Requesting a process:

enter image description here

Im getting an URL for my convertion process and all is good. So time to start my process of converting my file. Im using the option to let cloudconvert download the docx from my domain.

Starting my process:

enter image description here

The request for starting my process is also a succes and i now want to check the status of my conversion by calling the previous url as a GET. But this gives me an error message in the response saying: File not found (Upload failed)

As written in the beginning of my post, i tried using their API console to test if the file can be downloaded from my site, which it could and PDF was created successfully .. So i guess im missing something somewhere, just cant see it...

muenchdo
  • 2,161
  • 1
  • 17
  • 30
DTH
  • 1,133
  • 3
  • 16
  • 36
  • 1
    I think you have the content type header wrong. For JSON payload it should be application/JSON – Pawel Uchida-Psztyc Feb 11 '16 at 18:00
  • @PawełPsztyć That is so true ... if i set the Content-type to application/JSON i get a new error message "error": "SyntaxError: Unexpected token i" – DTH Feb 11 '16 at 19:03
  • It's because JSON object require both keys and (string) values to be in double quota marks. So instead of >>input<< you should have "input". And so on. – Pawel Uchida-Psztyc Feb 11 '16 at 19:06
  • @PawełPsztyć YOU ARE SO RIGHT AGAIN .. :) .. I tested it and it is now working .. Please post that comment as the answer and i will accept it .. – DTH Feb 11 '16 at 19:25
  • @PawełPsztyć .. BUT it is weird that the API's response to my BAD json was still a success response (when i did not set application/json) .. – DTH Feb 11 '16 at 19:26

1 Answers1

1

So yeah,

First problem was that there was wrong content-type header set. For JSON payload it should be "application/json". With "application/x-www.form-urlencoded" content type header the server expected different payload so the call resulted with error.

Second one was about JSON parsing. JSON is not the same as JavaScript object. Keys in JSON must contain double quotes characters.

Finally I'm not sure what do you mean by success response. If you talking about status code - well it's just bad API configuration/design.

Pawel Uchida-Psztyc
  • 3,735
  • 2
  • 20
  • 41
  • Thanks .. Just went through their API Documentation, and the JSON they have given there as an example (which I roughly copied) is without double quotes. But you spotted the bad JSON and everything is now working .. thanks a lot. – DTH Feb 11 '16 at 20:00