> ## Documentation Index
> Fetch the complete documentation index at: https://help.emotive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Emotive's Open API Integration

> Track orders using Emotive's Open API Integration.

Before getting started, reach out to Support at [support@emotive.io](mailto:support@emotive.io) to receive your API key.

## Orders Endpoint

Orders Endpoint: [https://api.emotiveapp.co/ecommerce/v1/orders/](https://api.emotiveapp.co/ecommerce/v1/orders/)

Method: POST

Content-type: application/json

## Authorization

To access the Emotive Open API, a client must add an "Authorization" HTTPS header to every API request and that header's value must contain a valid API token. This will be provided to you by Emotive.

### Formatting

Your Authorization header should contain the word "Token" followed by a space, and the API key provided by Emotive.

```
Authorization: Token <api_token>
```

## Required Body Parameters

The minimum required parameters for Emotive to successfully track an order are listed below. Orders sent without all required data, or with invalid values will result in a 400 error code. A full order object example is available at the bottom of the article to show how the data payload should be formed.

```
{ 
  "customer": {
    "phone": "+14132737194"
  },
  "line_items": [ 
    { 
      "product":{
        "title": "Test Product",
        "sku": "SKU"
      },      
      "price": 0
    } 
  ],
  "total_price": 0,
  "order_id": 12346,
  "order_date": "2020-02-02 10:10:10"
}
```

## HTTPS Status Codes

### Success Codes

| Code | Description                                           |
| ---- | ----------------------------------------------------- |
| 200  | OK                                                    |
| 201  | Created                                               |
| 292  | Accepted (Request accepted, and queued for execution) |

### Client Error Codes

| Code | Description                                    |
| ---- | ---------------------------------------------- |
| 400  | Bad Request (missing or invalid data provided) |
| 401  | Unauthorized/Authentication Failure            |
| 403  | Forbidden                                      |
| 404  | Resource not found                             |
| 405  | Method not allowed                             |
| 409  | Conflict                                       |
| 412  | Precondition failed                            |
| 413  | Request entity too large                       |

### Server Error Codes

| Code | Description           |
| ---- | --------------------- |
| 500  | Internal server error |
| 501  | Not implemented       |
| 503  | Service unavailable   |

## Example POST Code Snippets

### Python

```
import http.client

conn = http.client.HTTPSConnection("api.emotiveapp.co")
payload = "{ \n \"customer\": {\n \"id\": \"10506\", \n \"first_name\": \"Test\", \n \"last_name\": \"Order\", \n \"phone\": \"+14132737194\",\n \"email\": \"support@emotive.io\",\n \"notes\":\"\",\n \"extra_data\": {}\n },\n \"shipping_address\": {\n \"state_code\": \"NJ\",\n \"name\": \"Stella Valle\",\n \"zip\": \"08822\",\n \"city\": \"Flemington\",\n \"address1\": \"12 MinneakoningRoad\",\n \"address2\": \"Suite 109B\",\n\t\t\"country_code\": \"us\",\n \"notes\":\"\",\n \"extra_data\": {}\n },\n \"line_items\": [ \n \t{ \n \"product\":{\n \t \"title\": \"Test Product\", \n \t\t \"sku\": \"3151235\"\n\t \t }, \n \"collection\": {\n \"title\": \"Testing Collection\", \n \"id\": \"TEST\"\n }, \t \t \n \"variant\": {\n \"id\": \"\", \n \"title\": \"\"\n },\n \"price\": 0,\n \"quantity\": 1,\n \"notes\":\"\",\n \"extra_data\": {}\n } \n ],\n \"discount_codes\": \"TEST15\",\n \"total_price\": 0,\n \"currency\": \"USD\",\n \"order_id\": 12346,\n \"order_date\": \"2020-02-02T10:10:10\", \n \"is_subscribed_order\": false,\n \"email_opt_in\": true,\n \"text_opt_in\": false,\n \"notes\": \"\",\n \"extra_data\": {},\n \"customer_tags\": [\"Test Customer\", \"New Tag\"]\n}"
headers = {
'Content-Type': 'application/json',
'Authorization': 'Token <api_token>'
}
conn.request("POST", "/ecommerce/v1/orders/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

### cURL

```
curl --location --request POST 'https://api.emotiveapp.co/ecommerce/v1/orders/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token <api_token>' \
--data-raw '{ 
  "customer": {
    "id": "10506", 
    "first_name": "Test", 
    "last_name": "Order", 
    "phone": "+14132737194",
    "email": "support@emotive.io",
    "notes":"",
    "extra_data": {}
  },
  "shipping_address": {
    "state_code": "NJ",
    "name": "Stella Valle",
    "zip": "08822",
    "city": "Flemington",
    "address1": "12 MinneakoningRoad",
    "address2": "Suite 109B",
    "country_code": "us",
    "notes":"",
    "extra_data": {}
  },
  "line_items": [ 
    { 
      "product":{
        "title": "Test Product", 
        "sku": "3151235"
      }, 
      "collection": {
        "title": "Testing Collection", 
        "id": "TEST"
      }, 
      "variant": {
        "id": "", 
        "title": ""
      },
      "price": 0,
      "quantity": 1,
      "notes":"",
      "extra_data": {}
    } 
  ],
  "discount_codes": "TEST15",
  "total_price": 0,
  "currency": "USD",
  "order_id": 12346,
  "order_date": "2020-02-02T10:10:10", 
  "is_subscribed_order": false,
  "email_opt_in": true,
  "text_opt_in": false,
  "notes": "",
  "extra_data": {},
  "customer_tags": ["Test Customer", "New Tag"]
}'
```
