How to use "Custom" body type in Service Node

Hi Team,

I have two questions here, both are relate to “Service Node” request body.

  1. Please help me out on how to use the “Custom” body type .

  2. JSON (application/json - content type) object is accepting only string variable not number or date variables it seems in, please correct me if I am wrong here.

Thanks,
Karthik

1 Like

@karthik.nagulapally The values of data type number or date can be passed by selecting application/json type at request . And custom type helps developers to send the request payload in a format other than JSON say XML for instance. date and numbers can be passed in the payload for request payload type as application/json. Refer https://developer.kore.ai/docs/bots/bot-builder/defining-bot-tasks/dialog-tasks/working-with-the-service-node/ for more details.

Having said that, please provide us with the CURL so that we could look into your issue further and get back.

Thanks
Swathi

@swathi.vadlamani, thank you for the reply.

Here is my observation, I have an API which is accepting amount as number and If I pass it as part of JSON, it is considering as String not as Number. May I know where I can see the actual API request that is making by Kore.AI(I could not see the complete request from the Kore Debugger).

Here is what I have found from the browser console,

"{“context”:{“entities”:{“OpportunityName”:“Opp Kore 2”,“SelectedAccount”:“accounts(9248bda7-d435-e311-8795-78e7d1620f53)”,“Amount”:“20000”,“OpportunityCloseDate”:“2018-11-09”},“accountidtouse”:“su-2d878281-28df-5ad0”}} "

Look at the “Amount”, which is a Number entity but it sent as a String from Kore.

Please find the attached Service Node Body that I have configured.

54%20PM 13%20PM

"budgetamount":"{{context.entities.Amount}}"
Does the above param will be converted to Number during the API request ? Please look into this, and let me know your comments.

Thanks,
Karthik

Hi @karthik.nagulapally,
Please follow the below steps to pass the data to the endpoint:

  1. Select the type of request data being sent as “Custom”
    image
  2. Mention the values at keys which are stored in the context.entities.entityname without the quotes as shown in above snip.
  3. Now provide a value at the entity for testing and click test
    image
  4. Below snip show the request body which is passed to the end point
    image

Do let us know if you are still facing the issue and we could debug further.

Kr,
Subbu

Hi @Subrahmanyam, thank you for the detailed information.

I have followed the mentioned steps, and here is my observation,

Scenario-1:

  1. Tried by providing content-type as application/json and body as Custom
  2. Executed the API as expected.
  3. Moved out of service node and came back again
  4. Observed “Custom” changed to “application/json” and showing error in the payload

Scenario-2: (Just tried, not recommended)

  1. Tried by not providing the content-type, but body as Custom
  2. Error thrown by Kore regarding Content-Type.

But there is one more scenario I want to try with is, use Script node to prepare payload, save it in context variable and use the variable as payload for content type “application/json”. I have yet to try it, I’ll let you know the update.

Thanks,
Karthik

Hi @Subrahmanyam @swathi.vadlamani,

Script node is really worked for preparing the request body. Though bot builder showing error it is executing the API request and working as expected.

Thanks,
Karthik

Thanks @karthik.nagulapally. While we look into the observations you have with the request type on bot builder, we are happy your issue is resolved and you are able to execute the API fine during run time.

Glad, we could help you @karthik.nagulapally!

Hi @Subrahmanyam,
Thanks for your detailed steps.
By following your steps , I was able to make API call, and getting following response.

{
“statusCode”: 200,
“body”: “<result>Incident Created Successfully</result>”,
“headers”: {
“date”: “Wed, 30 Jan 2019 09:40:38 GMT”,
“x-powered-by”: “Servlet/3.0”,
“connection”: “close”,
“transfer-encoding”: “chunked”,
“content-type”: “text/plain”,
“content-language”: “en-US”
}
}

scr1

Service node CallINCService is default connected to message node.

Further I need to provide message to user for Body response.
I am providing following message response, But it is not working ,

Print(“This is your ticket information: +context.CallINCService.response.body.result”)

Could you please guide here. If anything wrong.

Thanks in advance.

@shobhit1.singh, I see the data under body of service node coming as text with some xml tags in it. You could possibly create a JS node to create a context variable and store the extracted value “Incident Created Successfully” from the body of the service node by trimming off the rest of the data. Further you would be able to use this variable to print the message at the message node.

Thanks @Subrahmanyam. I have created script node to fetch the body response from service node.
and passing below script in Add script window.

(Sample response I already attached in my previous post)

Further checked on this from my side,
I am able to print the jsonstringobj in message node successfully with below script.
var jsonstringobj = JSON.stringify(context.CallINCService);
print(“This is your ticket information” +jsonstringobj);

and this is the output from BOT for message node:
{“response”:{“statusCode”:200,“body”:“Incident Created Successfully”,“headers”:{“date”:“Thu, 07 Feb 2019 12:38:05 GMT”,“x-powered-by”:“Servlet/3.0”,“connection”:“close”,“transfer-encoding”:“chunked”,“content-type”:“text/plain”,“content-language”:“en-US”}}}

But when I am trying to print the body response with below script, it is failing with following error
print(“This is your ticket information” +jsonstringobj.response.body);

response1

response2

Why it is saying, "can not property response and body and undefined.

Please help me on this. We are following on this since last 3-4 days.

Thanks in advance.

Hi @shobhit1.singh, I have verified the issue from my side by storing the below data into context.result at a script node:

image

Then, at the message node, I am using the adv editor to print the below:
print("This is your ticket information: " + context.result.response.body);

Below is the snapshot showing that message is resolving fine during run time.

HI @Subrahmanyam,

I’m facing issue with Custom body in Service node with XML data. Can we write conditions in XML body.

if(gender == 'M'){ Male } else { Female }

Note : While sending request from Bot if condition also going as input I don’t want that.

Thanks in Advance !!!

Hi @m.satish512, Could you please use a script node at the dialog to apply logic, store the result onto a context variable and then send it directly from the payload being sent at service node?

Hi @Subrahmanyam,

Below is my requirement. Can we add “If condition” inside the body of Service Node.

{{context.name}} if(productCount >= 1){ Yes } else{ No }

Hi , when I am trying to use script node to store context and sending it as custom payload, it is passing empty data for REST API URL .

ai_doubt

context.requestBody is my script variable.
Capture

this is how I am passing it to Service

Capture1

Could you provide screenshots or details on data added at context.requestBody and the payload as received by your endpoint here?

this is my script

context.requestBody=JSON.stringify({
“fields”: {
“project”: {
“key”: “key name”
},
“parent”: {
“key”: "Key name "
},
“summary”: “Summary”,
“description”: “summary for context.UserContext.firstName”,
“issuetype”: {
“name”: “name”
}
}
}
);

it is received as below at endpoint
ai_doubt

I tried testing it on beeceptor, it shows empty request body though i am passing the this context variable as custom type body

Tested it at a beeceptor URL and the payload is received fine. Please refer to the below screenshots:

image
image
image
image
image

Also,If you are testing the service at the service node itself, then the value has to be passed at the defined variable as shown in below snip:
image

1 Like

shouldnt the value of context.UserContext.firstname be reflected in the final request body ?
Because that is not happening.