Creates a Product
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
product: {
name: '<string>',
price: '<string>',
shipping_category_id: '<string>',
description: '<string>',
available_on: '<string>',
discontinue_on: '<string>',
permalink: '<string>',
meta_description: '<string>',
meta_keywords: '<string>',
sku: '<string>',
deleted_at: '<string>',
prototype_id: '<string>',
option_values_hash: '<string>',
weight: '<string>',
height: '<string>',
width: '<string>',
depth: '<string>',
tax_category_id: '<string>',
cost_currency: '<string>',
cost_price: '<string>',
compare_at_price: '<string>',
option_type_ids: '<string>',
taxon_ids: '<string>',
public_metadata: {},
private_metadata: {}
}
})
};
fetch('http://{defaultHost}/api/v2/platform/products', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"data": {
"id": "168",
"type": "product",
"attributes": {
"name": "Spinning Top",
"description": null,
"available_on": null,
"deleted_at": null,
"slug": "spinning-top",
"meta_description": null,
"meta_keywords": null,
"created_at": "2022-11-08T19:34:53.239Z",
"updated_at": "2022-11-08T19:34:53.243Z",
"promotionable": true,
"meta_title": null,
"discontinue_on": null,
"public_metadata": {},
"private_metadata": {},
"status": "draft",
"make_active_at": null,
"display_compare_at_price": null,
"display_price": "$87.43",
"purchasable": false,
"in_stock": false,
"backorderable": false,
"available": false,
"currency": "USD",
"price": "87.43",
"compare_at_price": null
},
"relationships": {
"tax_category": {
"data": null
},
"primary_variant": {
"data": {
"id": "235",
"type": "variant"
}
},
"default_variant": {
"data": {
"id": "235",
"type": "variant"
}
},
"variants": {
"data": []
},
"option_types": {
"data": []
},
"product_properties": {
"data": []
},
"taxons": {
"data": []
},
"images": {
"data": []
}
}
}
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Select which associated resources you would like to fetch, see: https://jsonapi.org/format/#fetching-includes
Show child attributes
Record created
Show child attributes
Was this page helpful?
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
product: {
name: '<string>',
price: '<string>',
shipping_category_id: '<string>',
description: '<string>',
available_on: '<string>',
discontinue_on: '<string>',
permalink: '<string>',
meta_description: '<string>',
meta_keywords: '<string>',
sku: '<string>',
deleted_at: '<string>',
prototype_id: '<string>',
option_values_hash: '<string>',
weight: '<string>',
height: '<string>',
width: '<string>',
depth: '<string>',
tax_category_id: '<string>',
cost_currency: '<string>',
cost_price: '<string>',
compare_at_price: '<string>',
option_type_ids: '<string>',
taxon_ids: '<string>',
public_metadata: {},
private_metadata: {}
}
})
};
fetch('http://{defaultHost}/api/v2/platform/products', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"data": {
"id": "168",
"type": "product",
"attributes": {
"name": "Spinning Top",
"description": null,
"available_on": null,
"deleted_at": null,
"slug": "spinning-top",
"meta_description": null,
"meta_keywords": null,
"created_at": "2022-11-08T19:34:53.239Z",
"updated_at": "2022-11-08T19:34:53.243Z",
"promotionable": true,
"meta_title": null,
"discontinue_on": null,
"public_metadata": {},
"private_metadata": {},
"status": "draft",
"make_active_at": null,
"display_compare_at_price": null,
"display_price": "$87.43",
"purchasable": false,
"in_stock": false,
"backorderable": false,
"available": false,
"currency": "USD",
"price": "87.43",
"compare_at_price": null
},
"relationships": {
"tax_category": {
"data": null
},
"primary_variant": {
"data": {
"id": "235",
"type": "variant"
}
},
"default_variant": {
"data": {
"id": "235",
"type": "variant"
}
},
"variants": {
"data": []
},
"option_types": {
"data": []
},
"product_properties": {
"data": []
},
"taxons": {
"data": []
},
"images": {
"data": []
}
}
}
}