APIs & Integrations

niederberger
Participant

Contact Search > Wait for Response

SOLVE

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();

 

 

0 Upvotes
1 Accepted solution
niederberger
Solution
Participant

Contact Search > Wait for Response

SOLVE

Seems it's an Axios issuee, I did downgrade and the code works fine.
https://github.com/axios/axios/issues/5346

View solution in original post

0 Upvotes
1 Reply 1
niederberger
Solution
Participant

Contact Search > Wait for Response

SOLVE

Seems it's an Axios issuee, I did downgrade and the code works fine.
https://github.com/axios/axios/issues/5346

0 Upvotes