Skip to main content

Users API

Retrieve and browse your chatbot's users programmatically through the Developer API.


Base URL

https://api.peki.ai/api

Authentication

All endpoints require HMAC-SHA256 authentication. See the Messages API guide for full details on signature generation.

Required Headers

HeaderRequiredDescription
Content-TypeMust be application/json
X-API-KeyYour API key (starts with pk_)
X-SignatureHMAC-SHA256 signature
X-TimestampUnix timestamp in seconds

List Users

Get all users for your chatbot with pagination.

GET /Dev/{chatbotId}/users

Path Parameters

ParameterTypeRequiredDescription
chatbotIdstringThe unique identifier for your chatbot

Query Parameters

ParameterTypeRequiredDefaultDescription
pageint1Page number (1-based)
pageSizeint20Number of items per page

Response

{
"data": [
{
"id": "6612a1b2c3d4e5f6a7b8c9d0",
"chatbotId": "your_chatbot_id",
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"phoneNumber": "+1234567890",
"username": "johndoe",
"source": "Dev",
"dataDictionary": {
"city": "Istanbul"
},
"messageTimestamp": "2025-04-08T12:00:00Z",
"lastReceivedText": "Hello!",
"createdAt": "2025-04-01T10:00:00Z",
"updatedAt": "2025-04-08T12:00:00Z"
}
],
"error": null,
"totalItems": 45,
"pageSize": 20,
"currentPage": 1,
"totalPages": 3
}

Response Fields

FieldTypeDescription
idstringUnique identifier for the user
chatbotIdstringThe chatbot this user belongs to
firstNamestringUser's first name
lastNamestringUser's last name
emailstringUser's email address
phoneNumberstringUser's phone number
usernamestringUser's username
sourcestringPlatform where the user originated (Web, Dev, etc.)
dataDictionaryobjectCustom key-value data attached to the user
messageTimestampdatetimeTimestamp of the user's last message
lastReceivedTextstringThe most recent message sent by the user
createdAtdatetimeWhen the user profile was created
updatedAtdatetimeWhen the user profile was last updated

Get User

Get a single user by their ID.

GET /Dev/{chatbotId}/users/{userId}

Path Parameters

ParameterTypeRequiredDescription
chatbotIdstringThe unique identifier for your chatbot
userIdstringThe unique identifier for the user

Response

{
"data": {
"id": "6612a1b2c3d4e5f6a7b8c9d0",
"chatbotId": "your_chatbot_id",
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"phoneNumber": "+1234567890",
"username": "johndoe",
"source": "Dev",
"createdAt": "2025-04-01T10:00:00Z",
"updatedAt": "2025-04-08T12:00:00Z"
},
"error": null
}

Error Response

{
"data": null,
"error": "User not found."
}

Pagination

All list endpoints return paginated results with the following metadata:

FieldTypeDescription
totalItemsintTotal number of records
pageSizeintNumber of items per page
currentPageintCurrent page number
totalPagesintTotal number of pages

Use the page and pageSize query parameters to navigate through results. Results are ordered by creation date (newest first).


Code Examples

JavaScript

const crypto = require("crypto");

const apiKey = "pk_your_api_key";
const apiSecret = "sk_your_api_secret";
const chatbotId = "your_chatbot_id";

const timestamp = Math.floor(Date.now() / 1000);
const path = `/api/Dev/${chatbotId}/users?page=1&pageSize=20`;
const payload = `GET\n${path}\n\n${timestamp}`;
const signature = crypto
.createHmac("sha256", apiSecret)
.update(payload)
.digest("base64");

const response = await fetch(`https://api.peki.ai${path}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-Key": apiKey,
"X-Signature": signature,
"X-Timestamp": timestamp.toString(),
},
});

const result = await response.json();
console.log("Users:", result.data);
console.log("Total:", result.totalItems);

Python

import hmac, hashlib, base64, time, requests

api_key = 'pk_your_api_key'
api_secret = 'sk_your_api_secret'
chatbot_id = 'your_chatbot_id'

timestamp = str(int(time.time()))
path = f'/api/Dev/{chatbot_id}/users?page=1&pageSize=20'
payload = f'GET\n{path}\n\n{timestamp}'

signature = base64.b64encode(
hmac.new(api_secret.encode(), payload.encode(), hashlib.sha256).digest()
).decode()

headers = {
'Content-Type': 'application/json',
'X-API-Key': api_key,
'X-Signature': signature,
'X-Timestamp': timestamp
}

response = requests.get(f'https://api.peki.ai{path}', headers=headers)
result = response.json()
print('Users:', result['data'])
print('Total:', result['totalItems'])

cURL

API_KEY="pk_your_api_key"
API_SECRET="sk_your_api_secret"
CHATBOT_ID="your_chatbot_id"

TIMESTAMP=$(date +%s)
REQ_PATH="/api/Dev/$CHATBOT_ID/users?page=1&pageSize=20"
PAYLOAD="GET\n$REQ_PATH\n\n$TIMESTAMP"
SIGNATURE=$(echo -ne "$PAYLOAD" | openssl dgst -sha256 -hmac "$API_SECRET" -binary | base64)

curl -s "https://api.peki.ai$REQ_PATH" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-H "X-Signature: $SIGNATURE" \
-H "X-Timestamp: $TIMESTAMP"

Error Codes

Status CodeDescription
401Invalid API key or signature
403API key doesn't have access to the specified chatbot
404User not found
500Internal server error