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. It’s happening both in production and test mode.
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,
...
}
}
I am using python 3.12.8 and the package versions are:
pydantic==2.10.6
fastapi==0.115.7
httpx==0.28.1
uvicorn==0.34.0
google-cloud-firestore==2.20.0
firebase-admin==6.6.0
google-cloud-logging==3.11.3
google-cloud-tasks==2.18.0
user-agents==2.2.0
pytz==2024.2
urllib3==2.3.0
gcloud-aio-storage==9.3.0
pytest-asyncio==0.25.3
pytest-mock==3.14.0
python-multipart==0.0.20
pillow==11.1.0
types-Pillow==10.2.0.20240822
types-protobuf==5.29.1.20241207
alembic==1.14.1
SQLAlchemy==2.0.37
psycopg2-binary==2.9.10
transformers==4.48.1
asyncpg==0.30.0
types-pytz==2024.2.0.20241221
mixpanel==4.10.1
async-customerio==1.4.1
google-cloud-bigquery==3.29.0
phonenumbers==8.13.53
fastparquet==2024.11.0
taxjar==2.0.0
pandas-stubs==2.2.3.241126
pandas==2.2.3
pyarrow==19.0.0
types-aiofiles==24.1.0.20241221
gcloud-aio-bigquery==7.1.0
langchain==0.3.16
langchain-community==0.3.16
langchain-anthropic==0.3.4
langchain-core==0.3.32
langchain-openai==0.3.2
logsnag==1.0.1
types-python-dateutil==2.9.0.20241206
elasticsearch==8.17.1
RapidFuzz==3.11.0
app-store-server-library==1.5.0
Thank you,
Nawfal