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

# GetSmsHistory

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

Gets the history of sent and/or received SMS.

Allowed roles: `Owner`, `Admin`, `Developer`, `Supervisor`, `Accountant`, `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/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
- `direction` (string, optional) — Sent or received SMS. Possible values: 'IN', 'OUT', 'in, 'out'. Leave blank to get both incoming and outgoing messages
- `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 to perform search. Format is 'yyyy-MM-dd HH:mm:ss', time zone is UTC
- `to_date` (string, optional) — Date until which to perform search. 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**

## Response

### 200

Successful response

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

## Types

### SmsHistoryType

The [GetSmsHistory] function result.

- `message_id` (integer, optional) — Message ID
- `source_number` (SmsHistoryTypeSourceNumber, optional) — Number being called from
- `destination_number` (SmsHistoryTypeDestinationNumber, optional) — Number being called to
- `direction` (string, optional) — Incoming or outgoing message
- `fragments` (integer, optional) — Number of fragments the initial message is divided into
- `cost` (double, optional) — Cost of the message
- `status_id` (string, optional) — Status of the message. The possible values are: 1 — Success, 2 — Error, 3 — Waiting
- `error_message` (string, optional) — Error message (if any)
- `processed_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) — Id of the transaction for this message
- `text` (string, optional) — Stored message text

### SmsHistoryTypeSourceNumber

Number being called from

- integer
- string

### SmsHistoryTypeDestinationNumber

Number being called to

- integer
- string

## Examples

**Response**

```json
{
  "result": [
    {
      "message_id": 1,
      "source_number": "12345678111",
      "destination_number": "12345678222",
      "direction": "IN",
      "fragments": 1,
      "cost": 4.3437,
      "status_id": "2",
      "error_message": "Some error message text here",
      "processed_date": "2019-03-11 21:00:00",
      "transaction_id": 12,
      "text": "Hi!"
    },
    {
      "message_id": 3,
      "source_number": "12345678111",
      "destination_number": "12345678222",
      "direction": "IN",
      "fragments": 1,
      "cost": 2.7123,
      "status_id": "1",
      "processed_date": "2019-06-04 21:00:00",
      "transaction_id": 3333,
      "text": "Sup?"
    }
  ],
  "total_count": 2
}
```

**SDK Code**

```python Example 1
import requests

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

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

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

print(response.json())
```

```javascript Example 1
const url = 'https://api.voximplant.com/platform_api/GetSmsHistory';
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/GetSmsHistory"

	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/GetSmsHistory")

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/GetSmsHistory")
  .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/GetSmsHistory', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp Example 1
using RestSharp;

var client = new RestClient("https://api.voximplant.com/platform_api/GetSmsHistory");
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/GetSmsHistory")! 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()
```