Creates a Shipping Method
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
shipping_method: {
name: 'DHL Express',
display_on: 'both',
shipping_category_ids: ['2'],
admin_name: 'DHL Area Code D',
code: 'DHL-A-D',
tracking_url: 'dhlexpress.com?tracking=',
tax_category_id: '1',
calculator_attributes: {type: 'Spree::Calculator::Shipping::FlatPercentItemTotal'},
public_metadata: {},
private_metadata: {}
}
})
};
fetch('http://{defaultHost}/api/v2/platform/shipping_methods', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"data": {
"id": "81",
"type": "shipping_method",
"attributes": {
"name": "DHL Express Domestic",
"code": "DDD",
"admin_name": "DHL Express- Zone A",
"display_on": "both",
"tracking_url": null,
"created_at": "2022-11-08T19:35:24.485Z",
"updated_at": "2022-11-08T19:35:24.485Z",
"deleted_at": null,
"public_metadata": {},
"private_metadata": {}
},
"relationships": {
"shipping_categories": {
"data": [
{
"id": "148",
"type": "shipping_category"
}
]
},
"shipping_rates": {
"data": []
},
"tax_category": {
"data": {
"id": "142",
"type": "tax_category"
}
},
"calculator": {
"data": {
"id": "141",
"type": "calculator"
}
}
}
}
}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({
shipping_method: {
name: 'DHL Express',
display_on: 'both',
shipping_category_ids: ['2'],
admin_name: 'DHL Area Code D',
code: 'DHL-A-D',
tracking_url: 'dhlexpress.com?tracking=',
tax_category_id: '1',
calculator_attributes: {type: 'Spree::Calculator::Shipping::FlatPercentItemTotal'},
public_metadata: {},
private_metadata: {}
}
})
};
fetch('http://{defaultHost}/api/v2/platform/shipping_methods', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"data": {
"id": "81",
"type": "shipping_method",
"attributes": {
"name": "DHL Express Domestic",
"code": "DDD",
"admin_name": "DHL Express- Zone A",
"display_on": "both",
"tracking_url": null,
"created_at": "2022-11-08T19:35:24.485Z",
"updated_at": "2022-11-08T19:35:24.485Z",
"deleted_at": null,
"public_metadata": {},
"private_metadata": {}
},
"relationships": {
"shipping_categories": {
"data": [
{
"id": "148",
"type": "shipping_category"
}
]
},
"shipping_rates": {
"data": []
},
"tax_category": {
"data": {
"id": "142",
"type": "tax_category"
}
},
"calculator": {
"data": {
"id": "141",
"type": "calculator"
}
}
}
}
}