Error while using 'history' attribute in Virtual agent API

Kamal17
Kilo Sage

Hi,

While testing virtual agent API using postman, I'm getting errors in the system logs (listed below). These errors occur only when I add 'history' attribute in the request body. If I don't add the attribute then there was no error. Anyone faced similar issue?

 

Errors:

VABotToBotRestMessageHandler :: Error in VA Bot to Bot Rest API.java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Map (java.lang.String and java.util.Map are in module java.base of loader 'bootstrap')

 

Error in va_bot_to_bot_provider_attributes : Cannot find function forEach in object [object Object].

 

OOTB sample Endpoint:

https://demoinstance.service-now.com/api/sn_va_as_service/bot/integration

 

Sample request:

1. request with history attribute in the request body

{
"requestId":"req1111",
"action":"START_CONVERSATION",
"clientSessionId""",
"message":{
"text":"live agent support",
"typed":true,
"cliendMessageId":"msg1111"
},
"history":{ 
  "isBotMessage"false,
  "value""message 2"
  "displayName""User",
  "type""text"
}, 
"userId":"test_user",
"emailId":"testuser@testmail.com",
"timestamp":"1692082750",
"timezone":"America/New_York"
}

 

ServiceNow docs link to virtual agent API:

https://docs.servicenow.com/bundle/vancouver-api-reference/page/integrate/inbound-rest/concept/bot-a...

 

Thanks,

Kamal S

1 ACCEPTED SOLUTION

Kamal17
Kilo Sage

A minor correction to the request body resolved the issue. Value of the history parameter should be sent as array of objects.

{
"requestId":"req1111",
"action":"START_CONVERSATION",
"clientSessionId""",
"message":{
"text":"live agent support",
"typed":true,
"cliendMessageId":"msg1111"
},
"history":[
  "isBotMessage"false,
  "value""message 2"
  "displayName""User",
  "type""text"
}
]
"userId":"test_user",
"emailId":"testuser@testmail.com",
"timestamp":"1692082750",
"timezone":"America/New_York"
}

View solution in original post

4 REPLIES 4

Kamal17
Kilo Sage

A minor correction to the request body resolved the issue. Value of the history parameter should be sent as array of objects.

{
"requestId":"req1111",
"action":"START_CONVERSATION",
"clientSessionId""",
"message":{
"text":"live agent support",
"typed":true,
"cliendMessageId":"msg1111"
},
"history":[
  "isBotMessage"false,
  "value""message 2"
  "displayName""User",
  "type""text"
}
]
"userId":"test_user",
"emailId":"testuser@testmail.com",
"timestamp":"1692082750",
"timezone":"America/New_York"
}

Hi, I am also trying something similar but even with above format I am getting 400 error in rest API explorer, the error only occurs when I add history attribute without it its working fine getting 200 status code.

 

Can you please help me identify what could be the issue with using history attribute.

 

Make sure your endpoint is valid as per docs.

E.g., the default api is  "https://instancename/api/sn_va_as_service/bot/integration"

Most likely the issue could be due to incorrect request format. You can also share your api request body, I'll check it out.

 

somdev
Tera Contributor

@Kamal17 Even though this is an old post, could you by any chance were successful in sending Rich Text to bot/integration and display it correctly in the chat window  ? I am able to send link, Bold, Italics, but not able to embed image inside text and send it to ServiceNow via API call. Is this even possible or not ?