Hello,
I am using Intercom API in a GCP cloud run to do several things, especially updating a user.
Sometimes it works, but sometimes I get an 401 error: “token_not_found”, and I checked multiple times with logs: I am always sending the access token and it’s the right one. “intercom_user_id” is also the right one.
I also checked multiple times my server and logic, and there’s no error.
Here are some request ids where this error happened: 0003sad4ua316ingi1l0, 000an1qat9nc63bsg160, 0021017ivsn8tt93ipd0.
Here is the call in python:
url = f"https://api.intercom.io/contacts/{intercom_user_id}"
headers = {
"Authorization": f"Bearer {settings.INTERCOM_ACCESS_TOKEN}",
"Intercom-Version": "2.12",
"Content-Type": "application/json",
}
update_dict = intercom_profile.model_dump()
try:
response = await httpx_client.put(url=url, headers=headers, json=update_dict)
if response.status_code != 200:
log.info(response.json())
log.info(f"INTERCOM_ACCESS_TOKEN: {settings.INTERCOM_ACCESS_TOKEN}")
return False
return True
except Exception:
log.exception("failed updating user")
return False
And an example of what “update_dict” looks like:
{'role': 'user',
'name': 'username',
'signed_up_at': 1682037791,
'last_seen_at': 1738934990,
'custom_attributes':
{'Display name': 'display name',
'Description': ' ',
'First name': 'first_name',
'Last name': 'last_name',
'Follower count': 37767,
...
}
}
Thank you,
Nawfal