Menu

Expand
Rate this page:

Make HTTP Request Widget

Studio uses Widgets to represent various parts of Twilio's functionality that can then be stitched together in your Studio Flow to build out robust applications that require no coding on your part.

New to Twilio Studio? Check out our Getting Started guide!

The Make HTTP Request Widget allows you to interact with applications and code that live outside of Studio. You can use this widget to interact with parts of your business logic not defined in flows or as Functions.

A basic Make HTTP Request Widget with an HTTP GET request. We see the named widget ("my_http_get_req"), and underneath the name is our GET request with a url of of https://www.myurl.com/users. We can see that the Success transition moves on in the flow, while the Fail transition stops the flow.

Returning custom TwiML from a Make HTTP Request widget isn't supported. Use the Run Function widget instead, and follow our guide for returning custom TwiML from Twilio Functions.

Required configuration for Make HTTP Request

There are three required fields for this Widget: Request Method, Request URL, and Content Type. You can select the Request Method and Content Type from a dropdown in the Widget Inspector Panel.

Name Description Example Default
Request Method The HTTP method of your request GET or POST GET
Request URL The URL you would like to make a request to https://myurl.com N/A
Content Type Content type of the request body Form URL Encoded or Application/JSON Form URL Encoded

For secure URLs, add your Basic Authentication credentials. Example: https://user:password@mydomain.com/handler.php

This is what the default configuration looks like for the Make HTTP Request widget:

Required configuration for Make HTTP request widget. We see the named widget ("http_request_widget"), then a dropdown under Request Method with the default "Get" selected. Under that, the form has a field for Request URL, followed by another dropdown for Content Type (with Form URL Encoded selected).

Optional Configuration for Make HTTP Request Widget

The Make HTTP Request Widget also accepts a few configuration options that let you pass along additional information with your request.

Name Description Example Default
Request Body Text to include in the body of your request {{widgets.first_question.inbound.Body}} N/A
HTTP Parameters Key/Value pairs of parameters to pass along with the request, as string literals or variables

"key": "value" or key: {{flow.variables.<key>}}

N/A

Studio supports the Liquid templating language, which allows you to work with dynamic content throughout your Flow – you may find it useful for creating a Request Body or the value for HTTP parameters on the fly, as seen in the table above. You can see this in action in our Conduct a Survey tutorial.

For more on working with variables in Studio, see this user guide.

Make HTTP Request Transitions

Two events trigger transitions from this Widget to another Widget in your Flow:

Name Description Example
Success A successful return HTTP 200
Fail The URL does not successfully return, or has an error HTTP 500

The Make HTTP Request Widget requires you set up transitions for both success and failure states so that your Studio Flow knows what to do if it gets a response back, or if the request fails in some way. If the request succeeds, you will likely move on to the next Widget in your Flow. On a Fail state, you can can choose to re-try the request, or fail out of the flow.

In this screenshot, we see the transitions for a Make HTTP Request Widget. The Success state sends the floe to split_1, and the failure state sends the Flow back to re-try the HTTP GET request.

For more information on working with transitions in Studio, see this user guide.

HTTP Response requirements

The HTTP response from the URL you specify in a Make HTTP Request Widget must return a 2xx status code within 10 seconds to succeed, and the response body must not exceed 64kB. We've outlined a few recommendations for configuring your HTTP response:

Response Recommendation Notes
Status Code 200 or 204 3xx redirection is supported. 4xx or 5xx status code will transition to "failed" in the widget.
Content Type application/json Content-Type header is not required if Status Code is 204 No Content. Other content types are supported, such as plain text or XML. But only application/json objects (e.g. {"foo":"bar"}) will be automatically parsed into Studio variables.
Body Valid JSON Body content must match the Content-Type header.
Response Time 10 seconds or less Studio will timeout the request at 10 seconds and transition to "failed" in the widget.
Response Size Maximum 64kb Studio can only process responses up to 64kB.

How to access variables from your HTTP response

You may wish to do some work on the data you pass to your endpoint and return more data or variables to work with further along in your Flow.

Returning JSON

If your request returns an object in valid JSON, you will be able to access it via widgets.MY_WIDGET_NAME.parsed.

For example, if your URL returns {"message": "Hi", "person": {"name": "Bob", "age": 40}}, you can reference that in subsequent widgets as:

widgets.MY_WIDGET_NAME.parsed.message

widgets.MY_WIDGET_NAME.parsed.person.name

widgets.MY_WIDGET_NAME.parsed.person.age

Note that, although an array is valid JSON, if your request returns an array of objects, it will not be parsed by your Studio Flow.

Variables from all return types

No matter what kind of response your URL returns to Studio, the following variables will be available to your Flow:

widgets.MY_WIDGET_NAME.body

widgets.MY_WIDGET_NAME.status_code

widgets.MY_WIDGET_NAME.content_type

Example: post data to a third-party URL with Make HTTP Request

One example of using the Make HTTP Request Widget is posting a message that comes in to a Twilio phone number to Slack. In the screenshot below, we can see that the Make HTTP Request Widget is triggered when a message comes in to this Studio Flow's phone number. The Make HTTP Request Widget will take the message body that comes in from a user (as specified in the Request Body of the Widget's configuration) and POST it to a Slack hook.

Post to Slack Webhook. The Incoming Message trigger leads to our Make HTTP Request Widget, which is set up as a POST request to https://hooks.slack.com/services. The Content-Type is set to Application/JSON, and the Request Body is {"text": "{{trigger.message.Body}}"}

Learn More

Want to learn how to use the Make HTTP Request Widget in a real-world example? Follow along with one of our step-by-step tutorials to see this Widget in action in a few different ways:

We can't wait to see what you build!

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!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more