Fetching filing file metadata

Hello! I am trying to use the api to fetch filing file. I am using python requests library.
First step:

response = requests.get('https://api.companieshouse.gov.uk/company/09446231/filing-history/MzI1NDYyNzcxNWFkaXF6a2N4', 
                    headers={'Authorization': {mykey}).json()

I receive:

  {'action_date': '2020-01-07',
 'category': 'capital',
 'date': '2020-01-16',
 'description': 'capital-allotment-shares',
 'description_values': {'date': '2020-01-07',
  'capital': [{'figure': '12.946916', 'currency': 'GBP'}]},
 'links': {'self': '/company/09446231/filing-history/MzI1NDYyNzcxNWFkaXF6a2N4',
  'document_metadata': 'https://frontend-doc-api.companieshouse.gov.uk/document/2N7iuPGYl8d4g_jcmQtl_Mpqk6CbVFSGZQyPad70Y0k'},
 'paper_filed': True,
 'type': 'SH01',
 'pages': 10,
 'barcode': 'A8WN6FJF',
 'transaction_id': 'MzI1NDYyNzcxNWFkaXF6a2N4'}

However when I try to get metadata I get 404 error.

requests.get('https://frontend-doc-api.companieshouse.gov.uk/document/2N7iuPGYl8d4g_jcmQtl_Mpqk6CbVFSGZQyPad70Y0k',
             headers={'Authorization': '{mykey}'})
<Response [404]>

The documentation says that to get metadata I need to use http://document-api.companieshouse.gov.uk/document/{id}
However I am not sure, whether the id is MzI1NDYyNzcxNWFkaXF6a2N4(transaction_id) or the last part of broken metadata link 2N7iuPGYl8d4g_jcmQtl_Mpqk6CbVFSGZQyPad70Y0k. Anyway both ioptions yield error 500.

requests.get('http://document-api.companieshouse.gov.uk/document/MzI1NDYyNzcxNWFkaXF6a2N4',
         headers={'Authorization': '{mykey}'})
<Response [500]>
requests.get('http://document-api.companieshouse.gov.uk/document/2N7iuPGYl8d4g_jcmQtl_Mpqk6CbVFSGZQyPad70Y0k',
             headers={'Authorization': '{mykey}'})
<Response [500]>

Thank you in advance for the help!

Either document-api.companieshouse.gov.uk or frontend-doc-api.companieshouse.gov.uk should work (basically, use whatever you get back from CH in “document_metadata”) - see:
Filing history change - documents api alias?

For the 404 - that suggests something else has crept in to the URL you’re requesting. I tested exactly the “document_metadata” link you got back from CH and it worked OK for me (see later).

I don’t know if this is significant but I notice in your examples you’ve got two different expressions going on:
First example:

headers={'Authorization': {mykey})

and in the subsequent examples:

headers={'Authorization': '{mykey}'})

It’s likely not significant but I notice you’re using “http://document-api.companieshouse.gov.uk” not https in one example - I’d ensure you always use https.

I just tested the link (using curl) - either way works:

curl -u"API_KEY_HERE:" "https://frontend-doc-api.companieshouse.gov.uk/document/2N7iuPGYl8d4g_jcmQtl_Mpqk6CbVFSGZQyPad70Y0k"

Gives:

{
    "company_number": "09446231",
    "barcode": "A8WN6FJF",
    "significant_date": null,
    "significant_date_type": "",
    "category": "capital",
    "pages": 10,
    "created_at": "2020-01-17T12:28:09.163046105Z",
    "etag": "",
    "links": {
        "self": "https://document-api.companieshouse.gov.uk/document/2N7iuPGYl8d4g_jcmQtl_Mpqk6CbVFSGZQyPad70Y0k",
        "document": "https://document-api.companieshouse.gov.uk/document/2N7iuPGYl8d4g_jcmQtl_Mpqk6CbVFSGZQyPad70Y0k/content"
    },
    "resources": {
        "application/pdf": {
            "content_length": 207979
        }
    }
}

And:

curl -u"API_KEY_HERE:" "https://document-api.companieshouse.gov.uk/document/2N7iuPGYl8d4g_jcmQtl_Mpqk6CbVFSGZQyPad70Y0k"

…gives the same resource.

1 Like

Hi,
Thanks a lot! Turned out the problem was with the requests library.