Documents API issues

I have used this many times before but I just seem to be getting 500 errors? Feels like a rookie error somewhere. I have tested my key on the Filing History endpoint with no issues. Also tried a couple of different documents.

I have boiled it down to (key replaced )

curl -H “Authorization: MY_API_KEY”
-L
-o document.pdf
https://document-api.company-information.service.gov.uk/document/aBej_8qBArJPXRf4hENwnkTvWww5XW7UD2_s-bb5CmA/content

and

curl -i -H “Authorization: MY_API_KEY”
https://document-api.company-information.service.gov.uk/document/aBej_8qBArJPXRf4hENwnkTvWww5XW7UD2_s-bb5CmA/content

Wierd. Thoughts pls?

Regards

Andy

If you’re providing your own headers you need to build them yourself … are you doing that? The http basic authorization header format is:

Authorization: Basic {encoded-user-and-password}

{encoded-user-and-password} is the API_KEY (user), a separator (“:”) and the password (empty string) - all base64 encoded. So:

base64( API_KEY + “:” + “” )

You can see this by getting curl to do this for you. You can just provide the unencoded user (API key) and password (nothing). If you want to see what curl actually sends - including headers - add the -v flag. You don’t want to do this with the actual file download however as you’ll get screenfulls of bytes! So - only showing the first link (redirect) but showing your header:

curl -v -u API_KEY: https://document-api.company-information.service.gov.uk/document/aBej_8qBArJPXRf4hENwnkTvWww5XW7UD2_s-bb5CmA/content

To actually get the file, the following works for me (-L to follow the redirect, -o to save to a file, not verbose):

curl -u API_KEY: -L -o document_test.pdf https://document-api.company-information.service.gov.uk/document/aBej_8qBArJPXRf4hENwnkTvWww5XW7UD2_s-bb5CmA/content

That downloads a file for me.

Good luck.

Yup got there, thanks for the help.