> For a complete documentation index, fetch https://docs.voximplant.ai/llms.txt

# A2PGetSmsHistory

POST https://api.voximplant.com/platform_api/A2PGetSmsHistory

Gets the history of sent/or received A2P SMS.

Allowed roles: `Owner`, `Admin`, `CallsSMS`.

**Example request:** Get messages that had been sent to number 12345678222 starting from March 1, 2019. Number of resulting rows is limited to 2.

Reference: https://docs.voximplant.ai/api-reference/management-api/reference/sms/a2p-get-sms-history

## Authentication

- `Authorization` header (bearer token, required) — Voximplant Management API uses signed JWT tokens generated from your service-account private key. Pass the token in the `Authorization` header as a Bearer value: ``` Authorization: Bearer $VOXIMPLANT_TOKEN ``` See [Authorization](/api-reference/management-api/authorization) for ready-to-copy snippets in bash, Python, Node.js and Go that turn your `credentials.json` into a token.

## Request

### Query parameters

- `source_number` (string, optional) — The source phone number
- `destination_number` (string, optional) — The destination phone number
- `count` (integer, optional) — Maximum number of resulting rows fetched. Must be not bigger than 1000. If left blank, then the default value of 1000 is used
- `offset` (integer, optional) — The first **N** records are skipped in the output
- `from_date` (string, optional) — Date from which the search is to start. Format is 'yyyy-MM-dd HH:mm:ss', time zone is UTC
- `to_date` (string, optional) — Date from which the search is to end. Format is 'yyyy-MM-dd HH:mm:ss', time zone is UTC
- `output` (string, optional, default: json) — The output format. The following values available: **json**, **csv**, **xls**. The default value is **json**
- `delivery_status` (integer, optional) — The delivery status ID: QUEUED - 1, DISPATCHED - 2, ABORTED - 3, REJECTED - 4, DELIVERED - 5, FAILED - 6, EXPIRED - 7, UNKNOWN - 8

## Response

### 200

Successful response

- `result` (list of A2PSmsHistoryType, optional)
- `total_count` (integer, optional) — Total number of messages matching the query parameters

## Types

### A2PSmsHistoryType

The [A2PGetSmsHistory] function result.

- `message_id` (integer, optional) — Message ID
- `source_number` (A2PSmsHistoryTypeSourceNumber, optional) — SMS source number
- `destination_number` (A2PSmsHistoryTypeDestinationNumber, optional) — SMS destination number
- `fragments` (integer, optional) — Number of fragments the initial message is divided into
- `cost` (double, optional) — The message cost
- `status_id` (string, optional) — The message status. The possible values are: 1 — Success, 2 — Error, 3 — Waiting
- `error_message` (string, optional) — Error message (if any)
- `processing_date` (string, optional) — Date string as returned by the Management API. Date of message processing. The format is yyyy-MM-dd HH:mm:ss
- `transaction_id` (integer, optional) — The transaction ID for this message
- `delivery_status` (string, optional) — Delivery status: QUEUED, DISPATCHED, ABORTED, REJECTED, DELIVERED, FAILED, EXPIRED, UNKNOWN
- `text` (string, optional) — Stored message text

### A2PSmsHistoryTypeSourceNumber

SMS source number

- integer
- string

### A2PSmsHistoryTypeDestinationNumber

SMS destination number

- integer
- string

## Examples

**Response**

```json
{
  "result": [
    {
      "message_id": 1,
      "source_number": "12345678111",
      "destination_number": "12345678222",
      "fragments": 0,
      "cost": 4.3437,
      "status_id": "2",
      "error_message": "Error send sms to 12345678222 from 12345678111 Code = 1",
      "processing_date": "2019-03-11 21:00:00",
      "transaction_id": 123123,
      "delivery_status": "FAILED",
      "text": "Your reservation has been confirmed"
    },
    {
      "message_id": 3,
      "source_number": "12345678111",
      "destination_number": "12345678222",
      "fragments": 1,
      "cost": 2.7123,
      "status_id": "1",
      "processing_date": "2019-06-04 21:00:00",
      "transaction_id": 3333,
      "delivery_status": "DELIVERED",
      "text": "Your reservation has been canceled"
    }
  ],
  "total_count": 2
}
```

**SDK Code**

```python Example 1
import requests

url = "https://api.voximplant.com/platform_api/A2PGetSmsHistory"

headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Example 1
const url = 'https://api.voximplant.com/platform_api/A2PGetSmsHistory';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Example 1
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.voximplant.com/platform_api/A2PGetSmsHistory"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Example 1
require 'uri'
require 'net/http'

url = URI("https://api.voximplant.com/platform_api/A2PGetSmsHistory")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java Example 1
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.voximplant.com/platform_api/A2PGetSmsHistory")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php Example 1
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.voximplant.com/platform_api/A2PGetSmsHistory', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp Example 1
using RestSharp;

var client = new RestClient("https://api.voximplant.com/platform_api/A2PGetSmsHistory");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift Example 1
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.voximplant.com/platform_api/A2PGetSmsHistory")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```