### Overview

This endpoint is for importing inventory in bulk via the Rest API. (For setting the physical inventory of an **individual** product via the REST API, see [here](https://developer.sellercloud.com/dev-article/set-physical-inventory/) instead.) This endpoint exposes the same functionality as the Import Physical Inventory feature in our new Sellercloud UI.

In order to do a bulk inventory import, you must first download an Import Physical Inventory template file from the Sellercloud UI in one of these formats:

- TAB Delimited
- CSV
- Excel

See [this](https://help.sellercloud.com/omnichannel-ecommerce/import-physical-inventory/) article for assistance with getting a template file. After you’ve downloaded a template file and populated with inventory info (either manually or via code), you can proceed with importing that file via the REST API.

In order to import physical inventory in bulk, you must have a valid token, which is received after authentication. For information on how you can authenticate, see: [Authentication](https://developer.sellercloud.com/dev-article/authentication/)

### Endpoint

This would be the endpoint for the TT server:

[https://tt.api.sellercloud.com/rest/api/Inventory/ImportPhysicalInventory](https://tt.api.sellercloud.com/rest/api/Inventory/ImportPhysicalInventory)

For your server, the endpoint will be:

​ [https://{your_server_id}.api.sellercloud.com/rest/api/Inventory/ImportPhysicalInventory](https://{your_server_id}.api.sellercloud.com/rest/api/Inventory/ImportPhysicalInventory)

### Request

- Method Type: **HttpPut**  
- Authorization: Use **Bearer Token** + token received from token authentication  
- Header info: **Content-Type: application/json**

|     |     |     |     |
| --- | --- | --- | --- |
| **Parameter** | **Data Type** | **Description** | **Is Required** |
| UpdateType | int | Partial: 0<br>Full: 1<br>Optional.<br>Default value: Partial<br>Partial is **strongly** recommended. Full will set any SKU in the system that is not in the file to a quantity of zero. | No |
| FileContent | string | Base64 encoded string, which represents file content | Yes |
| FileExtension | string | The file extension. Must be provided when the format is excel and the file is with extension “.xlsx”. Example “.xlsx”. | No |
| InventoryDate | DateTime | Inventory Date<br>Optional.<br>Default value: current time of import. | No |
| Format | int | Tab Delimited: 0<br>CSV: 1<br>Excel: 2 | Yes |
| WarehouseID | int | ID of the warehouse where the imported inventory should be set | Yes |
| PinCode | string | Pin Code | Depends, see below |
| MergeDefaultWarehouseInventoryIntoShadowParent | bool | If to merge default warehouse inventory into shadow parent.<br>Optional.<br>Default Value: True | No |

Pin code is required if client setting “ **Require PIN to change inventory quantity**” is enabled.

### Response

- If inventory is imported successfully, then response will be **Status Code 200 => OK**
- If token is not valid, then response will be **Status Code 401 => Not Valid Token**
- Error on server response => **Status Code 500 => Internal Server Error**

### Demo

```csharp
public enum PhysicalInventoryUpdateType
    {
        Partial,
        Full
    }
```

```csharp
public enum FileFormatType
    {
        TAB_Delimited = 0,
        CSV = 1,
        Excel = 2
    }
```

```csharp
string url = $"http://cwa.api.sellercloud.com/api/Inventory/ImportPhysicalInventory";
string token = "test_token";

var content = new ImportBulkPhysicalInventoryRequest()
{
    FileContents = Convert.ToBase64String(File.ReadAllBytes($@"C:DataTestRunsBulk.xls")),
    Format = FileFormatType.Excel,
    UpdateType = PhysicalInventoryUpdateType.Partial,
    InventoryDate = DateTime.Now,
    MergeDefaultWarehouseInventoryIntoShadowParent = true
};

using (var client = new HttpClient())
using (var request = new HttpRequestMessage(HttpMethod.Post, url))
{
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    var json = JsonConvert.SerializeObject(content);
    using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
    {
        request.Content = stringContent;
        var responseMessage = await client.SendAsync(request);
        var jsonContent = await responseMessage.Content.ReadAsStringAsync();
    }
}
```

```csharp
public class ImportBulkPhysicalInventoryRequest
{
    public PhysicalInventoryUpdateType? UpdateType { get; set; }
    public string FileContent { get; set; }
    public DateTime? InventoryDate { get; set; }
    public FileFormatType? Format { get; set; }
    public int? WarehouseID { get; set; }
    public string PinCode { get; set; }
    public bool MergeDefaultWarehouseInventoryIntoShadowParent { get; set; }
}
```
