js-webflow-api icon indicating copy to clipboard operation
js-webflow-api copied to clipboard

`webflow.updateItem(...)` method inconsistent with other methods

Open sebscholl opened this issue 1 year ago • 1 comments

Hi!

The webflow.updateItem(...) method introduced a spread operation in the arguments that makes it behavior differently (and unnecessary) from other methods on the object.

The documentation (READme.md) specifies that both the updateItem and createItem methods can be used like so:

// Create a new item
await webflow.createItem({
    collectionId,
    fields,
});

// Update an item
await webflow.updateItem({
    collectionId,
    itemId,
    fields,
});

However, the updateItem function doesn't work like this, as the method uses a spread operator and thus expects all fields to be at the top level of the passed object:

  async updateItem({ collectionId, itemId, ...fields }: { itemId: string; collectionId: string }) {
    const _params = { collectionId, itemId, fields };
    const res = await Item.update(_params, this.client);
    return new Item(this.client, res);
  }

This means that in order to use the method, you must use the following patter:

// Update an item
await webflow.updateItem({
    collectionId,
    itemId,
    ...fields,
});

This is a little awkward...and could be improved in the future by making a breaking change in the next major version bump.

In the meantime, updating the docs should help 👍

sebscholl avatar Jun 01 '23 03:06 sebscholl

This also caused me issues

andrewmclagan avatar Jul 25 '23 23:07 andrewmclagan