## Create counter

### Example cURL Request

```bash
curl --request POST \
  --url https://api.fabric.inc/v3/inventory-counters \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-fabric-channel-id: <x-fabric-channel-id>' \
  --header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
  --data '
{
  "code": "onHand",
  "name": "onHand"
}
'  
```

### Python Example

```python
import requests

url = "https://api.fabric.inc/v3/inventory-counters"

payload = {
    "code": "onHand",
    "name": "onHand"
}
headers = {
    "x-fabric-tenant-id": "<x-fabric-tenant-id>",
    "x-fabric-channel-id": "<x-fabric-channel-id>",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)
```

### JavaScript Example

```javascript
const options = {
  method: 'POST',
  headers: {
    'x-fabric-tenant-id': '<x-fabric-tenant-id>',
    'x-fabric-channel-id': '<x-fabric-channel-id>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({code: 'onHand', name: 'onHand'})
};

fetch('https://api.fabric.inc/v3/inventory-counters', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### PHP Example

```php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.fabric.inc/v3/inventory-counters",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "", 
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'code' => 'onHand',
    'name' => 'onHand'
]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json",
    "x-fabric-channel-id: <x-fabric-channel-id>",
    "x-fabric-tenant-id: <x-fabric-tenant-id>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

### Go Example

```go
package main

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

func main() {

url := "https://api.fabric.inc/v3/inventory-counters"

payload := strings.NewReader("{\n  \"code\": \"onHand\",\n  \"name\": \"onHand\"\n}")

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

req.Header.Add("x-fabric-tenant-id", "<x-fabric-tenant-id>")
	req.Header.Add("x-fabric-channel-id", "<x-fabric-channel-id>")
	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(string(body))
}
```

### Response

#### 201 Created Example

```json
{
  "code": "onHand",
  "id": "38271022e832a1",
  "name": "onHand"
}
```

#### Error Examples

##### 400 Bad Request
```json
{
  "errors": [
    {
      "message": "Invalid request",
      "type": "CLIENT_ERROR"
    }
  ],
  "message": "Bad request",
  "type": "CLIENT_ERROR"
}
```

##### 401 Unauthorized
```json
{
  "message": "Unauthorized request",
  "type": "CLIENT_ERROR"
}
```

##### 409 Conflict
```json
{
  "message": "Counter code already exists",
  "type": "CLIENT_ERROR"
}
```

##### 500 Internal Server Error
```json
{
  "message": "Internal server error",
  "type": "SERVER_ERROR"
}
```

### Authorizations

- `Authorization`: Bearer authentication header of the form `Bearer <token>`, required.

### Headers

- `x-fabric-tenant-id`: Required for identifying the tenant.
- `x-fabric-channel-id`: Required for the sales channel.

### Request Body

The body must be in JSON format:
- `code`: **string** (required)
- `name`: **string** (required)

### Response Structure
- `code`: **string** (required)
- `id`: **string** (fabric system-generated counter ID)
- `name`: **string** (required)
