# Nodejs BatchUpserts

**URL:** <https://developer.squareup.com/forums/t/nodejs-batchupserts/267>\
**Category:** Questions\
**Tags:** catalog-api, node-js\
**Created:** [May 17, 2020, 11:20am UTC](https://developer.squareup.com/forums/t/nodejs-batchupserts/267 "2020-05-17T11:20:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgeedwards](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@georgeedwards](https://developer.squareup.com/forums/u/georgeedwards)\
**Post date:** [May 17, 2020, 11:20am UTC](https://developer.squareup.com/forums/t/nodejs-batchupserts/267/1 "2020-05-17T11:20:57Z")

</div>

I am trying to call the BatchUpsert method on the Catalog API from the [`Square API`](https://developer.squareup.com/reference/square/catalog-api/batch-upsert-catalog-objects) SDK. All of my operations so far have been successful, but now I am trying to do a batch operation, I am having issues and the SDK docs for node js don’t have many examples. I am calling the following method:

```auto
var body = new SquareConnect.BatchUpsertCatalogObjectsRequest({
    idempotency_key: uuidv4(),
    batches: [{
        objects: [{
            id: "#pack_size",
            type: "CUSTOM_ATTRIBUTE_DEFINITION",
            allowed_object_types: ["ITEM_VARIATION"],
            seller_visibility: "SELLER_VISIBILITY_READ_WRITE_VALUES",
            app_visibility: "APP_VISIBILITY_HIDDEN",
            custom_attribute_definition_data: {
                name: "PackSizeKgs",
                key: "pack_size",
                type: "NUMBER"

            }
        }]
    }]
});

apiInstance.upsertCatalogObject(body).then(function(data) {
  console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
  console.error(error);
});

```

I am getting the error back -

> “INVALID\_REQUEST\_ERROR”,“code”:“EXPECTED\_STRING”,“detail”:“Expected a string value.”,“field”:“idempotency\_key”

uuidv4() should be returning a string, I have verified this by logging `typeof uuidv4()` which returns `string` and even tried manually typing the fixed string idempotency\_key from square’s curl example.

Any ideas what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![sjosey](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/sjosey/32/40_2.png) [@sjosey](https://developer.squareup.com/forums/u/sjosey)\
**Post date:** [May 18, 2020, 5:02pm UTC](https://developer.squareup.com/forums/t/nodejs-batchupserts/267/2 "2020-05-18T17:02:03Z")

</div>

The `BatchUpsertCatalogObjectsRequest` takes two parameters: `idempotency_key` and `batches`. You’re currently passing one single parameter, an entire object (so it’s basically setting `idempotency_key` as an object, not a string). So, try updating to be something like:

```auto
var body = new SquareConnect.BatchUpsertCatalogObjectsRequest();
body.idempotency_key = uuid();
body.batches = [{
    objects: [{
        id: "#pack_size",
        type: "CUSTOM_ATTRIBUTE_DEFINITION",
        allowed_object_types: ["ITEM_VARIATION"],
        seller_visibility: "SELLER_VISIBILITY_READ_WRITE_VALUES",
        app_visibility: "APP_VISIBILITY_HIDDEN",
        custom_attribute_definition_data: {
            name: "PackSizeKgs",
            key: "pack_size",
            type: "NUMBER"

        }
    }]
}];

```

Finally, you’re calling `upsertCatalogObject`, so once you fix the above error you’d receive another error. Change this to `batchUpsertCatalogObjects(body).then...` instead.
