Having trouble creating a record with the tulip table api
8/9/2023, 8:47:10 AMnode: tulip-tablesmsg : error
“Error: Response status code 422”
Debug :errorCode: “MustSpecifyID”
details: “You must specify the id when creating a record”
trying to set id to the following
var date = flow.get(‘date’);
msg.recordId = date;
return msg;
Hey @kmcgavern -
You should encode the record id directly within the msg.payload
object. What that means is you will have a function that looks something like:
var date = flow.get(‘date’);
msg.payload.id = date;
msg.payload.hfaklsf_field_1 = "example value";
msg.payload.krsuaa_field_defect_type = "Scratched part";
...
return msg;
Hope this helps-
Pete
I am still receiving the same 442 message
I turned the date into a string in an attempt to generate a unique id. Is there a more reliable method to generate a unique id?
My function is the following:
var date = flow.get(‘date’);
var ppm = msg.payload;
msg.payload.id = date;
msg.payload.eefom_ppm = ppm;
return msg;
table id: ATutE5xgrKDx5PzJu
field id: eefom_ppm
Totally my fault, I forgot one of the key details here. Just went end-to-end on my instance with this code in my function.
function generateRandomString(length) {
const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
result += charset.charAt(randomIndex);
}
return result;
}
msg.body = {}
msg.body.id = generateRandomString(15)
return msg;
The big piece I was forgetting is that it is actually the msg.body element that is passed to the api, not the .payload attribute.
I also threw in a random string function that I usually just copy paste for this sort of thing. At 15 characters, this has about 90 bits of entropy, which is very safe in practice, but true UUIDs generally need to be around 128, which would correlate to a string about 23 characters long.
Pete
It works great now! Thanks for your help.