This API endpoint is designed to update a user’s email in the chat log based on a provided session_id
and subsequently trigger a Zapier webhook event. The webhook event contains details about the updated chat session and is sent to a registered Zapier URL if one exists.
HTTP Method #
PUT
Endpoint #
Request #
Body Parameters #
The request expects a JSON payload with the following fields:
sessionid
(String): The unique session identifier for the user’s chat session.email
(String): The email to be associated with the chat session.
Example Request #
{
"sessionid": "12345abcd",
"email": "[email protected]"
}
Response #
Success Response #
- Status Code:
200 OK
- Body:
- A JSON object confirming the success of the operation:
{ "message": "success" }
- A JSON object confirming the success of the operation:
Error Response #
- Status Code:
404 Not Found
- Body:
- A JSON object indicating the error:
{ "error": "Chatlog not found" }
- A JSON object indicating the error:
Functionality Overview #
- Fetch Chatlog: The API retrieves the chat log based on the provided
session_id
. If no such session exists, it returns a404
response with the message “Chatlog not found.” - Update Email: Once the chat log is successfully fetched, it updates the
mail
field with the new email provided in the request. - Zapier Webhook Integration:
- The API checks if the user associated with the chat log has a registered webhook subscription (
WebhookSubscription
) with a target URL. - If a webhook URL exists, an event is triggered and sent to the Zapier webhook containing details about the session and the updated email.
- The payload sent to Zapier includes:
user_session_id
: The session ID of the chat.receiver_email
: The newly updated email.company_username
: The username of the associated company.name
: The name of the user in the chat log.country
: The country of the user in the chat log.status
: A string indicating the status of the event (in this case,"email_updated"
).
- The API checks if the user associated with the chat log has a registered webhook subscription (
- Error Handling:
- If no
WebhookSubscription
exists for the user, the system silently handles the situation without failing. - In case the HTTP request to Zapier fails, an error message is logged with the status code of the failed response.
- If no