Help using Shortcuts (iOS13) to access an API using Basic Authentication

I’m finding myself a little bit out of my depth here with no real experience of creating shortcuts never mind APIs.

I have an API key and it works as I have tested it via the services website.

The API uses the HTTP Basic Authentication to transmit the API key. My understanding is that Basic Authentication is usually made up of a username and password pair; this API uses the API key as the username and ignores the password, so can be left blank.

There is no ‘Shortcuts’ example to access the API, but there is a curl example:

curl -XGET -u my_api_key:

The instructions say you need to add a “:” to the end of the API key and then base encode it. So this is the first part of my Shortcut which I believe works.

This is my next part which doesn’t work as you will see from the error below, and I’ve hit a brick wall.

Can anyone spot anything obvious with the Shortcut itself or how I am approaching it?

Many thanks.

What response do you get to your first step?

I would try setting your encoding to have no line breaks and try again.

The first step works ok as I have checked via a website that the encoded/decoded base64 string matches the API. I am adding the colon to the end of the API key before encoding it which seems a little odd.

Try it like this. Note the authorisation header entry, the lack of any encoding and the lack of any additional colon. That extra colon is usually required when an ID and password are being passed in together, but the API is using just a single token.

The output is JSON, so you can work with this in Shortcuts as a dictionary.

I occasionally do work involving submitting information to CCS, and a few other things, so being able to access Companies House data through Shortcuts may prove useful for the future :+1:t2:

Brilliant. That works. Next time I’ll remember to ignore all instructions on the Developer website :man_shrugging:

That was going to be my next suggestion. I had an api that called for that I was working with but because they ignored one of the things on either side of the colon I just sent what they needed separately.

Eh sometimes it changes and no one updates the documentation lol

1 Like