There are three client credential types, not just “test and live keys”:
- API key - Basic Auth, used for public-data GETs and also the Test Data Generator.
- Stream key - for Streaming API connections.
- OAuth web client - client ID/secret plus OAuth flow, used for filing/change APIs requiring user/company authorisation. Company Information Developer Hub
However, you only need a TEST REST API KEY to create a test company in the sandbox.
I’ve just tested this myself today using a Test application API key and the endpoint is working.
This exact request returned HTTP/2 201 Created:
curl -v \
-u 'MY-TEST-APPLICATION-API-KEY-HERE-FOLLOWED-BY-A-COLON:' \
-H 'Content-Type: application/json' \
-d '{}' \
'https://test-data-sandbox.company-information.service.gov.uk/test-data/company'
So I think we can rule out the Test Data Generator endpoint itself.
I’d now concentrate on the credential. In Developer Hub, make sure you have:
Application: Test
Client type: API key
rather than a Live API key, Stream key, OAuth client ID or OAuth client secret. This is a screenshot of the test application page where I got my API key from to perform this test:
Also check whether the API key has an IP restriction configured. For diagnosis I’d create a new Test API key with no IP restriction and try exactly the command above.
You don’t need OAuth or your localhost redirect URLs for this particular request, the Test Data Generator authenticates using the Test API key.
If a newly-created unrestricted Test API key (give it 5 minutes to propagate) still produces a bare 403, I’d send Companies House support the timestamp and request details because the identical request is currently returning 201 for another Test application.
This is the output from the CURL statement above, it shows a HTTP/2 201 response, identifies x-ratelimit-remain: 599 because this was my first test against the API during the last 5 minutes.