Skip to content

Instantly share code, notes, and snippets.

@peteryates
Created April 13, 2023 11:01
Show Gist options
  • Save peteryates/3e4aedc9cd11bf548d39e3aaa6947401 to your computer and use it in GitHub Desktop.
Save peteryates/3e4aedc9cd11bf548d39e3aaa6947401 to your computer and use it in GitHub Desktop.
Making requests to the Notify API via the command line

Accessing the Notify API from the command line

Prerequisites

Building a bearer token

  1. First generate an API key using Notify's admin interface. The API key consists of three parts:

    |--name---| |-----------service uuid-----------| |-----------secret uuid------------|
    yourkeyname-aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb
    
  2. Any generated tokens expire after 30 seconds so we need to generate them per request. The easiest way to do this is to write a small script (e.g., key). We need our service and secret uuids from the API key and be sure to trim the newline from the end.

    jwt encode \
     --iss "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" \
     --secret="bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" \
     --alg=HS256 | tr -d "\n"
    
  3. Now we should be able to make it executable chmod +x key and test calling it ./key

Making requests

Now the hard part is done we just need to build requests that use our script:

xh get https://api.notifications.service.gov.uk/v2/templates Authorization:"Bearer $(./key)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment