I am a newbie with RESTful APIs and have never tried accessing one from inside Mathematica. I am trying to access the Companies House API, in the UK. The following command works fine from the Terminal command line (company number 00000006 is just a number a picked at random):
curl -X GET -u My_API_Key: https://api.companieshouse.gov.uk/company/{00000006}
I entered the following code in a Mathematica notebook, following the help example:
urlRoot = "https://api.companieshouse.gov.uk/company/";
company = "{00000006}";
myKey = "My_API_Key";
requestURI = URLBuild[{urlRoot, myKey, company}]
with my actual key in place of My_API_Key. The URI created is this:
https://api.companieshouse.gov.uk/company/My_API_Key/%7B00000006%7D
When I execute this command:
response = URLExecute[requestURI, "RawJSON"]
I get the dialog into which I enter My_API_Key and some blank spaces for the password. That's because the API documentation says to do this, or at least this is what I have understood. The result is this:
<|"error" -> "Empty Authorization header", "type" -> "ch:service"|>
What am I doing wrong? Very sorry if this is a really simple/dumb question, I have never tried doing this before... Thanks
URLExecute@ HTTPRequest[ "https://api.companieshouse.gov.uk/company/{00000006}", <| "Headers" -> {"Authorization" -> ExportString["my_api_key:", "Base64"]}|>]
- make sure you leave the:
in place after you put in your API key. $\endgroup${"error" -> "Invalid Authorization", "type" -> "ch:service"}
$\endgroup$Submit
without entering username and/or password the messageThis field is required
appears below each/either. There are no other buttons to press. $\endgroup$You are attempting to read from the domain live-chs-apichgovuk-248537452.eu-west-2.elb.amazonaws.com The server is requesting authentication.
If I click on that link another dialog opens up with the further msg:The file "/Applications/Mathematica12.app/Contents/live-chs-apichgovuk-248537452.eu-west-2.elb.amazonaws.com" could not be found.
So it looks like I am missing some kind of local authentication file. $\endgroup$