Twilio API

From DreamFactory
Jump to: navigation, search

This tutorial shows how to configure a remote web service to connect to the Twilio API. It shows how to pass your authorization header to the remote service. This example is specific to the Twilio API, but many APIs have similar concepts.

Create the Remote Web Service

  • Sign up for a free Twilio account at
  • In the DreamFactory admin console, go to the Services tab and click Create.
  • Set the Service Type to 'Remote Service' > 'HTTP Service'
  • Set the service name to 'twilio'.
  • Set the service label to 'Twilio API'. Check the Active checkbox.
  • Go to the Config tab for the new service and set the Base URL to ``````.
  • Under Headers, click the '+' button and enter 'Authorization' for Name and 'Basic your-twilio-username-and-password-base64-encoded. Also select all five HTTP verbs so that the header is sent to the Twilio API for all requests.
  • Optionally, go to the Service Definition tab and copy in a Swagger 2.0 JSON definition for many of the Twilio API calls. The JSON file is located [here].
  • Click Create Service to save your new service.

Call the Remote Web Service

You can now use any REST client to access your remote web service using the DreamFactory REST API. See other tutorials for authentication options.

For example, with cURL you can first log in as a DreamFactory admin and get a session token:

curl -i -k -3 -X POST "http://localhost:8080/api/v2/system/admin/session" -d '{ "email" : "[email protected]", "password" : "your_password" }'

Then make a cURL call to the Twilio API, like this:

curl -i -k -3 -X GET "http://localhost:8080/api/v2/twilio/Accounts/<your twilio account sid>.json" -H "X-DreamFactory-Api-Key: <api key for the admin app in the apps tab>" -H "X-DreamFactory-Session-Token: <session token returned by the login api call above>"

DreamFactory combines the request URL from the client with the configured base URL for the service to generate the actual URL for the request.

Remember that you can also create server-side scripts to manipulate the API request or response.