Create product
Create new product with HTTP POST request.
POST
/products-by-id/
Data
Type
Description
name
string
Name of product
custom_id
string
Custom ID for product
product_url
string
Url for your product
image_url
string
Url for your product image
curl -X POST \
https://<your_app_subdomain>.user.com/api/public/products-by-id/ \
-H 'authorization: Token <your_64_char_api_key>' \
-H 'content-type: application/json' \
-d '{
"name": "my product",
"custom_id": "my_product_id",
"product_url": "https://myshop.com/products/my_product/",
"image_url": "https://myshop.com/media/products/myproduct.jpg"
}'
Response
{
"id": 50,
"name": "my product",
"custom_id": "my_product_id",
"created_at": "2018-03-02T14:14:05.608704Z",
"updated_at": "2018-03-02T14:14:05.608742Z",
"product_url": "https://myshop.com/products/my_product/",
"image_url": "https://myshop.com/media/products/myproduct.jpg",
"attributes": [],
"categories": []
}
var settings = {
"async": true,
"crossDomain": true,
"url": "https://<your_app_subdomain>.user.com/api/public/products-by-id/",
"method": "POST",
"headers": {
"authorization": "Token <your_64_char_api_key>",
"content-type": "application/json"
},
"processData": false,
"data": "{\n\t\"name\": \"my product\",\n\t\"custom_id\": \"my_product_id\",\n\t\"product_url\": \"https://myshop.com/products/my_product/\",\n\t\"image_url\": \"https://myshop.com/media/products/myproduct.jpg\"\n}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
var data = JSON.stringify({
"name": "my product",
"custom_id": "my_product_id",
"product_url": "https://myshop.com/products/my_product/",
"image_url": "https://myshop.com/media/products/myproduct.jpg"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://<your_app_subdomain>.user.com/api/public/products-by-id/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
var request = require("request");
var options = { method: 'POST',
url: 'https://<your_app_subdomain>.user.com/api/public/products-by-id/',
headers:
{ 'content-type': 'application/json',
authorization: 'Token <your_64_char_api_key>' },
body:
{ name: 'my product',
custom_id: 'my_product_id',
product_url: 'https://myshop.com/products/my_product/',
image_url: 'https://myshop.com/media/products/myproduct.jpg' },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/products-by-id/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n\t\"name\": \"my product\",\n\t\"custom_id\": \"my_product_id\",\n\t\"product_url\": \"https://myshop.com/products/my_product/\",\n\t\"image_url\": \"https://myshop.com/media/products/myproduct.jpg\"\n}",
CURLOPT_HTTPHEADER => array(
"authorization: Token <your_64_char_api_key>",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import requests
url = "https://<your_app_subdomain>.user.com/api/public/products-by-id/"
payload = "{\n\t\"name\": \"my product\",\n\t\"custom_id\": \"my_product_id\",\n\t\"product_url\": \"https://myshop.com/products/my_product/\",\n\t\"image_url\": \"https://myshop.com/media/products/myproduct.jpg\"\n}"
headers = {
'authorization': "Token <your_64_char_api_key>",
'content-type': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)