x

Add high-performance, fully programmable video to any application with the new SignalWire Video API

List LaML Messages to CSV (PHP)

List messages in your SignalWire Project.

Cassie Bowles | Technical Success Manager

Apr 22, 2021

Why do you need it?

This snippet might be helpful to you if you need to pull your message records from SignalWire into a more readable format or somewhere easy to store for your own records. You can use one or more of the following parameters to further filter your records and return only the specific information that you need: DateSentBefore, DateSentAfter, From, Status, and To. This example shows how to filter all messages by a particular date range, status, from number, and to number.

You can read more about the List Messages API here.

What does it do?

This code snippet will allow you to list all the messages made (both outbound and inbound) from your SignalWire Project and export them as a CSV. You can choose the parameters you’d like to uncomment in order to filter the returned calls, or leave it with no parameters to return all of them.

Technical specifications

  1. You must have the SignalWire PHP SDK installed. You can install that here.

  2. You will also need to make sure that the vendor/autoload.php path points to the correct location on your computer. To copy this example exactly, you will need to install the SDK within the folder that contains this script.

Change the following variables
  1. ProjectID - Your project ID is an alphanumeric string that tells the SignalWire SDK where to find your project. You can find this in an easily copyable format by going to your SignalWire Portal and clicking the API tab on the left-hand side.

  2. AuthToken - Your Auth Token is an alphanumeric string that helps to authenticate your HTTP requests to SignalWire. You can create this (if you haven’t already) or copy this in an easily copyable format by going to your SignalWire Portal and clicking the API tab. If you have not created an API token, press the blue new button. If you have, click show and copy the string.

  3. SpaceURL - Your space URL is the domain of your space, i.e. example.signalwire.com. This can also be found in an easily copyable format within the API tab in your SignalWire space.

  4. You will need to change the date range to the one that fits your needs and uncomment any other parameters that you wish to use.

Step by step guide with the code
Comments

This snippet uses the PHP SDK to query SignalWire and return all the call data matching the parameters that you set. This data is inserted into a CSV file with the following columns:

  • From phone number

  • To phone number

  • DateSent

  • Status (queued, sending, sent, delivered, undelivered, failed, receiving, received)

  • Message SID (361d7f20-f30d-4baf-b8ca-c7912dleaacf)

Related Articles

Getting Started Guide

If you are looking for more information about using SignalWire, refer to our Getting Started guide.

Please feel free to reach out to us on our Community Slack or create a Support ticket if you need guidance!


Start a free trial

If you would like to test this example out, you can create a SignalWire account and space here.