Import Physical Inventory

Updated 3 weeks ago ​by nussi

Overview

This endpoint is for importing inventory in bulk via the Rest API. See this article for more information about Importing Physical Inventory in our new Sellercloud UI.

For setting the physical inventory of an individual product via the REST API, see here instead.

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

Endpoint

This would be the endpoint for the TT server:

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

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

Full: 1

Optional.

Default value: Partial

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

InventoryDate

DateTime

Inventory Date

Optional.

Default value: current time of import.

No

Format

int

Tab Delimited: 0

CSV: 1

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.

Optional.

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

public enum PhysicalInventoryUpdateType
{
Partial,

Full
}
public enum FileFormatType
{
TAB_Delimited = 0,
CSV = 1,
Excel = 2
}
string url = $"http://cwa.api.sellercloud.com/api/Inventory/ImportPhysicalInventory";
string token = "test_token";

var content = new ImportBulkPhysicalInventoryRequest()
{
FileContents = Convert.ToBase64String(File.ReadAllBytes($@"C:\\Data\\TestRuns\\Bulk.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();
}
}

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; }
}


How did we do?