Extra property wrapping issue when using shopify-api-node library

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!

You’re wrapping processedData in extra curly braces, which creates an object with processedData as the key instead of passing the actual data. Just pass processedData directly: store[resourceName][createMethod](processedData).then(response => console.log(response), error => console.error(error)); That’ll fix it and match your working example.

You’re hitting an ES6 shorthand syntax issue. When you write {processedData}, JavaScript creates {processedData: processedData} - basically wrapping your data in an extra object layer with processedData as the key. Hit this same problem about six months back with a similar API wrapper. Fix is simple - spread the object instead of passing it as a property. Try this: store[resourceName]createMethod.then(response => console.log(response), error => console.error(error)); If the API needs a specific wrapper, use the spread operator: store[resourceName]createMethod.then(response => console.log(response), error => console.error(error)); This passes your data directly without that extra wrapper that’s breaking things.