Document API - Fetch a doc - How to complete 'Explore this API' form?

I have been trying to complete the “Fetch a doc” form found at the bottom of the https://developer.companieshouse.gov.uk/document/docs/document/id/content/fetchDocument.html and I am not getting anywhere!

Specifically I do not know what to enter in the ‘Authorization’ header field. The documentation states that the “header parameter contains the token_type and the access_token”. Can anyone enlighten me as to what a ‘token_type’ and ‘access_token’ are as I cannot find any prior reference to these two terms in any of the documentation?

Thanks.

Hi Andrew,

What I have done is set a header called “Accept” with the value “Application/pdf”. Then created a Authorization header using basic Authorization with your API key as the username and the password being blank

If you would like an example let me know

This is a working example using c#

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(“https://document-api.companieshouse.gov.uk/”);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Basic”, System.Convert.ToBase64String(
System.Text.Encoding.UTF8.GetBytes(“AKYKEY”)
)
);
client.DefaultRequestHeaders.Add(“Accept”, “application/pdf”);

        var content = client.GetByteArrayAsync("document/FIxRR8teCKodjkBLRDHv2Cb8y0-nQ7T5G3BEXfWtOu4/content").Result;
1 Like

Hi Jordan,

Many thanks for your input.

My connection settings included the required Authorization and Accept headers but for some reason the connection was failing, which was why I resorted to trying the form at https://developer.companieshouse.gov.uk/document/docs/document/id/content/fetchDocument.html

Anyway I have subsequently tweaked my code and it now works, but have since discovered the document fetch process consists of two-stages. The first stage is the call to “document/FIxRR8teCKodjkBLRDHv2Cb8y0-nQ7T5G3BEXfWtOu4/content” (as per your example and with the correct request headers) which returns a HTTP response “Location” header, the value of which is the document download URL location. The second stage requires making a connection to that URL to retrieve the actual document.

Returning to the online form I can now take a stab at what input is required (although I could not get it to work :blush: ):
id field : document/FIxRR8teCKodjkBLRDHv2Cb8y0-nQ7T5G3BEXfWtOu4
authorisation: Basic T3FKdC1GekxLNHU2ePlusRestOfEncodedKey
accept: application/pdf

I understand the service is still Beta but hopefully the documentation will be improved to remove the guesswork and confusion.

Once again, thanks.

Andrew

Thanks for your comments.

Part of having the service out there in beta is to test the API design and associated documentation to find where it doesn’t meet user need.

The authorisation API’s and documentation are currently being extended, so the documentation will improve over coming months. If you find anything that is just plain wrong, of course shout !

Chris

Hi Team,
I tried all mentioned in this (and other posts tips) and I still have an error.
My request is following:

Request*
GET /document/GdA8vcfuhlN6jp_ckh5Kfd3VAvwFexZFmvATUZUnmZM/content HTTP/1.1
Host: document-api.companieshouse.gov.ukundefined
Authorization: Basic NEtxTVR0Y1dIM3YzNHliUnJSUzQ3Q0wtYVlVRGhZaktPQlRasdf==
Accept: application/pdf

Response status
0 error

Response body*
Failure while contacting API. Some possible causes are connection problems or cross-origin resource sharing protection. Please check javascript domains registered against APIKey / OAuth2 registration.


Id number was collected from document_metadata position - link below
Get the filing history of the company

Token was encoded to Base64.

I would be very grateful for help - I need to collect pdf document.

Best Regards,
M.