Reputation: 782
I'm using the 'official' Shopify node adapter (https://github.com/MONEI/Shopify-api-node) and trying to create a draft order.
Sending the payload of
{
"draft_order": {
"line_items": [
{
"title": "Custom Tee",
"price": "20.00",
"quantity": 2
}
]
}
}
works via Postman, but is returning 'bad request' (400) from the api.
The full function/call via wrapper is as follows:
import Shopify from 'shopify-api-node';
makeDraftOrder: function(shop_name) {
console.log('trying to connect with ', shop_name);
const shop = Shops.findOne({'shopName': shop_name});
const shopify_data = new Shopify({
shopName: shop.shopName,
accessToken: shop.accessToken
});
let newOrder = JSON.stringify({
"draft_order": {
"line_items": [
{
"title": "Custom Tee",
"price": "20.00",
"quantity": 2
}
]
}
});
shopify_data.draftOrder.create(newOrder).then(data => {
console.log('draft order', data);
}).catch(err => console.error('wawawoowa', err));
}
Making a call to draftOrder.list()
works fine, but the above fails. Any help much appreciated.
Upvotes: 2
Views: 881
Reputation: 20422
Don't wrap the order with "draft_order": { ... }
. You also don't need to stringify the object.
let newOrder= {
"line_items": [
{
"title": "Custom Tee",
"price": "20.00",
"quantity": 2
}
]
};
shopify_data.draftOrder.create(newOrder)
Upvotes: 3