Skip to main content

Hello!

I use an Airtable form to capture data from users. I want to send data from the bot to the form using URL parameters that allow me to prefill the form fields. If the Custom Fields are empty, the form fields should also be empty. However, ManyChat sends the Custom Fields' IDs as values in the URL parameters.

How to figure this out? 

 

If you click on the field, you can set a Default value.

What I usually do is type a space (‘ ‘) as the Default value, so if the field is empty it won’t show the {{cuf_xxxx}} thing.

It’s a workaround as it’s not technically ‘empty’, but it works most of the time.


I found a better solution for my case:

For the first time, I send only the user_id as a hidden parameter in the URL. The user will fill in the other fields themselves. After they send the form, Airtable makes an API request and sends the values of the fields AND the complete URL with all parameters (if the parameters are not null) to ManyChat in a separate custom field. All parameters are URL encoded. 

If the user clicks the button again, they can open the prefilled Airtable form with the data they entered before and just edit the fields if needed.

If somebody need a similar workflow here is the script for Airtable automation:

let inputConfig = input.config();

let token = inputConfig.token;
let user_id = inputConfig.user_id;
let fname = inputConfig.fname;
let lname = inputConfig.lname;
let phone = inputConfig.phone;
let email = inputConfig.email;
let tos = inputConfig.tos;
let subscribed = inputConfig.subscribed;
let department = inputConfig.department;
let form_url = inputConfig.form_url;

async function setCustomFields() {
let url = 'https://api.manychat.com/fb/subscriber/setCustomFields';
let fields =
{
"field_id": 11514531,
"field_name": "fname",
"field_value": fname
},
{
"field_id":11514532,
"field_name": "lname",
"field_value": lname
},
{
"field_id": 11515610,
"field_name": "phone",
"field_value": phone
},
{
"field_id": 11515611,
"field_name": "email",
"field_value": email
},
{
"field_id": 11514543,
"field_name": "tos",
"field_value": tos
},
{
"field_id": 11514543,
"field_name": "subscribed",
"field_value": subscribed
},
{
"field_id": 11515438,
"field_name": "department",
"field_value": department
},
{
"field_id": 11514688,
"field_name": "encoded_form_url",
"field_value": form_url
}
];

let payload = {
"subscriber_id": user_id,
"fields": fields
};

let response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify(payload)
});

if (!response.ok) {
console.error(`Error: ${response.statusText}`);
} else {
let result = await response.json();
console.log('Custom fields set successfully:', result);
}
}

setCustomFields();

 


Reply