Comments (4)
The README is actually correct. The webflow.updateItem
function takes an object with the key fields which is an object of all the fields that should be updated.
from js-webflow-api.
It's not. I had to update this as well in order for it to work.
from js-webflow-api.
Do have nested objects somewhere in your code? Given an item like the following:
const item = {
name: 'My Item',
slug: 'my-item',
field: 'value',
_archive: false,
_draft: false,
};
const fields = item;
your call effectively results in this:
const updatedItem = await webflow.updateItem({
collectionId: "[COLLECTION ID]",
itemId: "[ITEM ID]",
name: 'My Item',
slug: 'my-item',
field: 'value',
_archive: false,
_draft: false,
});
which is clearly not right, you do want the item data inside an object fields
:
const updatedItem = await webflow.updateItem({
collectionId: "[COLLECTION ID]",
itemId: "[ITEM ID]",
fields: {
name: 'My Item',
slug: 'my-item',
field: 'value',
_archive: false,
_draft: false,
}
});
You can confirm this with a short look at the source; the method destructures three fields from an object parameter:
js-webflow-api/src/api/item.ts
Lines 128 to 142 in 9d36bb1
The only way your code might be correct is if you have your actual fields nested inside another object, like the following example:
const item = {
id: 'some-item-id',
dirty: true,
fields: {
name: 'My Item',
slug: 'my-item',
field: 'value',
_archive: false,
_draft: false,
},
};
if (item.dirty) {
const updatedItem = await webflow.updateItem({
collectionId: "[COLLECTION ID]",
itemId: item.id,
...item,
});
}
In this case the fields
object within the item
object would actually end up where updateItem()
expects it. (Don't do this, however, a future API change might start reading a field called dirty
and start misbehaving.)
from js-webflow-api.
This is no longer relevant given the v2
SDK release!
from js-webflow-api.
Related Issues (20)
- Cannot find module './core' in webflow-api/dist/index.js - v1.3.0 HOT 6
- Authorization using auth0 : Add a support for openid in the allowed scope .
- Beta flag not typed? HOT 2
- API Issue: Date/Time is not a valid format. HOT 2
- Update Token does not set underlying axios auth HOT 1
- How to get option field as string (v2)?
- Not able to update fields
- TypeError: res.data.map is not a function HOT 2
- Custom fields are not inserted into function createItem() HOT 3
- `webhooks.list` endpoint returns error: "ParseError: Expected list. Received object." HOT 1
- How to use pagination in `pages.list` endpoint? HOT 2
- updateItem and updateItem methods do not update item fieldData HOT 3
- collections.items.getItem prints spurious warning HOT 3
- Passing scopes as array to authorizeURL function produces a url with invalid_scope error HOT 2
- Regression: `webflow.sites.list()` returns the wrong type HOT 1
- Wrong type definition for Collection HOT 2
- Wrong node-fetch import in Fetcher HOT 4
- Wrong type for Collection `fields` HOT 2
- Validation Error: Invalid field type: Boolean HOT 3
- Generic `Item` response types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-webflow-api.