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 endpoint | http://localhost:8090/api/inventory_submit/ |
|---|---|
| Request Method | POST |
Parameters
| api_key | Your 36 character long hex key |
| data | Your 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 name | Type | Mandatory? | Description |
|---|---|---|---|
| mpn | text | yes | Manufacturer Part Number |
| stock | int | yes | The stock quantity you offer |
| offer_unit_price | decimal | no | The price of the part |
| offer_price_validity | int | no | The validity of the price in days |
| moq | int | no | Minimum order quantity |
| category | text | no | Category of the MPN |
| description | text | no | Short description of the MPN |
| mfr | text | no | Manufacturer 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"}