Search code examples
twiliotwilio-apipostman-testcase

Twilio Error 11200- HTTP retrieval failure: Attempt to retrieve media failed, while trying to Trigger a Twilio Studio Flow Execution via Rest API


I am attempting to build this Appointment Management System for scheduling vaccination appointments using Twilio+ Airtable + Postman. ( [Link to the blog following])2

In order to trigger the Twilio studio flow via Rest API and to get the Programmable message on my personal number from my Twilio number, I made this POST request by providing the URL of the flow which contains the authentic flow_sid and other details, but every time the post request is made the following errors are encountered :

Twilio Error logs:

  1. (Error: 11200) HTTP retrieval failure There was a failure attempting to retrieve the contents of this URL.

error

Postman Test Results:

  1. Response time is less than 1000ms | AssertionError: expected 2315 to be below 1000

error

The function being called by the studio flow at the very first instance is:

const airtable = require("airtable");

exports.handler = function (context, event, callback) {
  const base = new airtable({apiKey: context.AIRTABLE_API_KEY}).base(context.AIRTABLE_BASE_ID);
 const client = context.getTwilioClient();
 let paramsMap = new Map();
  base("appointments")
 .select()
 .all()
 .then((records) => {
   const sendingMessages = records.map((record) => {
     if (record.get('Appointment_Status') === "pending"){
       paramsMap['name'] = record.get('Name');
       paramsMap['appointment_date'] = record.get('Date');
       paramsMap['appointment_time'] = record.get('Appointment_Time');
       paramsMap['airtable_record_id'] = record.getId();
       paramsMap['appt_id'] = record.get('ID');
     }
   });
   return Promise.all(sendingMessages);
 })
   .then(() => {
     if (paramsMap['name'] === undefined) //No appointments in system
     {
       console.log("No appointments in system");
       callback(null, "From studio function");
     }
    
     params_list = {
           "appointment_date": paramsMap['appointment_date'],
           "appointment_time": paramsMap['appointment_time'],
           "provider_name":"Owl Health",
           "patient_name": paramsMap['name'],
           "airtable_record_id": paramsMap['airtable_record_id'],
           "appt_id": paramsMap['appt_id']
     };
    
     client.studio.v1.flows('Vaccine-Reminder').executions.create(
       {
         to: '+91xxxxxxxxxx',
         from: '+12xxxxxxxxxx',
         parameters: JSON.stringify(params_list)
       }
     )
     .then(function(execution) {
       console.log("Execution Id:" + execution.sid);
       callback(null, "Message sent via studio function");
     })
     .catch(err => callback(err));
   })
   .catch((err) => {
       console.log("Airtable error");
       callback(err);
   });
};

Studio flow


Solution

  • Twilio developer evangelist here.

    I think, from your question, that you are creating the Studio Flow Execution by making the API request directly to the Flow. However the Function that you included is intended to make that request after collecting the data from Airtable.

    The Studio Flow is not supposed to call that function, the function creates an execution with this code:

         client.studio.v1.flows('Vaccine-Reminder').executions.create(
           {
             to: '+91xxxxxxxxxx',
             from: '+12xxxxxxxxxx',
             parameters: JSON.stringify(params_list)
           }
         )
    

    The Postman test results are misleading. The fact that the API didn't respond in under 1000ms means it could maybe be faster, but the 201 response shows that it was successful at least.

    Instead of using Postman to create the Studio execution, try using it to call your Twilio Function instead and let me know if that helps.

    Studio Flow