Skip to contentSkip to navigationSkip to topbar
On this page

Test TwiML Bins using Postman


Postman(link takes you to an external page) is an application that you can use either as a standalone application or in your browser to make HTTP requests. You can, for example, use Postman to explore our Twilio APIs, or in this case create an HTTP request to trigger your TwiML Bin.

In order to make a request to your TwiML Bin using Postman, you'll need:

  1. Have your Account SID and Auth Token available
  2. Your TwiML Bin Handler — it has the format of https://handler.twilio.com/twiml/EHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  3. Generate a valid X-Twilio-Signature to pass to your request.

Getting started with our Postman collection

getting-started-with-our-postman-collection page anchor

The best way to get started with triggering TwiML Bins from Postman is by using our Twilio Webhook Requests collection on postman.com/twilio(link takes you to an external page).

Once you open the collection hover over the Send button, and you'll be promoted to Create a fork. Click the button to create a new fork (you might be prompted to sign-up or sign-in with Postman).

Shows 'Create a fork' pop-up dialog in Postman.

Afterwards, create the fork by giving it a label, and selecting the workspace in your account that you want the collection to be added to.

Postman Create a Fork form.

After creating a fork, you'll have to create a new Environment in your account by clicking New at the top left and choosing Environment. Once created, you want to give the environment a name, such as "Your Twilio Environment", by pressing the pencil icon next to New Environment. Next, you have to add two new Variables:

  • TWILIO_ACCOUNT_SID with the Current Value of your Twilio Account SID
  • TWILIO_AUTH_TOKEN with the Current Value of your Twilio Auth Token
Postman environment creation dialog.

Afterward, click Save, and select your new environment at the top right in the dropdown reading "No Environment".

Postman environment selection dropdown.

You are now ready to make your requests. Open the TwiML Bin Request with Signature request from the left navigation bar, replace the placeholder URL of https://handler.twilio.com/twiml/EHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa with your own TwiML Bin URL, and click Send.

Postman request dialog.

Already familiar with Postman?

already-familiar-with-postman page anchor

If you are already familiar with Postman, you can use the following code in your Pre-request Script section in Postman:

1
const authToken = pm.environment.get('TWILIO_AUTH_TOKEN');
2
3
function interpolate (value) {
4
return value.replace(/{{([^}]+)}}/g, function (match, $1) {
5
return pm.variables.get($1);
6
});
7
}
8
9
function crypto(authToken, data) {
10
let signature = CryptoJS.HmacSHA1(CryptoJS.enc.Utf8.parse(data), authToken);
11
let base64 = CryptoJS.enc.Base64.stringify(signature);
12
return base64;
13
}
14
15
function getSignature(authToken, url, params) {
16
let data = Object.keys(params).sort().reduce((acc, key) => acc + key + interpolate(params[key]), interpolate(url));
17
return crypto(authToken, data);
18
}
19
20
pm.environment.set('TWILIO_SIGNATURE', getSignature(authToken, request.url, request.data));

Afterwards, make sure to:

  1. Create a Postman environment(link takes you to an external page) with the TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN variables defined.
  2. Change the Body configuration to contain an AccountSid Key with the Value {{TWILIO_ACCOUNT_SID}}.
  3. Change the Headers configuration to include a Key of X-Twilio-Signature with the Value {{TWILIO_SIGNATURE}}.

This will ensure that a valid X-Twilio-Signature is automatically generated and inserted into your request headers.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.