Hello. I did write that Script with the idea to look for the contact before to know, do I create new ones or do I update them. Something done a million times probably. My problem is that the script runs to fast somehow and doesn’t wait for the response. I thought it works with await. Because every time I run it locally I get a result back or it tells me “error > search_contact: Error: unexpected end of file. Does anyone has me a tipp? Thank You.
const search_contact = async () => {
const search_contact_data = {
"filterGroups": [
{
"filters": [
{
"operator": "EQ",
"propertyName": "email",
"value": email
}
]
}
]
}
try {
const search_contact_response = await axios.post('https://api.hubapi.com/crm/v3/objects/contacts/search', search_contact_data, {
headers: {
'content-type': 'application/json',
'authorization': token
}
})
const search_contact_total = search_contact_response.data;
console.log(search_contact_total);
if (search_contact_total.total === 1) {
const search_contact_id = search_contact_response.data.results[0].id;
console.log(search_contact_id);
return search_contact_id
}
} catch(error) {
console.log('error > search_contact: ' + error)
}
}
const search_contact_id = await search_contact();