> This page is for Developer.

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

# Create Invoice

POST https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices
Content-Type: application/json

Create Invoice

Reference: https://docs.bigcommerce.com/developer/api-reference/rest/b2b/management/invoice-management/invoice/post-invoices

## Authentication

- `X-Auth-Token` header (required) — | Header | Argument | Description | |:-------|:---------|:------------| | `X-Auth-Token` | `access_token` | For more about API accounts that generate `access_token`s, see our [Guide to API Accounts](/developer/docs/overview/api-fundamentals/api-accounts). | For example requests and more information about authenticating BigCommerce APIs, see [Authentication and Example Requests](/developer/docs/overview/api-fundamentals/api-accounts#x-auth-token-header-example-requests). For more about BigCommerce OAuth scopes, see our [Guide to API Accounts](/developer/docs/overview/api-fundamentals/api-accounts#oauth-scopes). For a list of API status codes, see [API Status Codes](/developer/api-reference/rest/overview#rest-http-status-codes).
- `X-Store-Hash` header (required) — | Header | Argument | Description | |:-------|:---------|:------------| | `X-Store-Hash` | `store_hash` | The unique store hash associated with a BigCommerce store that has B2B Edition enabled. |

## Request

### Body (application/json)

This endpoint expects an object.

- `invoiceNumber` (string, required) — Invoice no.
- `originalBalance` (InvoicesPostRequestBodyContentApplicationJsonSchemaOriginalBalance, required) — Original balance
- `openBalance` (InvoicesPostRequestBodyContentApplicationJsonSchemaOpenBalance, required) — Open balance , when it is \<= 0, status will be auto set to 2
- `customerId` (string, required) — B2B Edition Company ID
- `type` (string, optional, default: Invoice) — Invoice type
- `dueDate` (integer, optional) — The due date for this invoice, specified as a Unix timestamp. If left empty, it will be set to the current date plus a pre-configured number of days (set in your B2B Edition control panel settings).
- `status` (enum, optional, default: 0) — Invoice status. Possible values: 0: Open (default) 1: Partially paid 2: Completed The status will automatically be set to Completed (2) when the open balance becomes zero or negative.
  - Allowed values: `0`, `1`, `2`
- `orderNumber` (string, optional) — BigCommerce order ID associated with this invoice.
- `purchaseOrderNumber` (string, optional) — PO Number
- `issuedAt` (double, optional) — When the invoice was created. The current timestamp is the default.
- `details` (InvoicesPostRequestBodyContentApplicationJsonSchemaDetails, optional) — Invoice details
- `source` (enum, optional, default: 0) — The source of the invoice. Possible values: 0: B2B Edition 1: External
  - Allowed values: `0`, `1`
- `externalId` (string, optional) — ERP Invoice ID
- `externalCustomerId` (string, optional) — ERP Customer ID
- `channelId` (integer, optional) — BigCommerce Channel ID
- `externalPdfUrl` (string, optional) — The URL of an externally hosted PDF file to be associated with this invoice. The file size must not exceed 5 MB. Ensure that the file hosting service supports Cross-Origin Resource Sharing (CORS) to allow our system to access the file.
- `termsConditions` (string, optional) — Terms & Conditions. Visible on the default Invoice PDF.
- `extraFields` (list of InvoicesPostRequestBodyContentApplicationJsonSchemaExtraFieldsItems, optional)

## Response

### 200

OK

- `code` (double, optional) — 200
- `data` (InvoicesPostResponsesContentApplicationJsonSchemaData, optional)
- `meta` (InvoicesPostResponsesContentApplicationJsonSchemaMeta, optional)

## Types

### InvoicesPostRequestBodyContentApplicationJsonSchemaOriginalBalance

Original balance

- `code` (string, required) — Currency code
- `value` (double, required) — Amount

### InvoicesPostRequestBodyContentApplicationJsonSchemaOpenBalance

Open balance , when it is \<= 0, status will be auto set to 2

- `code` (string, required) — Currency code
- `value` (double, required) — Amount

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetails

Invoice details

- `header` (InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeader, optional)
- `details` (InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetails, optional)

### InvoicesPostRequestBodyContentApplicationJsonSchemaExtraFieldsItems

- `fieldName` (string, required) — Field name that config in you store
- `fieldValue` (string, required) — Value of the extra field.

### InvoicesPostResponsesContentApplicationJsonSchemaData

- `id` (double, optional) — Invoice ID

### InvoicesPostResponsesContentApplicationJsonSchemaMeta

- `message` (string, optional) — Success
- `errors` (string, optional)

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeader

- `costLines` (list of InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeaderCostLinesItems, optional) — Invoice cost information. This field is optional. If provided, it should contain an array of cost line items. The information in this field will be displayed on the invoice detail page.
- `billingAddress` (InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeaderBillingAddress, optional) — Invoice billing address. This field is optional. If provided, it should contain an object with address details.
- `shippingAddresses` (list of InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeaderShippingAddressesItems, optional) — Invoice shipping address. This field is optional. If provided, it should contain an object with address details.

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetails

- `shipments` (list of InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetailsShipmentsItems, optional) — Invoice shipments. This field is optional. If provided, it should contain an array of shipments. Required fields within each shipment object can be an empty string.
- `lineItems` (list of InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetailsLineItemsItems, optional) — Products within the invoice. This field is optional. If provided, it should contain an array of products.

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeaderCostLinesItems

- `amount` (InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeaderCostLinesItemsAmount, required) — cost amount
- `description` (string, required) — Price description, e.g., subtotal or other types of prices or fees.

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeaderBillingAddress

Invoice billing address. This field is optional. If provided, it should contain an object with address details.

- `city` (string, required)
- `state` (string, required)
- `country` (string, required)
- `street1` (string, required)
- `street2` (string, required)
- `zipCode` (string, required)
- `lastName` (string, required)
- `firstName` (string, required)

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeaderShippingAddressesItems

- `city` (string, required)
- `state` (string, required)
- `country` (string, required)
- `street1` (string, required)
- `street2` (string, required)
- `zipCode` (string, required)
- `lastName` (string, required)
- `firstName` (string, required)

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetailsShipmentsItems

- `addressIndex` (string, required) — address ID
- `shipDate` (string, required) — shipment time
- `shipVia` (string, required)
- `trackingNumber` (string, required) — tracking number
- `comments` (string, required)

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetailsLineItemsItems

- `sku` (string, required) — product sku
- `quantity` (string, required) — product quantity
- `unitPrice` (InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetailsLineItemsItemsUnitPrice, required) — product unit price
- `type` (string, optional) — product type
- `comments` (string, optional)
- `description` (string, optional) — Product description or product name. This field is required for custom product.
- `unitDiscount` (InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetailsLineItemsItemsUnitDiscount, optional) — Product level discount details. This field is optional. If provided, it should contain a discount object.

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsHeaderCostLinesItemsAmount

cost amount

- `code` (string, required) — currency code
- `value` (string, required) — amount

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetailsLineItemsItemsUnitPrice

product unit price

- `code` (string, required) — currency code
- `value` (string, required) — amount

### InvoicesPostRequestBodyContentApplicationJsonSchemaDetailsDetailsLineItemsItemsUnitDiscount

Product level discount details. This field is optional. If provided, it should contain a discount object.

- `code` (string, required) — currency code
- `value` (string, required) — amount

## Examples

### Create an invoice

**Request**

```json
{
  "invoiceNumber": "0000001",
  "originalBalance": {
    "code": "USD",
    "value": 100
  },
  "openBalance": {
    "code": "USD",
    "value": 100
  },
  "customerId": "12345",
  "dueDate": 1619161808,
  "status": 0,
  "issuedAt": 1619161808,
  "details": {
    "header": {
      "costLines": [
        {
          "amount": {
            "code": "USD",
            "value": "90.00"
          },
          "description": "Subtotal"
        },
        {
          "amount": {
            "code": "USD",
            "value": "10.00"
          },
          "description": "Freight"
        },
        {
          "amount": {
            "code": "USD",
            "value": "0.00"
          },
          "description": "Sales Tax"
        }
      ],
      "billingAddress": {
        "city": "Chengdu",
        "state": "Sichuan",
        "country": "China",
        "street1": "TianFuWuJie",
        "street2": "",
        "zipCode": "12345",
        "lastName": "Test",
        "firstName": "B2B"
      },
      "shippingAddresses": [
        {
          "city": "Chengdu",
          "state": "Sichuan",
          "country": "China",
          "street1": "TianFuWuJie",
          "street2": "",
          "zipCode": "12345",
          "lastName": "Test",
          "firstName": "B2B"
        }
      ]
    },
    "details": {
      "lineItems": [
        {
          "sku": "Test-1",
          "quantity": "2",
          "unitPrice": {
            "code": "USD",
            "value": "40.00"
          },
          "description": "A custom product requires a description."
        }
      ]
    }
  },
  "channelId": 1
}
```

**Response**

```json
{
  "code": 200,
  "data": {
    "id": 12
  },
  "meta": {
    "message": "Success"
  }
}
```

**SDK Code**

```python Create an invoice
import requests

url = "https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices"

payload = {
    "invoiceNumber": "0000001",
    "originalBalance": {
        "code": "USD",
        "value": 100
    },
    "openBalance": {
        "code": "USD",
        "value": 100
    },
    "customerId": "12345",
    "dueDate": 1619161808,
    "status": 0,
    "issuedAt": 1619161808,
    "details": {
        "header": {
            "costLines": [
                {
                    "amount": {
                        "code": "USD",
                        "value": "90.00"
                    },
                    "description": "Subtotal"
                },
                {
                    "amount": {
                        "code": "USD",
                        "value": "10.00"
                    },
                    "description": "Freight"
                },
                {
                    "amount": {
                        "code": "USD",
                        "value": "0.00"
                    },
                    "description": "Sales Tax"
                }
            ],
            "billingAddress": {
                "city": "Chengdu",
                "state": "Sichuan",
                "country": "China",
                "street1": "TianFuWuJie",
                "street2": "",
                "zipCode": "12345",
                "lastName": "Test",
                "firstName": "B2B"
            },
            "shippingAddresses": [
                {
                    "city": "Chengdu",
                    "state": "Sichuan",
                    "country": "China",
                    "street1": "TianFuWuJie",
                    "street2": "",
                    "zipCode": "12345",
                    "lastName": "Test",
                    "firstName": "B2B"
                }
            ]
        },
        "details": { "lineItems": [
                {
                    "sku": "Test-1",
                    "quantity": "2",
                    "unitPrice": {
                        "code": "USD",
                        "value": "40.00"
                    },
                    "description": "A custom product requires a description."
                }
            ] }
    },
    "channelId": 1
}
headers = {
    "X-Auth-Token": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Create an invoice
const url = 'https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices';
const options = {
  method: 'POST',
  headers: {'X-Auth-Token': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"invoiceNumber":"0000001","originalBalance":{"code":"USD","value":100},"openBalance":{"code":"USD","value":100},"customerId":"12345","dueDate":1619161808,"status":0,"issuedAt":1619161808,"details":{"header":{"costLines":[{"amount":{"code":"USD","value":"90.00"},"description":"Subtotal"},{"amount":{"code":"USD","value":"10.00"},"description":"Freight"},{"amount":{"code":"USD","value":"0.00"},"description":"Sales Tax"}],"billingAddress":{"city":"Chengdu","state":"Sichuan","country":"China","street1":"TianFuWuJie","street2":"","zipCode":"12345","lastName":"Test","firstName":"B2B"},"shippingAddresses":[{"city":"Chengdu","state":"Sichuan","country":"China","street1":"TianFuWuJie","street2":"","zipCode":"12345","lastName":"Test","firstName":"B2B"}]},"details":{"lineItems":[{"sku":"Test-1","quantity":"2","unitPrice":{"code":"USD","value":"40.00"},"description":"A custom product requires a description."}]}},"channelId":1}'
};

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

```go Create an invoice
package main

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

func main() {

	url := "https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices"

	payload := strings.NewReader("{\n  \"invoiceNumber\": \"0000001\",\n  \"originalBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"openBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"customerId\": \"12345\",\n  \"dueDate\": 1619161808,\n  \"status\": 0,\n  \"issuedAt\": 1619161808,\n  \"details\": {\n    \"header\": {\n      \"costLines\": [\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"90.00\"\n          },\n          \"description\": \"Subtotal\"\n        },\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"10.00\"\n          },\n          \"description\": \"Freight\"\n        },\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"0.00\"\n          },\n          \"description\": \"Sales Tax\"\n        }\n      ],\n      \"billingAddress\": {\n        \"city\": \"Chengdu\",\n        \"state\": \"Sichuan\",\n        \"country\": \"China\",\n        \"street1\": \"TianFuWuJie\",\n        \"street2\": \"\",\n        \"zipCode\": \"12345\",\n        \"lastName\": \"Test\",\n        \"firstName\": \"B2B\"\n      },\n      \"shippingAddresses\": [\n        {\n          \"city\": \"Chengdu\",\n          \"state\": \"Sichuan\",\n          \"country\": \"China\",\n          \"street1\": \"TianFuWuJie\",\n          \"street2\": \"\",\n          \"zipCode\": \"12345\",\n          \"lastName\": \"Test\",\n          \"firstName\": \"B2B\"\n        }\n      ]\n    },\n    \"details\": {\n      \"lineItems\": [\n        {\n          \"sku\": \"Test-1\",\n          \"quantity\": \"2\",\n          \"unitPrice\": {\n            \"code\": \"USD\",\n            \"value\": \"40.00\"\n          },\n          \"description\": \"A custom product requires a description.\"\n        }\n      ]\n    }\n  },\n  \"channelId\": 1\n}")

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

	req.Header.Add("X-Auth-Token", "<apiKey>")
	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 Create an invoice
require 'uri'
require 'net/http'

url = URI("https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices")

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

request = Net::HTTP::Post.new(url)
request["X-Auth-Token"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"invoiceNumber\": \"0000001\",\n  \"originalBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"openBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"customerId\": \"12345\",\n  \"dueDate\": 1619161808,\n  \"status\": 0,\n  \"issuedAt\": 1619161808,\n  \"details\": {\n    \"header\": {\n      \"costLines\": [\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"90.00\"\n          },\n          \"description\": \"Subtotal\"\n        },\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"10.00\"\n          },\n          \"description\": \"Freight\"\n        },\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"0.00\"\n          },\n          \"description\": \"Sales Tax\"\n        }\n      ],\n      \"billingAddress\": {\n        \"city\": \"Chengdu\",\n        \"state\": \"Sichuan\",\n        \"country\": \"China\",\n        \"street1\": \"TianFuWuJie\",\n        \"street2\": \"\",\n        \"zipCode\": \"12345\",\n        \"lastName\": \"Test\",\n        \"firstName\": \"B2B\"\n      },\n      \"shippingAddresses\": [\n        {\n          \"city\": \"Chengdu\",\n          \"state\": \"Sichuan\",\n          \"country\": \"China\",\n          \"street1\": \"TianFuWuJie\",\n          \"street2\": \"\",\n          \"zipCode\": \"12345\",\n          \"lastName\": \"Test\",\n          \"firstName\": \"B2B\"\n        }\n      ]\n    },\n    \"details\": {\n      \"lineItems\": [\n        {\n          \"sku\": \"Test-1\",\n          \"quantity\": \"2\",\n          \"unitPrice\": {\n            \"code\": \"USD\",\n            \"value\": \"40.00\"\n          },\n          \"description\": \"A custom product requires a description.\"\n        }\n      ]\n    }\n  },\n  \"channelId\": 1\n}"

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

```java Create an invoice
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices")
  .header("X-Auth-Token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"invoiceNumber\": \"0000001\",\n  \"originalBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"openBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"customerId\": \"12345\",\n  \"dueDate\": 1619161808,\n  \"status\": 0,\n  \"issuedAt\": 1619161808,\n  \"details\": {\n    \"header\": {\n      \"costLines\": [\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"90.00\"\n          },\n          \"description\": \"Subtotal\"\n        },\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"10.00\"\n          },\n          \"description\": \"Freight\"\n        },\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"0.00\"\n          },\n          \"description\": \"Sales Tax\"\n        }\n      ],\n      \"billingAddress\": {\n        \"city\": \"Chengdu\",\n        \"state\": \"Sichuan\",\n        \"country\": \"China\",\n        \"street1\": \"TianFuWuJie\",\n        \"street2\": \"\",\n        \"zipCode\": \"12345\",\n        \"lastName\": \"Test\",\n        \"firstName\": \"B2B\"\n      },\n      \"shippingAddresses\": [\n        {\n          \"city\": \"Chengdu\",\n          \"state\": \"Sichuan\",\n          \"country\": \"China\",\n          \"street1\": \"TianFuWuJie\",\n          \"street2\": \"\",\n          \"zipCode\": \"12345\",\n          \"lastName\": \"Test\",\n          \"firstName\": \"B2B\"\n        }\n      ]\n    },\n    \"details\": {\n      \"lineItems\": [\n        {\n          \"sku\": \"Test-1\",\n          \"quantity\": \"2\",\n          \"unitPrice\": {\n            \"code\": \"USD\",\n            \"value\": \"40.00\"\n          },\n          \"description\": \"A custom product requires a description.\"\n        }\n      ]\n    }\n  },\n  \"channelId\": 1\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices', [
  'body' => '{
  "invoiceNumber": "0000001",
  "originalBalance": {
    "code": "USD",
    "value": 100
  },
  "openBalance": {
    "code": "USD",
    "value": 100
  },
  "customerId": "12345",
  "dueDate": 1619161808,
  "status": 0,
  "issuedAt": 1619161808,
  "details": {
    "header": {
      "costLines": [
        {
          "amount": {
            "code": "USD",
            "value": "90.00"
          },
          "description": "Subtotal"
        },
        {
          "amount": {
            "code": "USD",
            "value": "10.00"
          },
          "description": "Freight"
        },
        {
          "amount": {
            "code": "USD",
            "value": "0.00"
          },
          "description": "Sales Tax"
        }
      ],
      "billingAddress": {
        "city": "Chengdu",
        "state": "Sichuan",
        "country": "China",
        "street1": "TianFuWuJie",
        "street2": "",
        "zipCode": "12345",
        "lastName": "Test",
        "firstName": "B2B"
      },
      "shippingAddresses": [
        {
          "city": "Chengdu",
          "state": "Sichuan",
          "country": "China",
          "street1": "TianFuWuJie",
          "street2": "",
          "zipCode": "12345",
          "lastName": "Test",
          "firstName": "B2B"
        }
      ]
    },
    "details": {
      "lineItems": [
        {
          "sku": "Test-1",
          "quantity": "2",
          "unitPrice": {
            "code": "USD",
            "value": "40.00"
          },
          "description": "A custom product requires a description."
        }
      ]
    }
  },
  "channelId": 1
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Auth-Token' => '<apiKey>',
  ],
]);

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

```csharp Create an invoice
using RestSharp;

var client = new RestClient("https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Auth-Token", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"invoiceNumber\": \"0000001\",\n  \"originalBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"openBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"customerId\": \"12345\",\n  \"dueDate\": 1619161808,\n  \"status\": 0,\n  \"issuedAt\": 1619161808,\n  \"details\": {\n    \"header\": {\n      \"costLines\": [\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"90.00\"\n          },\n          \"description\": \"Subtotal\"\n        },\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"10.00\"\n          },\n          \"description\": \"Freight\"\n        },\n        {\n          \"amount\": {\n            \"code\": \"USD\",\n            \"value\": \"0.00\"\n          },\n          \"description\": \"Sales Tax\"\n        }\n      ],\n      \"billingAddress\": {\n        \"city\": \"Chengdu\",\n        \"state\": \"Sichuan\",\n        \"country\": \"China\",\n        \"street1\": \"TianFuWuJie\",\n        \"street2\": \"\",\n        \"zipCode\": \"12345\",\n        \"lastName\": \"Test\",\n        \"firstName\": \"B2B\"\n      },\n      \"shippingAddresses\": [\n        {\n          \"city\": \"Chengdu\",\n          \"state\": \"Sichuan\",\n          \"country\": \"China\",\n          \"street1\": \"TianFuWuJie\",\n          \"street2\": \"\",\n          \"zipCode\": \"12345\",\n          \"lastName\": \"Test\",\n          \"firstName\": \"B2B\"\n        }\n      ]\n    },\n    \"details\": {\n      \"lineItems\": [\n        {\n          \"sku\": \"Test-1\",\n          \"quantity\": \"2\",\n          \"unitPrice\": {\n            \"code\": \"USD\",\n            \"value\": \"40.00\"\n          },\n          \"description\": \"A custom product requires a description.\"\n        }\n      ]\n    }\n  },\n  \"channelId\": 1\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create an invoice
import Foundation

let headers = [
  "X-Auth-Token": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "invoiceNumber": "0000001",
  "originalBalance": [
    "code": "USD",
    "value": 100
  ],
  "openBalance": [
    "code": "USD",
    "value": 100
  ],
  "customerId": "12345",
  "dueDate": 1619161808,
  "status": 0,
  "issuedAt": 1619161808,
  "details": [
    "header": [
      "costLines": [
        [
          "amount": [
            "code": "USD",
            "value": "90.00"
          ],
          "description": "Subtotal"
        ],
        [
          "amount": [
            "code": "USD",
            "value": "10.00"
          ],
          "description": "Freight"
        ],
        [
          "amount": [
            "code": "USD",
            "value": "0.00"
          ],
          "description": "Sales Tax"
        ]
      ],
      "billingAddress": [
        "city": "Chengdu",
        "state": "Sichuan",
        "country": "China",
        "street1": "TianFuWuJie",
        "street2": "",
        "zipCode": "12345",
        "lastName": "Test",
        "firstName": "B2B"
      ],
      "shippingAddresses": [
        [
          "city": "Chengdu",
          "state": "Sichuan",
          "country": "China",
          "street1": "TianFuWuJie",
          "street2": "",
          "zipCode": "12345",
          "lastName": "Test",
          "firstName": "B2B"
        ]
      ]
    ],
    "details": ["lineItems": [
        [
          "sku": "Test-1",
          "quantity": "2",
          "unitPrice": [
            "code": "USD",
            "value": "40.00"
          ],
          "description": "A custom product requires a description."
        ]
      ]]
  ],
  "channelId": 1
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices")! 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()
```

### Invalid invoice creation

**Request**

```json
{
  "invoiceNumber": "0000001",
  "originalBalance": {
    "code": "USD",
    "value": 100
  },
  "openBalance": {
    "code": "USD",
    "value": 100
  },
  "customerId": "12345",
  "channelId": 1
}
```

**Response**

```json
{
  "code": 400,
  "data": {
    "errMsg": "The invoice number already exists."
  },
  "meta": {
    "message": "Bad Requests Error"
  }
}
```

**SDK Code**

```python Invalid invoice creation
import requests

url = "https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices"

payload = {
    "invoiceNumber": "0000001",
    "originalBalance": {
        "code": "USD",
        "value": 100
    },
    "openBalance": {
        "code": "USD",
        "value": 100
    },
    "customerId": "12345",
    "channelId": 1
}
headers = {
    "X-Auth-Token": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Invalid invoice creation
const url = 'https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices';
const options = {
  method: 'POST',
  headers: {'X-Auth-Token': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"invoiceNumber":"0000001","originalBalance":{"code":"USD","value":100},"openBalance":{"code":"USD","value":100},"customerId":"12345","channelId":1}'
};

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

```go Invalid invoice creation
package main

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

func main() {

	url := "https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices"

	payload := strings.NewReader("{\n  \"invoiceNumber\": \"0000001\",\n  \"originalBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"openBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"customerId\": \"12345\",\n  \"channelId\": 1\n}")

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

	req.Header.Add("X-Auth-Token", "<apiKey>")
	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 Invalid invoice creation
require 'uri'
require 'net/http'

url = URI("https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices")

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

request = Net::HTTP::Post.new(url)
request["X-Auth-Token"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"invoiceNumber\": \"0000001\",\n  \"originalBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"openBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"customerId\": \"12345\",\n  \"channelId\": 1\n}"

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

```java Invalid invoice creation
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices")
  .header("X-Auth-Token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"invoiceNumber\": \"0000001\",\n  \"originalBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"openBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"customerId\": \"12345\",\n  \"channelId\": 1\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices', [
  'body' => '{
  "invoiceNumber": "0000001",
  "originalBalance": {
    "code": "USD",
    "value": 100
  },
  "openBalance": {
    "code": "USD",
    "value": 100
  },
  "customerId": "12345",
  "channelId": 1
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Auth-Token' => '<apiKey>',
  ],
]);

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

```csharp Invalid invoice creation
using RestSharp;

var client = new RestClient("https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Auth-Token", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"invoiceNumber\": \"0000001\",\n  \"originalBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"openBalance\": {\n    \"code\": \"USD\",\n    \"value\": 100\n  },\n  \"customerId\": \"12345\",\n  \"channelId\": 1\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Invalid invoice creation
import Foundation

let headers = [
  "X-Auth-Token": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "invoiceNumber": "0000001",
  "originalBalance": [
    "code": "USD",
    "value": 100
  ],
  "openBalance": [
    "code": "USD",
    "value": 100
  ],
  "customerId": "12345",
  "channelId": 1
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api-b2b.bigcommerce.com/api/v3/io/ip/invoices")! 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()
```