> For the complete documentation index, see [llms.txt](https://photon-commerce.gitbook.io/photon-commerce-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://photon-commerce.gitbook.io/photon-commerce-api/update-doc-v4/add-line-item.md).

# Add Line Item

To add a new line item, submit a POST request with the data to be updated as a string of dictionary.

## Add a new line item

<mark style="color:orange;">`PUT`</mark> `https://api.photoncommerce.com/api/v4/line-items`

This method can be used to add one new line item at a time. The line item keys whose values can be added are listed in the code block after the following API method block.

#### Path Parameters

| Name        | Type   | Description                                                    |
| ----------- | ------ | -------------------------------------------------------------- |
| photon\_key | string | <p>Photon Key of the JSON file that needs to<br>be updated</p> |

#### Headers

| Name          | Type   | Description                                                                          |
| ------------- | ------ | ------------------------------------------------------------------------------------ |
| CLIENT-ID     | string | <p>Unique client-id provided upon user <br>registration</p>                          |
| AUTHORIZATION | string | <p>Pass your username and api key in the form<br>'apikey \<username>:\<api-key>'</p> |
| SECRET-KEY    | string | Secret key provided as a string                                                      |
| PASSWORD      | string | Password used during user registration                                               |
| Content-Type  | string | Set to "application/json"                                                            |

#### Request Body

| Name | Type   | Description                                                                                                                                                                     |
| ---- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| data | string | <p>String of dictionary containing fields to be <br>updated with their corresponding values<br>e.g {'SKU': '003',  'Description': 'MacBook', 'Price': 1299, 'Amount': 1299}</p> |

{% tabs %}
{% tab title="200 " %}

```
{"message":"Added line item successfully","status":"success"}
```

{% endtab %}
{% endtabs %}

Line item keys that can be added:

```
"SKU":                 <string- parsed SKU code>,
"Description":         <string- raw item description>,
"Date":                <date of the line item as a string "YYYY-MM-DD">,
"Order":               <integer - Order of the item>,
"Reference":           <string- Reference ID for the item>,
"QTY":                 <decimal number of units>,
"Unit":                <unit of measure>,
"Price":               <decimal unit price>,
"Amount":              <decimal total pricing>,
"Discount":            <decimal line item discount amount>,
"Tax_Rate":            <the tax rate levied>,
"Tax",                 <decimal line item tax amount>,
"Type"                 <inferred product or service string>
```

Syntax for sending a POST request to add a new line item:

{% tabs %}
{% tab title="cURL" %}

```
curl -X PUT -H 'Content-Type: application/json' -H "CLIENT-ID:<client-id>" -H "AUTHORIZATION:apikey <username>:<api-key>" -H 'PASSWORD:<password>' -H "SECRET-KEY:<secret-key>" -d '{'SKU': '003',  'Description': 'MacBook', 'Price': 1299, 'Amount': 1299}' "https://api.photoncommerce.com/api/v4/update/line-items?photon_key=<mention-the-photon-key-here>"
```

{% endtab %}

{% tab title="Python" %}

```
import requests

headers = {
    'Content-Type': 'application/json',
    'CLIENT-ID': '<client-id>',
    'AUTHORIZATION': 'apikey <username>:<api-key>',
    'PASSWORD': '<password>',
    'SECRET-KEY': '<secret-key>',
}

params = (
    ('photon_key', '<mention-the-photon-key-here>'),
)

data = '{"SKU": "003", "Description": "MacBook", "Price": 1299, "Amount": 1299}'

response = requests.put('https://api.photoncommerce.com/api/v4/update/line-items', headers=headers, params=params, data=data)
```

{% endtab %}

{% tab title="NodeJS" %}

```
var request = require('request');

var headers = {
    'Content-Type': 'application/json',
    'CLIENT-ID': '<client-id>',
    'AUTHORIZATION': 'apikey <username>:<api-key>',
    'PASSWORD': '<password>',
    'SECRET-KEY': '<secret-key>'
};

var dataString = '{SKU: 003, Description: MacBook, Price: 1299, Amount: 1299}';

var options = {
    url: 'https://api.photoncommerce.com/api/v4/update/line-items?photon_key=<mention-the-photon-key-here>',
    method: 'PUT',
    headers: headers,
    body: dataString
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);
```

{% endtab %}

{% tab title="Java" %}

```
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {
		URL url = new URL("https://api.photoncommerce.com/api/v4/update/line-items?photon_key=<mention-the-photon-key-here>");
		HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
		httpConn.setRequestMethod("PUT");

		httpConn.setRequestProperty("Content-Type", "application/json");
		httpConn.setRequestProperty("CLIENT-ID", "<client-id>");
		httpConn.setRequestProperty("AUTHORIZATION", "apikey <username>:<api-key>");
		httpConn.setRequestProperty("PASSWORD", "<password>");
		httpConn.setRequestProperty("SECRET-KEY", "<secret-key>");

		httpConn.setDoOutput(true);
		OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
		writer.write("{SKU: 003, Description: MacBook, Price: 1299, Amount: 1299}");
		writer.flush();
		writer.close();
		httpConn.getOutputStream().close();

		InputStream responseStream = httpConn.getResponseCode() / 100 == 2
				? httpConn.getInputStream()
				: httpConn.getErrorStream();
		Scanner s = new Scanner(responseStream).useDelimiter("\\A");
		String response = s.hasNext() ? s.next() : "";
		System.out.println(response);
	}
}

```

{% endtab %}
{% endtabs %}
