API / Integrate XSparts search
XSparts provides an API endpoint to get 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.
The API in general is in BETA state.
| API endpoint | http://localhost:8090/api/inventory_search/ |
|---|---|
| Request Method | POST |
Parameters
| api_key | Your 36 character long hex key |
| mpns | The MPNs to search for (see example below) |
The api_key must be a valid partner API key.
Currently API has a restriction of sending array size of 20 per request (That means, if you want to get 100 MPNs inventory then you have to send 5 API requests (array of 20 MPNs) each).
| Field name | Type | Mandatory? | Description |
|---|---|---|---|
| mpns | array | yes | Manufacturer Part Number |
An example of payload
mpns:["test-mpn1", "test-mpn2", "test-mpn4"]
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_search/"
payload = {
'api_key': '**4a6243-****-497e-****-6d3982******',
'mpns': '["test-mpn1", "test-mpn2", "test-mpn4"]'
}
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 the exact MPN exists in the database; if the MPN does not exist, an error (Part not found) is returned for that MPN.
{
"code": 1,
"data": [
{
"mpn": "test-mpn1",
"description": "test-mpn1 desc",
"owner": "Liad",
"last_updated_on": "24/Jan/2023",
"type": "",
"category": "Capacitors",
"manufacturer": "The Manufacturer",
"stock": 0,
"price": "1.50"
},
{
"mpn": "test-mpn2",
"description": "test-mpn2 desc",
"owner": "Liad",
"last_updated_on": "27/Jan/2023",
"type": "",
"category": "Resistors",
"manufacturer": "The Manufacturer",
"stock": 15,
"price": "1.60"
},
{
"mpn": "test-mpn1",
"description": "test-mpn1 desc",
"owner": "intellial",
"last_updated_on": "24/Jan/2023",
"type": "",
"category": "Capacitors",
"manufacturer": "",
"stock": 101,
"price": "1.10"
},
{
"mpn": "test-mpn4",
"error": "Part not found."
}
]
}
In case of an error you will get a JSON response with an error message.
{"code": 0, "msg": "Invalid API key"}