I’m working with the shopify-api-node package to add products to my Shopify store. I’m running into a problem where my data gets wrapped in an unwanted extra property.
Here’s my working example that functions correctly:
store.resource.create({
name: 'inventory_location',
count: 50,
data_type: 'number',
category: 'stock',
target_resource: 'item',
target_id: 789123456
}).then(
resource => console.log(resource),
error => console.error(error)
);
But when I try to use it dynamically like this:
self.processData(request, dataItem, function(error, processedData) {
var resourceName = mapping.resource;
var createMethod = mapping.actions.create;
console.log(processedData);
console.log(JSON.stringify(processedData));
store[resourceName][createMethod]({
processedData
}).then(
response => console.log(response),
error => console.error(error)
);
});
My processed data looks like this:
{
photos: [
{"url":"https://cdn.example.com/assets/item1.jpg"},
{"url":"https://cdn.example.com/assets/item2.jpg"}
],
category: "Furniture",
keywords: ["Modern", "Chair", "Office", "Black", 299],
name: "ergonomic desk chair",
options: {
"cost": 299,
"material": "leather",
"name": "Chair leather",
"code": "CH001-BLK",
"size": "Standard",
"color": "Black"
}
}
The issue happens because of how the library processes the request body. Instead of getting {"item": myData}, I’m getting {"processedData": myData} which makes the API call fail.
How can I pass my object directly without it getting wrapped in that extra property name? I’m pretty new to this and already tried asking elsewhere but didn’t get help. Any suggestions would be great!