How to use "Custom" body type in Service Node

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.

Do you mean while you test the service? No, because the intention here is to test the service by providing inputs as needed. During runtime, the values would be picked from context as they were defined.

1 Like

hi can you please help me by explain how to pass payload for storing dynamic data

@53394.hexaware
Please see response on why am i not able to pass context variable in run time for a service