Menu

Test TwiML Bins using Postman

Postman 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

The best way to get started with triggering TwiML Bins from Postman is by using our Twilio Webhook Requests collection on postman.com/twilio.

Once you opened 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.

Screenshot of the 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

Screenshot of Postman environment creation dialog

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

Screenshot of 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.

Screenshot of the Postman request dialog

Already familiar with Postman?

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

const authToken = pm.environment.get('TWILIO_AUTH_TOKEN');

function interpolate (value) {
    return value.replace(/{{([^}]+)}}/g, function (match, $1) {
        return pm.variables.get($1);
    });
}

function crypto(authToken, data) {
    let signature = CryptoJS.HmacSHA1(CryptoJS.enc.Utf8.parse(data), authToken);
    let base64 = CryptoJS.enc.Base64.stringify(signature);
    return base64;
}

function getSignature(authToken, url, params) {
    let data = Object.keys(params).sort().reduce((acc, key) => acc + key + interpolate(params[key]), interpolate(url));
    return crypto(authToken, data);
}

pm.environment.set('TWILIO_SIGNATURE', getSignature(authToken, request.url, request.data));

Afterwards, make sure to:

  1. Create a Postman environment 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.

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Thank you for your feedback!

Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

Sending your feedback...
🎉 Thank you for your feedback!
Something went wrong. Please try again.

Thanks for your feedback!

thanks-feedback-gif