> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.tryenvoy.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.tryenvoy.ai/_mcp/server.

# Import carrier-preference CSV rows

POST https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch
Content-Type: application/json

CSV-specific preference import. Resolves an existing carrier by MC/DOT and writes lane preferences without creating or updating carrier or contact data.

**Authentication:** Supports API key and bearer token authentication.

Reference: https://docs.tryenvoy.ai/api-reference/endpoints/api/import-carrier-preference-csv-api-v-1-carriers-csv-lane-preferences-batch-post

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://tryenvoy.ai/api/v1` (Production, default)
- `https://staging.tryenvoy.ai/api/v1` (Staging)

## Request

### Headers

- `X-Organization-ID` (string, optional, nullable)
- `X-CSV-Import-ID` (string, optional, nullable) — Browser-generated UUID correlating every chunk of one CSV import attempt
- `X-CSV-Chunk-Index` (string, optional, nullable) — 1-based position of this chunk within the import
- `X-CSV-Chunk-Count` (string, optional, nullable) — Total number of chunks in the import
- `Idempotency-Key` (string, optional) — A unique key (up to 255 printable ASCII characters, e.g. a UUID) that makes a retry of this request safe. Envoy stores the response for 24 hours; a retry with the same key and the same request returns it again with `Idempotent-Replayed: true` instead of running twice. The same key with a different request returns 422 `idempotency_key_reused`; while the first request is still running, 409 `idempotency_key_in_progress`. 5xx and 429 responses are not stored.

### Body (application/json)

This endpoint expects a CsvCarrierLaneBatchRequest.

- `carrier_lane_preferences` (list of CsvCarrierLanePreference, required) — Carrier preference CSV rows (max 1000)

## Response

### 201

Successful Response

- `success` (boolean, required)
- `total` (integer, required)
- `successful` (integer, required)
- `failed` (integer, required)
- `created` (integer, required)
- `updated` (integer, required)
- `results` (list of CsvCarrierRowResult, required)
- `processed_at` (datetime, required)
- `backend_duration_ms` (double, optional, nullable) — Server processing time for this CSV import chunk

## Errors

### 401 Unauthorized Error

Not authenticated - missing or invalid token/API key

- `any`

### 403 Forbidden Error

Insufficient permissions for this operation

- `any`

### 409 Conflict Error

`idempotency_key_in_progress`: a request with this Idempotency-Key is still running; retry later

- `any`

### 422 Unprocessable Entity Error

Validation Error; or `idempotency_key_reused`: this Idempotency-Key was already used for a different request

- `detail` (list of ValidationError, optional)

### 429 Too Many Requests Error

Rate limit exceeded - see Retry-After header

- `any`

## Types

### CsvCarrierLanePreference

Minimal CSV preference row that cannot mutate carrier/contact data.

- `lane` (CsvCarrierLane, required) — Required origin and optional destination
- `source_row` (integer, optional, nullable) — Original 1-based CSV data-row number (header excluded)
- `external_id` (string, optional, nullable) — Optional idempotency identifier
- `carrier_name` (string, optional, nullable) — Optional display/error context
- `tms_carrier_id` (string, optional, nullable) — Supplemental metadata; not an identity key
- `mc_number` (string, optional, nullable) — MC number
- `dot_number` (string, optional, nullable) — DOT number
- `completed_loads` (integer, optional, nullable)
- `preference_score` (integer, optional, nullable)
- `equipment_types` (list of enum, optional, nullable)
  - Allowed values: `VAN`, `REEFER`, `FLATBED`, `STEPDECK`, `RGN`, `CONESTOGA`, `BOX_TRUCK`, `CONTAINER`, `INTERMODAL`, `POWER_ONLY`, `TANKER`, `LOWBOY`, `HOTSHOT`, `AUTO_CARRIER`, `DRY_BULK`, `DRY_TEAM`, `REEFER_TEAM`, `LTL`, `OTHER`, `VAN/REEFER`

### CsvCarrierRowResult

Safe, actionable result for one carrier-related CSV row.

- `success` (boolean, required)
- `source_row` (integer, optional, nullable)
- `identifier` (string, optional, nullable)
- `carrier_id` (string, optional, nullable)
- `operation` (string, optional, nullable)
- `error_code` (string, optional, nullable)
- `error_field` (string, optional, nullable)
- `error` (string, optional, nullable)

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `input` (any, optional)
- `ctx` (ValidationErrorCtx, optional)

### CsvCarrierLane

Lane fields accepted by the carrier-preference CSV contract.

- `origin_city` (string, required)
- `origin_state` (string, required)
- `destination_city` (string, optional, nullable)
- `destination_state` (string, optional, nullable)

### ValidationErrorLocItems

- string
- integer

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "carrier_lane_preferences": [
    {
      "lane": {
        "origin_city": "string",
        "origin_state": "string"
      }
    }
  ]
}
```

**Response**

```json
{
  "success": true,
  "total": 1,
  "successful": 1,
  "failed": 1,
  "created": 1,
  "updated": 1,
  "results": [
    {
      "success": true,
      "source_row": 1,
      "identifier": "string",
      "carrier_id": "string",
      "operation": "string",
      "error_code": "string",
      "error_field": "string",
      "error": "string"
    }
  ],
  "processed_at": "2024-01-15T09:30:00Z",
  "backend_duration_ms": 1.1
}
```

**SDK Code**

```python
import requests

url = "https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch"

payload = { "carrier_lane_preferences": [{ "lane": {
                "origin_city": "string",
                "origin_state": "string"
            } }] }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"carrier_lane_preferences":[{"lane":{"origin_city":"string","origin_state":"string"}}]}'
};

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

```go
package main

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

func main() {

	url := "https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch"

	payload := strings.NewReader("{\n  \"carrier_lane_preferences\": [\n    {\n      \"lane\": {\n        \"origin_city\": \"string\",\n        \"origin_state\": \"string\"\n      }\n    }\n  ]\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	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
require 'uri'
require 'net/http'

url = URI("https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"carrier_lane_preferences\": [\n    {\n      \"lane\": {\n        \"origin_city\": \"string\",\n        \"origin_state\": \"string\"\n      }\n    }\n  ]\n}"

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

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

HttpResponse<String> response = Unirest.post("https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"carrier_lane_preferences\": [\n    {\n      \"lane\": {\n        \"origin_city\": \"string\",\n        \"origin_state\": \"string\"\n      }\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch', [
  'body' => '{
  "carrier_lane_preferences": [
    {
      "lane": {
        "origin_city": "string",
        "origin_state": "string"
      }
    }
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"carrier_lane_preferences\": [\n    {\n      \"lane\": {\n        \"origin_city\": \"string\",\n        \"origin_state\": \"string\"\n      }\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["carrier_lane_preferences": [["lane": [
        "origin_city": "string",
        "origin_state": "string"
      ]]]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://tryenvoy.ai/api/v1/carriers/csv/lane-preferences/batch")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```