PinionAI API
This document provides details about the API endpoints available in the PinionAI API agent
service.
Authentication
Most endpoints require a Bearer token in the Authorization
header for authentication.
Authorization: Bearer <YOUR_ACCESS_TOKEN>
Endpoints
1. Start Agent Session
- Endpoint:
GET /agent/:uid
- Method:
GET
- Description: Initiates an agent session. It retrieves agent information based on the provided UID and creates a new session.
- Authorization: Bearer token required.
- Path Parameters:
uid
(string, required): The unique identifier of the agent.- Responses:
200 OK
: Agent started successfully.{ "success": true, "message": "Agent started successfully", "data": { // Session object "uid": "session_uid", "customer_uid_fk": null, "agent_uid_fk": "agent_id_from_agent_json", "account_uid_fk": "account_id_from_token", "session_data": { /* agent JSON data */ }, "created": "timestamp", "lastmodified": "timestamp", "transfer_requested": null, "transfer_accepted": null } }
400 Bad Request
: Invalid UID format.401 Unauthorized
: Missing or invalid bearer token, or token expired.404 Not Found
: Agent not found.500 Internal Server Error
: Database or other server error.
2. Start Agent Session from Version
- Endpoint:
GET /version/:uid
GET /version/:uid/:version_type
- Method:
GET
- Description: Initiates an agent session based on a specific version. It retrieves agent version data and creates a new session.
- Authorization: Bearer token required.
- Path Parameters:
uid
(string, required): The unique identifier of the agent.version_type
(string, optional): The type of the version (e.g., "sandbox", "live"). Defaults to "live" if not provided (handled by the backend SQL query).- Responses:
200 OK
: Agent version started successfully.{ "success": true, "message": "Agent version started successfully", "data": { // Session object "uid": "session_uid", "customer_uid_fk": null, "agent_uid_fk": "agent_uid_from_path", // or extracted from version data "account_uid_fk": "account_id_from_token", "session_data": { /* agent version data */ }, "created": "timestamp", "lastmodified": "timestamp", "transfer_requested": null, "transfer_accepted": null } }
400 Bad Request
: Invalid UID format.401 Unauthorized
: Missing or invalid bearer token, or token expired.404 Not Found
: Agent version not found.500 Internal Server Error
: Database or other server error.
3. Generate Token
- Endpoint:
POST /token
- Method:
POST
- Description: Generates a new access token for a client.
- Request Body:
- Responses:
200 OK
: Token generated successfully.400 Bad Request
: Invalid request format or unsupported grant type.401 Unauthorized
: Invalid client credentials.500 Internal Server Error
: Database or other server error.
4. Create or Update Session
- Endpoint:
POST /session
- Method:
POST
- Description: Creates or updates an agent session.
sessionUid
can be provided in URL query, form data, or JSON body. - Authorization: Bearer token required.
- Request Body (if
sessionUid
anddata
in JSON): - Query/Form Parameters (alternative to JSON body for
sessionUid
): sessionUid
(string)- Responses:
200 OK
: Session data updated successfully.400 Bad Request
: Invalid request format (e.g., missingsessionUid
, invalid timestamp format).401 Unauthorized
: Missing or invalid bearer token, or token expired.404 Not Found
: Session not found (if updating an existing session).500 Internal Server Error
: Database or other server error.
5. Get Session
- Endpoint:
GET /session/:uid
- Method:
GET
- Description: Retrieves an agent session.
- Authorization: Bearer token required.
- Path Parameters:
uid
(string, required): The unique identifier of the session.- Responses:
200 OK
: Session retrieved successfully.400 Bad Request
: Invalid UID format.401 Unauthorized
: Missing or invalid bearer token, or token expired.404 Not Found
: Session not found.500 Internal Server Error
: Database or other server error.
6. Get Session Last Modified Timestamp
- Endpoint:
GET /session/:uid/lastmodified
- Method:
GET
- Description: Retrieves the last modified timestamp for a given session UID.
- Authorization: Bearer token required.
- Path Parameters:
uid
(string, required): The unique identifier of the session.- Responses:
200 OK
: Last modified timestamp retrieved successfully.400 Bad Request
: Invalid UID format.401 Unauthorized
: Missing or invalid bearer token, or token expired.404 Not Found
: Session not found.500 Internal Server Error
: Database or other server error.
7. Get Customer
- Endpoint:
GET /customer/:value
- Method:
GET
- Description: Retrieves customer data by phone, email, or UID, associated with the authenticated account.
- Authorization: Bearer token required.
- Path Parameters:
value
(string, required): The customer's phone number, email address, or unique identifier.- Responses:
200 OK
: Customer data retrieved successfully.400 Bad Request
: Invalid value format.401 Unauthorized
: Missing or invalid bearer token, or token expired.404 Not Found
: Customer not found.500 Internal Server Error
: Database or other server error.
8. Create Customer
- Endpoint:
POST /customer
- Method:
POST
- Description: Creates a new customer associated with the authenticated account.
- Authorization: Bearer token required.
- Request Body:
- Responses:
201 Created
: Customer created successfully.400 Bad Request
: Invalid request format.401 Unauthorized
: Missing or invalid bearer token, or token expired.500 Internal Server Error
: Database or other server error.
9. Update Customer
- Endpoint:
POST /customer/:uid
- Method:
POST
- Description: Updates an existing customer associated with the authenticated account. Fields not provided in the request will retain their existing values.
- Authorization: Bearer token required.
- Path Parameters:
uid
(string, required): The unique identifier of the customer to update.- Request Body (all fields optional, provide only what needs to be updated):
Note: The
{ "customerFirst": "UpdatedFirstName", "customerLast": "UpdatedLastName", "customerEmail": "updated@example.com", "customerPhone": "0987654321", "customerConfig": { /* new JSON config object */ }, "customerData": { /* new JSON data object */ } }
database.UpdateCustomerParams
struct is used for binding, so field names in the JSON should match thejson
tags in that struct (e.g.,customerFirst
,customerLast
,customerEmail
,customerPhone
,customerConfig
,customerData
). - Responses:
200 OK
: Customer updated successfully.400 Bad Request
: Invalid request format or missing UID.401 Unauthorized
: Missing or invalid bearer token, token expired.404 Not Found
: Customer not found.500 Internal Server Error
: Database or other server error.
Data Structures
pathParameters
customerParameters
TokenRequest
type TokenRequest struct {
GrantType string `json:"grant_type"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
}
CreateCustomerRequest
type CreateCustomerRequest struct {
Phone string `json:"phone"`
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}
(Other internal or database-specific structs like apiAgent
, TokenResponse
, Token
, database.CreateSessionParams
, database.UpdateCustomerParams
etc., are used internally but their relevant fields are reflected in the request/response examples above.)