# Simulate an inbound SMS (test keys only)

Source: https://jointextkit.com/docs/api/test/simulate-inbound
Index: https://jointextkit.com/llms.txt

`POST /v1/test/inbound`

Runs through the real inbound pipeline and emits `message.received` with `simulated: true`. Once the account has live access, STOP, START, YES and HELP change consent only when `from` is a +1 500 555 number or one of your verified numbers; from any other number the message is handled as an ordinary one and the response carries a `notice`.

Send your API key as a bearer token: `Authorization: Bearer ssms_sk_...`. Test keys run this endpoint against the [sandbox](/docs/sandbox); see [Authentication](/docs/authentication) for key modes and scopes.

## Request body

JSON (`Content-Type: application/json`).

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `to` | string | No | One of your sandbox numbers (never a live number). Optional while the account has one sandbox number. |
| `from` | string | Yes |  |
| `body` | string | Yes |  |

## Responses

| Status | Meaning | Body |
| --- | --- | --- |
| 201 | Simulated inbound message, with `notice` when consent was left unchanged | `Message` |
| 401 | Missing, malformed, or revoked API key | `Error` |
| 402 | Billable live calls only: the prepaid credit balance cannot cover the call (insufficient_credits); nothing was done or charged | `Error` |
| 403 | Live keys not allowed | `Error` |
| 429 | Rate limit or quota exceeded | `Error` |

### 201: `Message` fields

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Example: `msg_a1B2c3D4e5F6g7H8`. |
| `object` | `message` |  |
| `to` | string | Example: `+15005550006`. |
| `from` | string | Example: `+15005550100`. |
| `body` | string |  |
| `direction` | `outbound`, `inbound` |  |
| `status` | `queued`, `sent`, `delivered`, `failed`, `blocked`, `received` | `blocked`: refused by one of our checks before any carrier saw it (opt-out, quiet hours, unregistered sender, content, allowance, spend limit, credits). Final, never charged; `failure` says why. `failed`: accepted, then not delivered. |
| `test` | boolean |  |
| `simulated` | boolean | True when nothing was handed to a carrier: every test-key message except one sent to your own verified phone. Always false on live messages. A simulated message still reaches `delivered`. |
| `notice` | string | Only on the response to POST /messages. Present when a test-key send to a real-looking number was simulated: says nothing was sent and how to send for real. |
| `schedule_id` | string | The recurring schedule this message is an occurrence of. Present only when set. |
| `tags` | array of string | The labels sent with the message (`tags` on POST /messages), lowercased. Present only when set. |
| `category` | `marketing`, `transactional`, `otp` | How the message was classified. Present when you sent one, or when it was classified as marketing. |
| `disclosures_added` | array of `brand`, `opt_out` | Wording we added to a message from a number linked to a registration ([what we add](/docs/compliance-checks#what-we-add)): `brand`, your business name in front of a person's first message; `opt_out`, " Reply STOP to opt out." on marketing that had none. `body` is the text as sent. Present only when we added something. |
| `deferred` | object | Present when the message was held for quiet hours and sent when the window opened. |
| `deferred.reason` | `quiet_hours` |  |
| `deferred.held_at` | string (date-time) |  |
| `redacted_at` | string (date-time) | When the message was redacted (POST /messages/{id}/redact): `body` is empty and `media` is gone. Present only then. |
| `links` | array of object | Links shortened with `shorten_links`, in the order they appear. On the send response and GET /messages/{id} (with clicks so far); not on list pages. `body` is the text as sent, with the short links. |
| `links[].url` | string | The link as you wrote it. |
| `links[].short_url` | string | Example: `https://links.example.com/Ab3dEf9h`. |
| `links[].clicks` | integer | Opens by people. Link previews (a messaging app fetching the link to draw a preview) are not counted. |
| `links[].first_clicked_at` | string (date-time) | Nullable. |
| `links[].last_clicked_at` | string (date-time) | Nullable. |
| `created_at` | string (date-time) |  |
| `media` | array of string (uri) | MMS attachments (inbound today). |
| `sent_by` | string | Console user or API key that composed it. |
| `failure_reason` | string | The carrier's raw text for a failed send. Kept for compatibility; see `failure`. |
| `attempts` | integer | Live sends: carrier submissions so far. More than 1 means it was retried. |
| `next_attempt_at` | string (date-time) | Present while queued for an automatic carrier retry. |
| `receipt_status` | `missing` | The carrier accepted the message but sent no delivery report within 72 hours. status stays sent. |
| `customer_id` | string | The customer this is attributed to. Present only when set. |
| `timeline` | array of object | Every status transition, oldest first. Inbound messages have a single `received`. |
| `timeline[].status` | `accepted`, `validated`, `queued`, `sent_to_carrier`, `carrier_accepted`, `retry_scheduled`, `delivered`, `failed`, `blocked`, `received` |  |
| `timeline[].at` | string (date-time) |  |
| `timeline[].attempt` | integer | Carrier attempt this step belongs to (from sent_to_carrier on). |
| `segments` | integer | Parts the body is split into (GSM-7: 160, then 153 each; UCS-2: 70, then 67). Example: `1`. |
| `encoding` | `gsm7`, `ucs2` |  |
| `price` | object | What this message costs, in USD: the outbound rate per segment, plus the recipient's carrier fee per segment, at cost, as its own line. Null on messages sent before prices were recorded. Nullable. |
| `price.total` | number | Example: `0.0082`. |
| `price.currency` | `usd` |  |
| `price.breakdown` | array of object |  |
| `price.breakdown[].label` | string |  |
| `price.breakdown[].amount` | number |  |
| `destination_carrier` | string | The recipient's mobile carrier, when a cached lookup knows it. Nullable. |
| `failure` | Failure | Null unless status is `failed`. Nullable. |

## Errors

| Status | When |
| --- | --- |
| 401 | Missing, malformed, or revoked API key |
| 402 | Billable live calls only: the prepaid credit balance cannot cover the call (insufficient_credits); nothing was done or charged |
| 403 | Live keys not allowed |
| 429 | Rate limit or quota exceeded |

Every error has the same JSON shape, and `request_id` matches the `X-Request-Id` response header. [Errors](/docs/errors) lists every code and what to do about it.

```json
{
  "error": {
    "code": "invalid_request",
    "message": "What went wrong, in plain words.",
    "param": "the_field",
    "request_id": "req_a1B2c3D4e5F6g7H8"
  }
}
```

## Examples

### Node.js

The Node.js SDK does not wrap this endpoint yet; call it over HTTP.

```javascript
const res = await fetch('https://api.jointextkit.com/v1/test/inbound', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.TEXTKIT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "from": "+15005550100",
    "body": "Hello from TextKit"
  }),
});

if (!res.ok) throw new Error((await res.json()).error.message);
const data = await res.json();
```

### PHP

```php
<?php

$ch = curl_init('https://api.jointextkit.com/v1/test/inbound');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('TEXTKIT_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'from' => '+15005550100',
        'body' => 'Hello from TextKit',
    ]),
]);

$data = json_decode(curl_exec($ch), true);
```

### Python

The Python SDK does not wrap this endpoint yet; call it over HTTP.

```python
import json, os, urllib.request

req = urllib.request.Request(
    "https://api.jointextkit.com/v1/test/inbound",
    method="POST",
    headers={
        "Authorization": f"Bearer {os.environ['TEXTKIT_API_KEY']}",
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "from": "+15005550100",
        "body": "Hello from TextKit"
    }).encode(),
)
with urllib.request.urlopen(req) as res:
    data = json.load(res)
```

### Ruby

```ruby
require "net/http"
require "json"

uri = URI("https://api.jointextkit.com/v1/test/inbound")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer #{ENV["TEXTKIT_API_KEY"]}"
req["Content-Type"] = "application/json"
req.body = {
  "from": "+15005550100",
  "body": "Hello from TextKit"
}.to_json

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
data = JSON.parse(res.body)
```

### Go

```go
package main

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

func main() {
	body := strings.NewReader(`{
	  "from": "+15005550100",
	  "body": "Hello from TextKit"
	}`)
	req, _ := http.NewRequest("POST", "https://api.jointextkit.com/v1/test/inbound", body)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("TEXTKIT_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	data, _ := io.ReadAll(res.Body)
	fmt.Println(res.Status, string(data))
}
```

### Rust

```rust
// cargo add reqwest --features blocking,json
// cargo add serde_json
use serde_json::json;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key = std::env::var("TEXTKIT_API_KEY")?;
    let res = reqwest::blocking::Client::new()
        .post("https://api.jointextkit.com/v1/test/inbound")
        .bearer_auth(key)
        .json(&json!({
          "from": "+15005550100",
          "body": "Hello from TextKit"
        }))
        .send()?
        .error_for_status()?;
    let data: serde_json::Value = res.json()?;
    println!("{data}");
    Ok(())
}
```

### Java

```java
import java.net.URI;
import java.net.http.*;

public class Main {
    public static void main(String[] args) throws Exception {
        var request = HttpRequest.newBuilder(URI.create("https://api.jointextkit.com/v1/test/inbound"))
            .header("Authorization", "Bearer " + System.getenv("TEXTKIT_API_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("""
                {
                  "from": "+15005550100",
                  "body": "Hello from TextKit"
                }
                """))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
```

### .NET

```csharp
using System.Net.Http.Headers;
using System.Text;

var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("TEXTKIT_API_KEY"));

var body = new StringContent("""
    {
      "from": "+15005550100",
      "body": "Hello from TextKit"
    }
    """, Encoding.UTF8, "application/json");
var res = await http.PostAsync("https://api.jointextkit.com/v1/test/inbound", body);
res.EnsureSuccessStatusCode();

var data = await res.Content.ReadAsStringAsync();
```

### cURL

```bash
curl -X POST "https://api.jointextkit.com/v1/test/inbound" \
  -H "Authorization: Bearer $TEXTKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "from": "+15005550100",
  "body": "Hello from TextKit"
}'
```

## Related

- Guide: [Sandbox & test numbers](/docs/sandbox)
- [All sandbox endpoints](/docs/api#test)
- [API reference](/docs/api)
