How to create/update a Haptik User using API?
- Getting Started
- Bot Building
- Smart Agent Chat
- Conversation Design
-
Developer Guides
Code Step Integration Static Step Integration Shopify Integration SETU Integration Exotel Integration CIBIL integration Freshdesk KMS Integration PayU Integration Zendesk Guide Integration Twilio Integration Razorpay Integration LeadSquared Integration USU(Unymira) Integration Helo(VivaConnect) Integration Salesforce KMS Integration Stripe Integration PayPal Integration CleverTap Integration Fynd Integration HubSpot Integration Magento Integration WooCommerce Integration Microsoft Dynamics 365 Integration
- Deployment
- External Agent Tool Setup
- Analytics & Reporting
- Notifications
- Commerce Plus
- Troubleshooting Guides
- Release Notes
Create or Update Haptik User API
Eventually, when you will be sending messages via Haptik, you will provide Haptik with a unique id for every user (auth_id). This is supposed to be the unique identifier for the user in your system.
Before sending any message to Haptik, you need to register the user, during this phase you could also provide additional information like:
- name - mobile number - email - language preference - phone model - os version - package name
The User API allows you to register the user via a POST request or update the user info via a PUT request to the Haptik Platform.
URL
Staging endpoint: https://staging-messenger.haptikapi.com/v1.0/user/
Production URL will be shared by your Haptik SPOC
Headers
Authorization: Bearer <TOKEN> client-id: <CLIENT_ID> Content-Type: application/json
- Authorization - The Authorization header of each HTTP request should be “Bearer” followed by your token which will be provided by Haptik
- client-id - The client id for your account which will be provided by Haptik
- Content-Type - application/JSON
Request
{ "auth_id": "<AUTH_ID>", "mobile_no": "<MOBILE_NO>", "email": "<EMAIL>", "name": "<NAME>", "language_code": "<LANGUAGE_CODE>", "custom_data": "<FLAT JSON OBJECT>" }
auth_id - This is an alphanumeric User identifier from your System
mobile_no (optional) - Mobile no of the user
email (optional) - Email of the user
name (optional) - Name of the user
language_code (optional) - This is a language identifier for user's preferred language based on ISO 639-1 (standardized nomenclature used to classify language) Eg: en for English, hi for Hindi(optional)
phone model (optional) - Phone model/type that the user is using
os version (optional) - OS version of where the user is coming from (Android, iOS, Windows etc.)
package name (optional)- An identifier to differentiate between different Apps on the device (WhatsApp or custom client app)
-
custom_data (optional) - Any additional information about the user (which could not be captured by any of the above fields) should be added as a part of this flat JSON structure.
Thus, additional information like country, city, date of birth, etc. which needs to be stored along with the user, should go here as:{ "country": "India", "city": "Mumbai", "date_of_birth": "25-03-1985" }
Rules for valid custom_data value:
- The value assigned to custom_data should always be a valid JSON.
- This value should always be a flat JSON. In other words, no property can have a JSON object assigned to it.
For instance, the below JSON, though a valid JSON in itself, will still be considered as an invalid custom_data value since the property, address, is assigned a JSON object:{ "date_of_birth": "12-8-1993", "address": { "country": "India", "state": "Goa" } }
The suggested way is to flatten the above JSON as:{ "date_of_birth": "12-8-1993", "country": "India", "state": "Goa" }
Response
A successful request to the user creation API will return a 200 status code with a JSON response object.
{ "auth_id": "<AUTH_ID>", "mobile_no": "<MOBILE_NO>", "email": "<EMAIL>", "name": "<NAME>" }
Error Response
If the Authorization header is missing or invalid, then the API will return a 401 status code.
{ "error_message": "invalid authorization details" }
Sample CURL command
Create User
curl -X POST \ https://staging-messenger.haptikapi.com/v1.0/user/ \ -H 'Authorization: Bearer <TOKEN>' \ -H 'client-id: <CLIENT_ID>' \ -H 'Content-Type: application/json' \ -d '{"auth_id": "<AUTH_ID>", "name": "guest user", "language_code":"<LANGUAGE_CODE>", "custom_data": { "<key_1>": "<value_1>", "<key_2>": "<value_2>" }}'
Update User
curl -X PUT \
https://staging-messenger.haptikapi.com/v1.0/user/ \
-H 'Authorization: Bearer <TOKEN>' \
-H 'client-id: <CLIENT_ID>' \
-H 'Content-Type: application/json' \
-d '{"auth_id": "<AUTH_ID>", "name": "guest user", "language_code":"<LANGUAGE_CODE>",
"custom_data": {
"<key_1>": "<value_1>",
"<key_2>": "<value_2>"
}}'