Skip to content

Instantly share code, notes, and snippets.

@sammachin
Last active November 2, 2018 11:51
Show Gist options
  • Save sammachin/4b5c2b50b0851195d4e9787b7eb1d251 to your computer and use it in GitHub Desktop.
Save sammachin/4b5c2b50b0851195d4e9787b7eb1d251 to your computer and use it in GitHub Desktop.
Making API Requets using JWT and HTTPie

HTTPie is AWESOME! if you're still using cURL do yourself a favor and get this https://httpie.org/

Here's a quick guide to make requests to the nexmo API that need to be authenticated with JWT and have a JSON request body.

You will need:

  • The Nexmo CLI installed
  • The private key for your application stored in a local file named private.key
  • The applicaiton ID of your applicaiton
  • The payload of the request in a file called request.json (see example)

For exampe to create a call use the following command (replace the application ID with your value)

http POST https://api.nexmo.com/v1/calls Authorization: "Bearer `nexmo jwt:generate ./private.key application_id=aaaaaaaa-bbbb-cccc-dddd-0123456789ab`" @request.json

You'll get nicely formatted responses from the API

{
"to":[{"type":"phone","number":"447700900123"}],
"from":{"type":"phone","number":"447700900456"},
"answer_url":["https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment