> ## Documentation Index
> Fetch the complete documentation index at: https://plivo.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Delivery Reports

> Track SMS delivery status with message delivery report callbacks

<h2 id="api-{{'Overview' | slugify}}">Overview</h2>

Delivery reports serve as your callback service, informing you of the status of messages sent to a specific destination (outbound message) or received on your Plivo number (inbound message).

When a call to the [Message API](/docs/messaging/api/message/#send-a-message) to send a message completes successfully, your message is put into a queue to be sent to its destination. By default, you do not receive an automatic notification regarding the delivery of your message. To get notified about the status of your message, include the `url` parameter in your API request. This generates a notification when your message reaches its destination, or if it fails to deliver. Your delivery report will show the status — `“queued”`, `“sent”,` `“delivered”`, `“undelivered”` or `“failed”` — for each recipient, along with other [parameters](/docs/messaging/api/message/#message-status-callbacks).

You can find SMS delivery reports by visiting Messaging > [Logs](https://cx.plivo.com/logs?tab=messages) on the Plivo console.

Similarly, if you want a delivery report when you receive an SMS message on your Plivo number, update the Message URL of the application associated with your Plivo number. Your delivery report will show the status — “delivered” or “undelivered” — along with incoming message [details](/docs/messaging/api/message/#handling-incoming).

<Note>
  <strong>Note:</strong> Long SMS messages are automatically split for sending and concatenated upon receipt for a seamless user experience. When checking message logs and delivery reports for long SMS messages that are split, look for the MessageUUID, which is the same in all related split messages and identical to the UUID of the first message in the split sequence of messages.
</Note>

<Tabs>
  <Tab title="Inbound">
    <h2 id="api-{{'Prerequisites' | slugify}}">Prerequisites</h2>

    To get started, you need a Plivo account — [sign up](https://cx.plivo.com/signup) with your work email address if you don’t have one already. To receive incoming messages, you must have a Plivo phone number that supports SMS; you can rent numbers from the [Numbers](https://cx.plivo.com/phone-numbers) page of the Plivo console or by using the [Numbers API](/docs/numbers/). If this is your first time using Plivo APIs, follow our instructions to set up a Ruby development environment and a web server and safely expose that server to the internet.

    Here’s how the process works for inbound messages.

    <h2 id="api-{{'Inbound' | slugify}}">Inbound</h2>

    <h3 id="api-{{'Create the autoresponder application using Rails server' | slugify}}">Create the autoresponder application using Rails server</h3>

    Edit app/controllers/plivo\_controller.rb and paste into it this code.

    ```rb theme={null}
    include Plivo
    include Plivo::Exceptions
    include Plivo::XML

    class PlivoController < ApplicationController
      skip_before_action :verify_authenticity_token
      def delivery_report
    		from_number = params[:From]
        to_number = params[:To]
        text = params[:Text]
    		puts "Message received - From: #{from_number}, To: #{to_number}, Text: #{text}"

      	render json: "Report Received"
      	end
    end
    ```

    <h3 id="api-{{'Add a route' | slugify}}">Add a route</h3>

    Edit config/routes.rb and change the line

    ```ruby theme={null}
    Rails.application.routes.draw do
      get 'plivo/sms' 
    end
    ```

    to

    ```ruby theme={null}
    Rails.application.routes.draw do
      post 'plivo/delivery_report/' => 'plivo#delivery_report'
    end
    ```

    <h2 id="api-test">Test</h2>
    Start the Rails server

    ```shell theme={null}
    $ rails server
    ```

    You should see your basic server application in action at [http://localhost:3000/plivo/delivery\_report/](http://localhost:3000/plivo/delivery_report/).

    Expose your local server to the internet.

    <Note>
      <strong>Note:</strong>
      For ngrok testing, add this line to config/environments/development.rb.<br />
      `config.hosts << /[a-z0-9-]+\.ngrok\.io/`
    </Note>

    <h2 id="api-{{'Create an application' | slugify}}">Create an application</h2>

    Associate the code you created with Plivo by creating a Plivo application. Visiting Messaging > [Applications](https://cx.plivo.com/xml-applications) and click **Add New Application**. You can also use Plivo’s [Application API](/docs/account/api/application/#create-an-application).

    Give your application a name — we called ours Delivery Reports. Enter the server URL you want to use (for example https\://\<yourdomain>.com/delivery\_report/) in the Message URL field and set the method to POST. Click Create Application to save your application.

    <Frame>
      <img src="https://mintcdn.com/plivo/EvRfP72Bjs4tuRt5/images/create-app.png?fit=max&auto=format&n=EvRfP72Bjs4tuRt5&q=85&s=4e692ce08f780dcc9107c22da480ff8a" alt="Create Application" width="1440" height="821" data-path="images/create-app.png" />
    </Frame>

    <h2 id="api-{{'Assign a Plivo number to your application' | slugify}}">Assign a Plivo number to your application</h2>

    Navigate to the [Numbers](https://cx.plivo.com/phone-numbers) page and select the phone number you want to use for this application.
    From the Application Type drop-down, select **XML Application**.
    From the Plivo Application drop-down, select **Receive SMS** (the name we gave the application).
    Click **Update Number** to save.

    <Frame>
      <img src="https://mintcdn.com/plivo/NFI9_HRHTMInDf93/images/assign-number.png?fit=max&auto=format&n=NFI9_HRHTMInDf93&q=85&s=4afae0cee2bb6cf3c623c72cfd049502" alt="Assign Phone Number to Receive Delivery Reports" width="1440" height="821" data-path="images/assign-number.png" />
    </Frame>

    <h2 id="api-{{'Test' | slugify}}">Test</h2>

    Send an SMS message to your Plivo number using a regular mobile phone. Plivo will send a request to your Message URL with the parameters listed in the [Messaging documentation](/docs/messaging/api/message/#handling-incoming).

    You can view the details posted by Plivo by looking at your terminal.
  </Tab>

  <Tab title="Outbound">
    <h2 id="api-{{'Prerequisites' | slugify}}">Prerequisites</h2>

    To get started, you need a Plivo account — [sign up](https://cx.plivo.com/signup) with your work email address if you don’t have one already. To receive incoming messages, you must have a Plivo phone number that supports SMS; you can rent numbers from the [Numbers](https://cx.plivo.com/phone-numbers) page of the Plivo console or by using the [Numbers API](/docs/numbers/). If this is your first time using Plivo APIs, follow our instructions to set up a Ruby development environment and a web server and safely expose that server to the internet.

    Here’s how the process works for outbound messages.

    <h2 id="api-{{'Outbound' | slugify}}">Outbound</h2>

    <h3 id="api-{{'Create the autoresponder application using Rails server' | slugify}}">Create the autoresponder application using Rails server</h3>

    Edit app/controllers/plivo\_controller.rb and paste into it this code.

    ```rb theme={null}
    include Plivo
    include Plivo::Exceptions
    include Plivo::XML

    class PlivoController < ApplicationController
      skip_before_action :verify_authenticity_token
      def delivery_report
            from_number = params[:From]
       		to_number = params[:To]
        	status = params[:Status]
    		puts "Message received - From: #{from_number}, To: #{to_number}, Status: #{status}"
      	render json: "Report Received"
    	end
    end
    ```

    <h3 id="api-{{'Add a route' | slugify}}">Add a route</h3>

    Edit config/routes.rb and change the line

    ```ruby theme={null}
    Rails.application.routes.draw do
      get 'plivo/sms' 
    end
    ```

    to

    ```ruby theme={null}
    Rails.application.routes.draw do
      post 'plivo/delivery_report/' => 'plivo#delivery_report'
    end
    ```

    Start the Rails server

    ```shell theme={null}
    $ rails server
    ```

    You should see your basic server application in action at [http://localhost:3000/plivo/delivery\_report/](http://localhost:3000/plivo/delivery_report/).

    Expose your local server to the internet.

    <Note>
      <strong>Note:</strong>
      For ngrok testing, add this line to config/environments/development.rb.<br />
      `config.hosts << /[a-z0-9-]+\.ngrok\.io/`
    </Note>

    <h2 id="api-{{'Test' | slugify}}">Test</h2>

    To test delivery reports on outbound messages, send an SMS message to a mobile phone using this code.

    ```rb theme={null}
    require "plivo"
    include Plivo

    api = RestClient.new("<auth_id>","<auth_token>")
    response = api.messages.create(
    	src: "<sender_id>",
    	dst:"<destination_number>",
    	text:"Hello, this is a sample text",
    	url: "https://<ngrok_url>/delivery_report/",
    )
    puts response
    ```

    Replace the phone number placeholders with actual phone numbers in [E.164 format](https://en.wikipedia.org/wiki/E.164) (for example, +12025551234) and `url` with the ngrok-generated URL.

    Plivo will send a request to your `url` with the parameters listed in the [Messaging documentation](/docs/messaging/api/message/#message-status-callbacks).

    You can view the details posted by Plivo by looking at your terminal.
  </Tab>
</Tabs>
