API / Submit your inventory

XSparts provides an API endpoint to submit your inventory programatically. In order to use the API, you will first need to obtain an API KEY for your account. You can obtain the key by sending your request to xsparts@pcbplanet.com. Once you have the API KEY you can begin sending the requests.

Submitted stock is not shown in search straight away: the XSParts team reviews each submission first, and it appears once approved. Re-submitting an MPN in a later request updates its offer once approved.

API endpointhttp://localhost:8090/api/inventory_submit/
Request MethodPOST

Parameters

api_keyYour 36 character long hex key
dataYour inventory data as JSON array (see example below)

For each MPN the JSON array should contain the fields described in the table below.

Currently API has a restriction of sending array size of 1000 per request (That means, if you want to send 5000 MPNs then you have to send 5 API requests of 1000 MPNs each).

Field nameTypeMandatory?Description
mpntextyesManufacturer Part Number
stockintyesThe stock quantity you offer
offer_unit_pricedecimalnoThe price of the part
offer_price_validityintnoThe validity of the price in days
moqintnoMinimum order quantity
categorytextnoCategory of the MPN
descriptiontextnoShort description of the MPN
mfrtextnoManufacturer of the MPN

An example JSON payload

[
    {
        "mpn": "test-mpn1",
        "stock": "101",
        "offer_unit_price": "1.1",
        "offer_price_validity": "30",
        "moq": "1",
        "category": "Capacitors",
        "description": "test-mpn1 desc",
        "mfr": "The Manufacturer"
    },
    {
        "mpn": "test-mpn2",
        "stock": "102",
        "offer_unit_price": "1.2",
        "offer_price_validity": "30",
        "moq": "1",
        "category": "Resistors",
        "description": "test-mpn2 desc",
        "mfr": "The Manufacturer"
    }
]

An example Python Programming Language code snippet to send the request to the endpoint is given below.

import requests

url = "http://localhost:8090/api/inventory_submit/"

payload = {'api_key': '**4a6243-****-497e-****-6d3982******',
           'data': '''[{
                   "mpn": "test-mpn1",
                   "stock": "101",
                   "offer_unit_price": "1.1",
                   "offer_price_validity": "30",
                   "moq": "1",
                   "category": "Capacitors",
                   "description": "test-mpn1 desc",
                   "mfr": "The Manufacturer"
               },
               {
                   "mpn": "test-mpn2",
                   "stock": "102",
                   "offer_unit_price": "1.2",
                   "offer_price_validity": "30",
                   "moq": "1",
                   "category": "Resistors",
                   "description": "test-mpn2 desc",
                   "mfr": "The Manufacturer"
               }]'''
           }

headers = {}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

After a valid request is submitted, you will get a JSON response as shown below if data is received successfully by the database.

{"code": 1, "msg": "Success!"}

In case of an error you will get a JSON response with an error message.

{"code": 0, "msg": "Invalid API key"}