Skip to main content
added 570 characters in body
Source Link
Carl Lange
  • 13.2k
  • 1
  • 38
  • 70

We will generate our own Authorization header, because this API uses a slightly obtuse method. The API uses what's known as "Basic Authentication", which is essentially "Basic " + Base64["username:password"]. Since the password doesn't appear to matter for this API, we can generate our header like so.

auth = StringJoin["Basic ", 
  ExportString["MYKEY:", "Base64"]]

It's important to leave the : in place when you paste in your key.

And now we can read the results from the API:

URLExecute[
 HTTPRequest[
  "https://api.companieshouse.gov.uk/company/00000006", <|
   "Headers" -> {"Authorization" -> auth}|>]]

There are some weirdnesses here that caused your issue. First, the API uses basic authentication strangely. Normally for an API, you would pass an Authorization header with just your API key, rather than needing to encode it like a basic authentication header. As well, it seems like WL has some vaguely-defined behaviour with basic authentication. The Authorization symbol exists (as does that dialog that you came up against), but I actually can't make it work correctly. Seems like there's a bug in the system here - and if nothing else, it's poorly documented.

We will generate our own Authorization header, because this API uses a slightly obtuse method. The API uses what's known as "Basic Authentication", which is essentially "Basic " + Base64["username:password"]. Since the password doesn't appear to matter for this API, we can generate our header like so.

auth = StringJoin["Basic ", 
  ExportString["MYKEY:", "Base64"]]

It's important to leave the : in place when you paste in your key.

And now we can read the results from the API:

URLExecute[
 HTTPRequest[
  "https://api.companieshouse.gov.uk/company/00000006", <|
   "Headers" -> {"Authorization" -> auth}|>]]

We will generate our own Authorization header, because this API uses a slightly obtuse method. The API uses what's known as "Basic Authentication", which is essentially "Basic " + Base64["username:password"]. Since the password doesn't appear to matter for this API, we can generate our header like so.

auth = StringJoin["Basic ", 
  ExportString["MYKEY:", "Base64"]]

It's important to leave the : in place when you paste in your key.

And now we can read the results from the API:

URLExecute[
 HTTPRequest[
  "https://api.companieshouse.gov.uk/company/00000006", <|
   "Headers" -> {"Authorization" -> auth}|>]]

There are some weirdnesses here that caused your issue. First, the API uses basic authentication strangely. Normally for an API, you would pass an Authorization header with just your API key, rather than needing to encode it like a basic authentication header. As well, it seems like WL has some vaguely-defined behaviour with basic authentication. The Authorization symbol exists (as does that dialog that you came up against), but I actually can't make it work correctly. Seems like there's a bug in the system here - and if nothing else, it's poorly documented.

Source Link
Carl Lange
  • 13.2k
  • 1
  • 38
  • 70

We will generate our own Authorization header, because this API uses a slightly obtuse method. The API uses what's known as "Basic Authentication", which is essentially "Basic " + Base64["username:password"]. Since the password doesn't appear to matter for this API, we can generate our header like so.

auth = StringJoin["Basic ", 
  ExportString["MYKEY:", "Base64"]]

It's important to leave the : in place when you paste in your key.

And now we can read the results from the API:

URLExecute[
 HTTPRequest[
  "https://api.companieshouse.gov.uk/company/00000006", <|
   "Headers" -> {"Authorization" -> auth}|>]]