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.
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
- Hope Webflow can generate React code. HOT 2
- Configuration default host HOT 3
- Configuration params HOT 3
- CloudQuery Plugin? HOT 1
- 🐛 issue with authorizeUrl method HOT 3
- Typescript / Jest Compatibility Issues HOT 22
- Add live to Create and Update Methods (or add it to the README.md) HOT 1
- Pagination data missing HOT 1
- RichText fields don't return Embedded content HOT 2
- API returning different name for fields HOT 2
- `webflow.updateItem(...)` method inconsistent with other methods HOT 1
- 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.