# Bulk create or update contacts

Source: https://jointextkit.com/docs/api/contacts/import
Index: https://jointextkit.com/llms.txt

`POST /v1/contacts/import`

Up to 500 per request, keyed on phone number, with the same merge rule as POST /contacts. Rows that cannot be imported come back in skipped; the rest still land. `dry_run: true` returns the summary (found, valid, malformed, duplicates, landlines, already opted out, will create / update, eligible) and writes nothing. A row with `opt_in.status: true` (or a date or source) stores opt-in evidence in the consent ledger; `opt_in.status: false` records the number as opted out. An import never opts anyone back in.

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 |
| --- | --- | --- | --- |
| `contacts` | array of ContactInput | Yes | At most 500 items. |
| `campaign_id` | string | No | Applies to every opt_in row that does not name its own campaign_id Example: `reg_a1B2c3D4e5F6`. |
| `dry_run` | boolean | No |  |
| `check_line_types` | boolean | No | dry_run only. Looks up line types to count landlines; live lookups are paid, so only the first 500 numbers are checked. |
| `import_id` | string | No | From a previous response, to group several requests as one import. |
| `name` | string | No | A label for the import (first request only). |

## Responses

| Status | Meaning | Body |
| --- | --- | --- |
| 200 | Import result, or the dry-run preview | JSON object |
| 400 | Invalid request | `Error` |
| 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` |
| 429 | Rate limit or quota exceeded | `Error` |

### 200: response fields

| Field | Type | Description |
| --- | --- | --- |
| `object` | `contact_import`, `contact_import_preview` |  |
| `created` | integer |  |
| `updated` | integer |  |
| `skipped` | array of object |  |
| `skipped[].index` | integer | Position of the row in the request |
| `skipped[].value` | string |  |
| `skipped[].reason` | string |  |
| `import_id` | string | Example: `imp_a1B2c3D4e5`. |
| `opted_out` | integer | Rows recorded as opted out because they were marked unsubscribed. |
| `summary` | object | dry_run only. |
| `summary.found` | integer |  |
| `summary.valid` | integer |  |
| `summary.malformed` | integer |  |
| `summary.duplicates` | integer |  |
| `summary.landlines` | integer | null unless check_line_types was set Nullable. |
| `summary.already_opted_out` | integer |  |
| `summary.marked_unsubscribed` | integer |  |
| `summary.will_create` | integer |  |
| `summary.will_update` | integer |  |
| `summary.eligible` | integer | Would receive a broadcast today |
| `rejected` | array of object | dry_run only. |
| `rejected[].index` | integer |  |
| `rejected[].phone_number` | string |  |
| `rejected[].reason` | `malformed`, `duplicate`, `landline` |  |
| `rejected[].detail` | string |  |

## Errors

| Status | When |
| --- | --- |
| 400 | Invalid request |
| 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 |
| 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

```javascript
import { TextKit } from 'jointextkit'; // npm install jointextkit

const sms = new TextKit(process.env.TEXTKIT_API_KEY);

const result = await sms.contacts.import([
  { phoneNumber: '+14155550132', name: 'Jane Doe', tags: ['customers'] },
  { phoneNumber: '+14155550133', name: 'Sam Lee' },
]);
```

### PHP

```php
<?php

$ch = curl_init('https://api.jointextkit.com/v1/contacts/import');
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([
        'contacts' => [
            [
                'phone_number' => '+14155550132',
            ],
        ],
        'campaign_id' => 'reg_a1B2c3D4e5F6',
    ]),
]);

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

### Python

```python
import os
from jointextkit import TextKit  # pip install jointextkit

client = TextKit(os.environ["TEXTKIT_API_KEY"])

result = client.contacts.import_([
    {"phone_number": "+14155550132", "name": "Jane Doe", "tags": ["customers"]},
    {"phone_number": "+14155550133", "name": "Sam Lee"},
])
```

### Ruby

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

uri = URI("https://api.jointextkit.com/v1/contacts/import")
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer #{ENV["TEXTKIT_API_KEY"]}"
req["Content-Type"] = "application/json"
req.body = {
  "contacts": [
    {
      "phone_number": "+14155550132"
    }
  ],
  "campaign_id": "reg_a1B2c3D4e5F6"
}.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(`{
	  "contacts": [
	    {
	      "phone_number": "+14155550132"
	    }
	  ],
	  "campaign_id": "reg_a1B2c3D4e5F6"
	}`)
	req, _ := http.NewRequest("POST", "https://api.jointextkit.com/v1/contacts/import", 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/contacts/import")
        .bearer_auth(key)
        .json(&json!({
          "contacts": [
            {
              "phone_number": "+14155550132"
            }
          ],
          "campaign_id": "reg_a1B2c3D4e5F6"
        }))
        .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/contacts/import"))
            .header("Authorization", "Bearer " + System.getenv("TEXTKIT_API_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("""
                {
                  "contacts": [
                    {
                      "phone_number": "+14155550132"
                    }
                  ],
                  "campaign_id": "reg_a1B2c3D4e5F6"
                }
                """))
            .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("""
    {
      "contacts": [
        {
          "phone_number": "+14155550132"
        }
      ],
      "campaign_id": "reg_a1B2c3D4e5F6"
    }
    """, Encoding.UTF8, "application/json");
var res = await http.PostAsync("https://api.jointextkit.com/v1/contacts/import", body);
res.EnsureSuccessStatusCode();

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

### cURL

```bash
curl -X POST "https://api.jointextkit.com/v1/contacts/import" \
  -H "Authorization: Bearer $TEXTKIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "contacts": [
    {
      "phone_number": "+14155550132"
    }
  ],
  "campaign_id": "reg_a1B2c3D4e5F6"
}'
```

## Related

- Guide: [Contacts](/docs/contacts)
- [All contacts endpoints](/docs/api#contacts)
- [API reference](/docs/api)
