Common errors in Virtual Agent API
Summarize
Summary of Common errors in Virtual Agent API
This guide explains frequent errors encountered with the Virtual Agent API in ServiceNow’s Australia release and how to resolve them. It covers request structure validation, file upload methods, and user linking issues to help ensure smooth integration and operation of Virtual Agent interactions.
Show less
Virtual Agent API Request Structure Validation
The API expects a specific JSON request format where userId and message.text fields are mandatory. Other fields such as requestId, clientSessionId, emailId, action, contextVariables, history, and clientVariables are optional or pass-through. Properly structuring requests avoids common validation errors.
File Upload Handling
Virtual Agent API supports both synchronous and asynchronous file uploads:
- Synchronous mode: Upload files first using the Media API to receive a media URL. Then include this media URL in the Virtual Agent API request’s
message.attachment.urlfield. - Asynchronous mode: You can send a direct public file URL or a protected URL with authentication headers embedded in the attachment section of the request.
Required fields for file uploads include contentType (e.g., image/png), fileName, and url. Optional headers support authentication for protected resources.
User Linking Considerations
Automatic user linking is supported by default but requires correct configuration and prerequisites:
- Message Authentication: Must be properly configured and active to enable linking functionality.
- Request Fields: Both
userIdand a validemailIdmust be included in API requests. - User Record Requirements: The
emailIdmust exactly match one active, unlocked user record in thesysusertable. If multiple users share the same email, linking will fail. - Provider Configuration: Ensure the
automaticlinkenabledandlinkaccountenabledflags are true in the relevant provider records, and that the automatic link action points to the appropriate script. - Provider User Map: Inactive mappings for the user must be removed to allow linking.
- Customizations: Review any custom scripts affecting auto-linking to avoid logic conflicts.
Following a comprehensive troubleshooting checklist helps quickly identify and resolve user linking failures.
This section describes some common errors in Virtual Agent API and how they can be resolved.
Virtual Agent API structure validation
Request structure:
{
"requestId": "any-unique-request-id",
"clientSessionId": "any-unique-session-id",
"userId": "any-unique-user-id",
"emailId": "user@example.com",
"action": "",
"message": {
"text": "User message text",
"typed": true
},
"contextVariables": {},
"history": [
{
"isBotMessage": true,
"value": "How can I help you?",
"displayName": "Bot",
"type": "text"
}
],
"clientVariables": {
"id": "va-bot-12345",
"timestamp": "1687527831786"
}
}| Field | Required | Description |
|---|---|---|
requestId |
No | Pass-through variable returned in responses |
clientSessionId |
No | Pass-through session identifier |
userId |
Yes | Unique user identifier (mandatory) |
emailId |
No* | User email for linking (*required for user linking) |
action |
No | Optional action parameter |
message.text |
Yes | User message content (mandatory) |
message.typed |
No | true for search text, false for value selection |
contextVariables |
No | Optional context data |
history |
No | Bot conversation history (first request only) |
clientVariables |
No | Pass-through client variables |
File upload issues
Virtual Agent API supports two file upload modes, such as Synchronous and Asynchronous.
File upload request structure:
{
"userId": "{{user_id}}",
"message": {
"attachment": {
"clientAttachmentId": "{{request_id}}",
"contentType": "video/mp4",
"fileName": "sample.mp4",
"url": "https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4",
"headers": {
"header 1": "value 1"
}
},
"text": "along with text",
"typed": true
}
}
| Field | Required | Description |
|---|---|---|
contentType |
Yes | MIME type (e.g., video/mp4, image/png) |
fileName |
Yes | Name of the file with extension |
url |
Yes | Accessible URL to download the file |
clientAttachmentId |
No | Unique identifier for tracking |
headers |
No | Authentication headers for file download |
File upload in synchronous mode:
- Upload the file by using Media API. For more information, see CCCIF Media Resource API.Media API returns a url. An example of the response is:
{ "result": { "mediaUrl": "<instance>/api/now/v1/cs/media/JOBBfkqSq6kDiFzxyinvHhke73O4TZ0j", "name": "image.png", "state": "available", "attachmentId": "e8671b9193209210a755b8e86cba104b" } } - Use the media url in Virtual Agent API request. A JSON example is:
{ "userId": "user123", "message": { "attachment": { "contentType": "image/png", "fileName": "image.png", "url": "<instance>/api/now/v1/cs/media/JOBBfkqSq6kDiFzxyinvHhke73O4TZ0j" }, "text": "Here is the image", "typed": true } }
File upload in asynchronous mode:
- Use the file url in the Virtual Agent API request.
- Direct file url:
{ "userId": "user123", "message": { "attachment": { "contentType": "application/pdf", "fileName": "report.pdf", "url": "https://publicserver.com/files/report.pdf" }, "text": "Document attached", "typed": true } } - Protected file url:
{ "userId": "user123", "message": { "attachment": { "contentType": "application/pdf", "fileName": "confidential.pdf", "url": "https://secureserver.com/files/confidential.pdf", "headers": { "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "X-Custom-Header": "custom-value" } }, "text": "Secure document attached", "typed": true } }
- Direct file url:
- Using the Media API (as followed in synchronous mode).
User linking issues
Virtual Agent API supports automatic user linking only out-of-the-box. Manual linking is not enabled by default in Virtual Agent API.
- Message Auth is mandatory.
- Without message auth in
sys_cs_provider_application, user linking doesn't work. - You must configure Message auth properly. (See the authentication section.)
- Without message auth in
- Required request fields.
userIdmust be present and unique.emailIdmust be present and valid.
User record requirements:
emailId must match a sys_user record that meets all of the below conditions:- Record exists in the
sys_usertable. - Email field matches exactly.
- User is active. (
active=true) - User is not locked out. (
locked_out=false) - Only one user record matches these conditions.
- Verify the provider configuration.
- Navigate to the
sys_cs_providertable and open the "VA Bot to Bot Provider" record. -
Table 3. Required setting Field Expected Value automatic_link_enabledtrueautomatic_link_actionsn_va_as_service.virtual_agent__bot_to_bot_auto_link_accountlink_account_enabledtrue
- Navigate to the
- Check the provider user map.
- Navigate to the
provider_user_maptable. - Filter by:
active=falseANDchannel_user_id={userId from request}. - Issue: If record exists with
active=false, the user cannot be linked automatically. - Solution: Admin must manually delete the inactive record and retry the linking request.
- Navigate to the
- Check for customizations.
- Review customizations by running the
sn_va_as_service.virtual_agent__bot_to_bot_auto_link_accountscript. - Check for the common customization issues:
- Logic preventing automatic linking
- Additional validation checks
- Modified field mappings
- Review customizations by running the
User linking troubleshooting checklist:
- Configuration:
- Message auth exists and is active.
userIdis present in request.emailIdis present in request.automatic_link_enabled = trueautomatic_link_actionpoints to correct script.link_account_enabled = true
- User record:
- User exists in
sys_user. - Email matches exactly (case-sensitive).
- User is active.
- User is not locked out.
- Only one user matches the email.
- User exists in
- Provider user map:
- No inactive records for this
userId. - Check for duplicate mappings.
- No inactive records for this
- Customizations:
- Review auto-link script for modifications.
- Test with OOB script if customized.