Can't Create New CMS Items with Webflow API

Hi Guys.

I’m really desperately trying to create collection items through the Webflow API.

Here’s the code I’ve been using :

const fs = require(‘fs’);
const parse = require(‘csv-parse’);
const Webflow = require(“webflow-api”);

var parser = parse({columns: true}, function (err, records) {

const webflow = new Webflow({token : “xxxxxxx”});
for(i = 0; i<records.length; i++){
var equipement_array = ;
var equipement_string = records[i].EQUIPEMENTS.split(“,”);
equipement_string.forEach(element =>{
if(element == “barre de lap dance”){
equipement_array.push(“6036b964748af861cf3ed949”)
}else if(element == “musique”){
equipement_array.push(“6036b9224e65a903fd054e6c”);
}else if(element == “douche xl”){
equipement_array.push(“6036b8a6d3b7be24c3bd148b”);
}else if(element == “parking privé”){
equipement_array.push(“6036b81e14de8fc41aeda6f9”);
}else if(element == “champagne”){
equipement_array.push(“6036b7fe29f38c9abd2de1fb”);
}else if(element == “sofa tantrique”){
equipement_array.push(“603539a53f6dda6bb4eae8c2”);
}else if(element == “machine à café”){
equipement_array.push(“6035398a1339ab61abb590cb”);
}else if(element == “vidéo”){
equipement_array.push(“6035396c5e301fe2b591b992”);
}else if(element == “ambiance lumineuse”){
equipement_array.push(“6035394356fa92177453ef79”);
}else if (element == “non fumeur”){
equipement_array.push(“603539289c295afc8d5f96aa”);
}else if (element == ‘tv’){
equipement_array.push(“603538c856fa9257f553ed65”);
}else if (element == “sauna”) {
equipement_array.push(“603538adc3c78474dc12841d”);
}else if (element == “jardin”){
equipement_array.push(“6035388156fa92b2b053ec92”);
}else if (element == “spa”) {
equipement_array.push(“6035386ae3111a569edf09b8”);
}else if (element == “serviettes”){
equipement_array.push(“60353857f4c43a0f9b91f2af”);
}else if (element == “cuisine équipée”) {
equipement_array.push(“6035383dae095d1503747a2e”);
}else if (element == “piscine extérieure”) {
equipement_array.push(“60353805f42dc15bc72003c2”);
}else if (element == “piscine intérieur”) {
equipement_array.push(“603537f5ada68315db11a941”);
}else if (element == “lit rond”) {
equipement_array.push(“603537d515b8e8b01ff206e2”);
}else if (element == “cheminée”) {
equipement_array.push(“603537bf63618c3c4f69b777”);
}else if (element == “wifi”) {
equipement_array.push(“603537a2775ef7859ea7046b”);
}else if (element == “carte cadeau”){
equipement_array.push(“603534b1ea94ae4c95688c81”);
}else if (element == “table de massage”) {
equipement_array.push(“6035348d69ee5b2a1dd97efe”);
}else if (element == “hammam”) {
equipement_array.push(“603534514650267364894766”);
}else if (element == “lit king size”) {
equipement_array.push(“6035343bca57065dfddf0c85”);
}else{
console.log(“error in naming amneties”);
};
});

const item = webflow.createItem({
collectionId: ‘xxxxxxxxxx’,
fields: {
“name” : records[i].H1,
“ville” : records[i].VILLE,
“region” : records[i].REGION,
“latitude” : records[i].LATITUDE,
“longitude” : records[i].LONGITUDE,
“lien-vers-etablissement” : records[i].LINK,
“date-d-ajout” : records[i].AJOUT_DATE,
“titre-description-h2” : records[i].H2,
“equipement-s” : equipement_array
}
});
item.then(i => console.log(i));
};
});

var data_stream = fs.createReadStream(“Bretagne.csv”).pipe(parser);

I’m getting error responses such as :
(node:20159) UnhandledPromiseRejectionWarning: WebflowError: ValidationError: Validation Failure
at /Users/martybellili/Documents/Webflow-API/node_modules/webflow-api/dist/Webflow.js:70:17
at process._tickCallback (internal/process/next_tick.js:68:7)

I’ve been working on this for 3 days.
Can anyone tell me what’s wrong ???

Thanks a lot.


Here is my site Read-Only: LINK
(how to share your site Read-Only link)

Add a catch() statement to log the WebflowError. It should contain an “err” property that will help understand what is the validation rule that you are breaking.

https://developers.webflow.com/?javascript#errors

Thats’s what I did and i gave me a bunch of NaN Output.
I solved the problem by adding additional fields to the field object inside the createItem function like _achived and _draft.

1 Like

Wow, I don’t think it says anywhere in API docs that all fields must be included?! In fact not quite all do?! This cost me a pile of time! :v(

A decent API would let you update only the fields that have changed.

Catch statement did not help. The full error was “WebflowError: ValidationError: Validation Failure”

“ValidationError: Validation Failure”

In my experience those errors are typically due to either:

  1. You are missing a value for a required field (in the Webflow CMS)
  2. You are missing a field that is required to exist (and is not being passed)

Since you have a lot of custom code listed, you have a lot of moving pieces that make it hard to narrow down. It would simplify things if you could get a very, very simple version working from either Integromat / Zapier first. They’ll typically auto-populate and include fields that may be non-intinutive to you. You can then figure out what your custom code is missing.