twilio-apibulk

How do I use the BulkExport API to retrieve all messages for a specific dat


Using the BulkExport API and examples, I am unable to retrieve all messages for a given day. I'm using Postman, to test on.

I know that I am authenticated, because I can change the authentication parameters, and it will fail. How does the API determine which Message Service I am referring to? We are not on an Enterprise plan.

The url I have created is: https://bulkexports.twilio.com/v1/Exports/Messages/Days/2024-10-21 However, I receive the following response:

{
    "code": 20404,
    "message": "The requested resource /Exports/Messages/Days/2024-10-21 was not found",
    "more_info": "https://www.twilio.com/docs/errors/20404",
    "status": 404
}

Solution

  • Twilio Evangelist here,

    The error: 20404 is usually received in the BulkExport API when there's not a valid job. According to the following API documentation https://www.twilio.com/docs/usage/bulkexport, in order to fetch data, it's needed to create a job like this:

    curl -X POST "https://bulkexports.twilio.com/v1/Exports/Messages/Jobs" \
    
    --data-urlencode "Email=example@example.com" \
    
    --data-urlencode "WebhookMethod=POST" \
    
    --data-urlencode "WebhookUrl=https://webhook.site" \
    
    --data-urlencode "StartDay=2022-11-05" \
    
    --data-urlencode "EndDay=2022-11-06" \
    
    --data-urlencode "FriendlyName=Export1" \
    
    -u 'ACxxx:12345'
    

    It takes some minutes to create the Job, you will see the expected time in the property estimated_completion_time. Additionally, you should expect an update when your Job is ready within the included "WebhookUrl" or "Email"

    Reference: https://www.twilio.com/docs/usage/bulkexport/export-custom-job

    Once your Job is ready, please execute this command:

    curl -X GET "https://bulkexports.twilio.com/v1/Exports/Messages/Days/2022-11-05" \
    -u 'ACxxx:12345'
    

    You will see a URL, please copy it and paste it in your browser, the download will start after that.

    Reference: https://www.twilio.com/docs/usage/bulkexport/day

    Regarding the following inquiry: How does the API determine which Message Service I am referring to? We are not on an Enterprise plan. The API uses the Messaging Service configured as default.

    I hope this way you're able to retrieve data with the BulkExport API.