> For a complete page index, fetch https://developer.close.com/llms.txt

# Create an SMS activity

POST https://api.close.com/api/v1/activity/sms/
Content-Type: application/json

*status* must be one of the following:

 - `inbox` to log an already received SMS.
 - `draft` to create a draft SMS.
 - `scheduled` to send an SMS at a scheduled date and time, which must be specified in the `date_scheduled` field.
 - `outbox` to actually **send** an SMS. To delay SMS sending by a few seconds (to allow undo), specify `send_in` in seconds (must be less than 60).
 - `sent` to log an already sent SMS.

Only drafts can be modified, and their status can be changed to `scheduled` (to send later) or `outbox` (to send immediately). Scheduled SMS, or SMS in outbox that weren't sent yet can be canceled by setting the status back to `draft`.

You have to provide a `local_phone` that will be used to send the SMS. The number you choose has to be associated with a Phone Number of type `internal`. See the [Phone Numbers](https://developer.close.com/api/resources/phone-numbers) paragraph for more details.

A `template_id` referencing an SMS Template may be provided instead of `text` to automatically render that template and use the content as `text`.

When `direction` is not provided, but `status="inbox"`, `direction` will default to "inbound". Otherwise, `direction` defaults to "outbound".

When creating a new SMS with the status set to `inbox`, you can pass the query parameter `send_to_inbox` with the value of `true`  to create a corresponding Inbox Notification for the SMS.

Reference: https://developer.close.com/api/resources/activities/sms/create

## Authentication

- `Authorization` header (basic auth, required) — Use your API key as the username and leave the password empty.
- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Query parameters

- `send_to_inbox` (boolean, optional)

### Body (application/json)

This endpoint expects an object.

- `status` (enum, required)
  - Allowed values: `inbox`, `draft`, `scheduled`, `outbox`, `sent`, `error`
- `activity_at` (datetime, optional, nullable)
- `attachments` (list of object, optional, nullable)
  - `content_type` (enum, required)
    - Allowed values: `application/pdf`, `application/vcard`, `audio/3gpp`, `audio/3gpp2`, `audio/L24`, `audio/ac3`, `audio/amr`, `audio/amr-nb`, `audio/basic`, `audio/mp4`, `audio/mpeg`, `audio/ogg`, `audio/vnd.rn-realaudio`, `audio/vnd.wave`, `audio/webm`, `image/bmp`, `image/gif`, `image/jpeg`, `image/jpg`, `image/png`, `image/tiff`, `text/calendar`, `text/csv`, `text/directory`, `text/richtext`, `text/rtf`, `text/vcard`, `text/x-vcard`, `video/3gpp`, `video/3gpp-tt`, `video/3gpp2`, `video/H261`, `video/H263`, `video/H263-1998`, `video/H263-2000`, `video/H264`, `video/mp4`, `video/mpeg`, `video/quicktime`, `video/webm`
  - `filename` (string, required)
  - `url` (string, required)
- `caller_id_mode` (enum, optional)
  - Allowed values: `fixed`, `auto`
- `contact_id` (string, optional, nullable)
- `created_by` (string, optional, nullable)
- `date_created` (datetime, optional, nullable)
- `direction` (enum, optional)
  - Allowed values: `inbound`, `outbound`
- `lead_id` (string, optional, nullable)
- `local_phone` (string, optional, nullable) — Phone number in E.164 format
- `organization_id` (string, optional, nullable)
- `remote_phone` (string, optional, nullable) — Phone number in E.164 format
- `source` (enum, optional)
  - Allowed values: `Close.io`, `External`
- `template_id` (string, optional, nullable)
- `text` (string, optional, nullable)
- `user_id` (string, optional, nullable)

## Response

### 200

Successful response

- `_type` (string, required)
- `activity_at` (datetime, required, nullable)
- `caller_id_mode` (enum, required, nullable) — How a caller's outbound number is chosen. Fixed uses a single configured number; Auto lets Close select the best number per call/SMS (Managed by Close Caller ID).
  - Allowed values: `fixed`, `auto`
- `caller_id_reason` (enum, required, nullable) — Why a number was chosen in Auto mode: reused from a prior communication (context), picked for geographic proximity (local_presence), or the default/oldest fallback.
  - Allowed values: `context`, `local_presence`, `fallback`
- `contact_id` (string, required, nullable)
- `cost` (string, required, nullable)
- `created_by` (string, required, nullable)
- `date_created` (datetime, required)
- `date_scheduled` (datetime, required, nullable)
- `date_sent` (datetime, required, nullable)
- `date_updated` (datetime, required)
- `direction` (enum, required) — Direction of a phone activity, such as a call or an SMS message.
  - Allowed values: `inbound`, `outbound`
- `error_message` (string, required, nullable)
- `id` (string, required)
- `lead_id` (string, required, nullable)
- `local_country_iso` (string, required, nullable)
- `local_phone` (string, required, nullable)
- `local_phone_formatted` (string, required, nullable)
- `organization_id` (string, required)
- `remote_country_iso` (string, required, nullable)
- `remote_phone` (string, required, nullable)
- `remote_phone_formatted` (string, required, nullable)
- `source` (enum, required) — Source of a phone activity. Describes whether the phone activity (such as a call or an SMS) was handled by Close's telephony provider or handled externally by a 3rd party and is merely logged in Close.
  - Allowed values: `Close.io`, `External`
- `status` (enum, required) — Status of a message, such as Email or SMS.
  - Allowed values: `inbox`, `draft`, `scheduled`, `outbox`, `sent`, `error`
- `template_id` (string, required, nullable)
- `text` (string, required, nullable)
- `updated_by` (string, required, nullable)
- `user_id` (string, required, nullable)
- `users` (list of string, required)
- `agent_action_reason` (string, optional, nullable)
- `agent_config_id` (string, optional, nullable)
- `created_by_name` (string, optional, nullable)
- `sequence_id` (string, optional, nullable)
- `sequence_name` (string, optional, nullable)
- `sequence_subscription_id` (string, optional, nullable)
- `updated_by_name` (string, optional, nullable)
- `user_name` (string, optional, nullable)

## Errors

### 400 Bad Request Error

Bad request

- `any`

### 401 Unauthorized Error

Unauthorized

- `any`

### 404 Not Found Error

Not found

- `any`

## Examples

**Request**

```json
{
  "status": "inbox",
  "contact_id": "cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk",
  "direction": "inbound",
  "lead_id": "lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb",
  "local_phone": "+14154445555",
  "remote_phone": "+18183334444",
  "source": "External",
  "text": "Hi! This is a reminder that we have a call scheduled for 12pm PT today."
}
```

**Response**

```json
{
  "_type": "SMS",
  "activity_at": "2016-10-03T16:06:11.167000+00:00",
  "caller_id_mode": null,
  "caller_id_reason": null,
  "contact_id": "cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk",
  "cost": "1",
  "created_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "date_created": "2016-10-03T16:06:11.167000+00:00",
  "date_scheduled": null,
  "date_sent": null,
  "date_updated": "2016-10-03T16:06:11.167000+00:00",
  "direction": "outbound",
  "error_message": null,
  "id": "acti_12358hIUhaklslYoYSbtozZuUTyB2zO2nhm7iVSpZpp",
  "lead_id": "lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb",
  "local_country_iso": "US",
  "local_phone": "+14154445555",
  "local_phone_formatted": "+1 415-444-5555",
  "organization_id": "orga_RbREgmiiwcr1w2b4cOnCMQaQPSIFxMqAD2Dh243uxcH",
  "remote_country_iso": "US",
  "remote_phone": "+18183334444",
  "remote_phone_formatted": "+1 818-333-4444",
  "source": "Close.io",
  "status": "outbox",
  "template_id": null,
  "text": "Hi! This is a reminder that we have a call scheduled for 12pm PT today.",
  "updated_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "user_id": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "users": [],
  "created_by_name": "Tobias Fuenke",
  "updated_by_name": "Tobias Fuenke",
  "user_name": "Tobias Fuenke"
}
```

**SDK Code**

```python activities.sms_create_example
import requests

url = "https://api.close.com/api/v1/activity/sms/"

payload = {
    "status": "inbox",
    "contact_id": "cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk",
    "direction": "inbound",
    "lead_id": "lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb",
    "local_phone": "+14154445555",
    "remote_phone": "+18183334444",
    "source": "External",
    "text": "Hi! This is a reminder that we have a call scheduled for 12pm PT today."
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript activities.sms_create_example
const url = 'https://api.close.com/api/v1/activity/sms/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"status":"inbox","contact_id":"cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk","direction":"inbound","lead_id":"lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb","local_phone":"+14154445555","remote_phone":"+18183334444","source":"External","text":"Hi! This is a reminder that we have a call scheduled for 12pm PT today."}'
};

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

```go activities.sms_create_example
package main

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

func main() {

	url := "https://api.close.com/api/v1/activity/sms/"

	payload := strings.NewReader("{\n  \"status\": \"inbox\",\n  \"contact_id\": \"cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk\",\n  \"direction\": \"inbound\",\n  \"lead_id\": \"lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb\",\n  \"local_phone\": \"+14154445555\",\n  \"remote_phone\": \"+18183334444\",\n  \"source\": \"External\",\n  \"text\": \"Hi! This is a reminder that we have a call scheduled for 12pm PT today.\"\n}")

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

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

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

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

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

}
```

```ruby activities.sms_create_example
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/activity/sms/")

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

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"status\": \"inbox\",\n  \"contact_id\": \"cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk\",\n  \"direction\": \"inbound\",\n  \"lead_id\": \"lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb\",\n  \"local_phone\": \"+14154445555\",\n  \"remote_phone\": \"+18183334444\",\n  \"source\": \"External\",\n  \"text\": \"Hi! This is a reminder that we have a call scheduled for 12pm PT today.\"\n}"

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

```java activities.sms_create_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/activity/sms/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"status\": \"inbox\",\n  \"contact_id\": \"cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk\",\n  \"direction\": \"inbound\",\n  \"lead_id\": \"lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb\",\n  \"local_phone\": \"+14154445555\",\n  \"remote_phone\": \"+18183334444\",\n  \"source\": \"External\",\n  \"text\": \"Hi! This is a reminder that we have a call scheduled for 12pm PT today.\"\n}")
  .asString();
```

```php activities.sms_create_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/activity/sms/', [
  'body' => '{
  "status": "inbox",
  "contact_id": "cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk",
  "direction": "inbound",
  "lead_id": "lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb",
  "local_phone": "+14154445555",
  "remote_phone": "+18183334444",
  "source": "External",
  "text": "Hi! This is a reminder that we have a call scheduled for 12pm PT today."
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

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

```csharp activities.sms_create_example
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/activity/sms/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"status\": \"inbox\",\n  \"contact_id\": \"cont_q4xYmlGhA3060dEl0NDJuHRxPMuVjqLn30AFSzh1fRk\",\n  \"direction\": \"inbound\",\n  \"lead_id\": \"lead_iuSXNk1x3446ggPVwQS7ynmp8pGRIDieRYiCnuo4yFb\",\n  \"local_phone\": \"+14154445555\",\n  \"remote_phone\": \"+18183334444\",\n  \"source\": \"External\",\n  \"text\": \"Hi! This is a reminder that we have a call scheduled for 12pm PT today.\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```