Hey forum,
I am trying to create API to send a “lead” to my client.
This is what I have right now:
function(properties, context) {
Bubble.plugins.action(“send-lead-to-offerte-vergelijker”, {
run_client: function (actions, data) {
const apiUrl = ‘https://www.offertevergelijker.nl/api/create/’;
const {
guid,
secret_key,
customer_first_name,
customer_last_name,
customer_postal_code,
customer_house_number,
customer_street,
customer_city,
customer_email_address,
customer_phone,
product_id,
type_request,
owner_of_building,
power_consumption,
execution_date,
extra_note,
} = data;
const leadData = {
guid,
secret_key,
customer: {
customer_first_name,
customer_last_name,
customer_postal_code,
customer_house_number,
customer_street,
customer_city,
customer_email_address,
customer_phone,
},
product: {
product_id,
type_request,
owner_of_building,
power_consumption,
execution_date,
extra_note,
},
};
if (data.type_roof) {
leadData.product.type_roof = data.type_roof;
}
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(leadData),
})
.then(response => response.json())
.then(data => {
console.log('API Response:', data);
actions.done();
})
.catch(error => {
console.error('API Error:', error);
actions.done({status: 'error', description: 'API-fout'});
});
},
});
}
This is the error I receive. What can I do to fix this?