Mockapi response through service node in version 11

I have set up a MockAPI, and while testing it through the chat flow, the API call fails. However, when I test the same API using a Service Node, it returns the expected response. I’ve made all possible adjustments to ensure the response is correct, but the API continues to fail during the chat flow execution.

below is the json body structure for post request:
{
“policyType”:“{{context.AI_Assisted_Dialogs.userDetails.entities.policyType}}”,
“policyHolder”:“{{context.AI_Assisted_Dialogs.userDetails.entities.policyHolder}}”,
“contactNumber”:“{{context.AI_Assisted_Dialogs.userDetails.entities.contactNumber}}”,
“location”:“{{context.AI_Assisted_Dialogs.userDetails.entities.location}}”,
“date”:“{{context.AI_Assisted_Dialogs.userDetails.entities.date}}”,
“lossAmount”:{{context.AI_Assisted_Dialogs.userDetails.entities.lossAmount}}
}

Hello Akash,

Please confirm if you are using XO 11 ?

this issue often occurs due to how context variables are resolved during runtime, especially within mock or simulated environments like chat flows.

Here are a few suggestions to help troubleshoot and resolve the issue:

  1. Check if all context variables are populated at runtime
    Ensure that context.AI_Assisted_Dialogs.userDetails.entities.[fieldName] values are actually populated before the API call is made in the chat flow. If any of them are undefined or null, the request may break or return an unexpected error.

  2. Add debug logs before the API call
    Add a Script Node or Log Node before the Service Node to log the values of all fields used in your JSON body. This will help verify what’s being passed during the chat flow.

print("policyType: ", context.AI_Assisted_Dialogs.userDetails.entities.policyType);
print("policyHolder: ", context.AI_Assisted_Dialogs.userDetails.entities.policyHolder);
// and so on...

Use stringify for safer payload construction
Instead of hardcoding the JSON body inside the Service Node, construct the payload using a Script Node first. This allows better control and debugging:

context.requestPayload = {
  policyType: context.AI_Assisted_Dialogs.userDetails.entities.policyType,
  policyHolder: context.AI_Assisted_Dialogs.userDetails.entities.policyHolder,
  contactNumber: context.AI_Assisted_Dialogs.userDetails.entities.contactNumber,
  location: context.AI_Assisted_Dialogs.userDetails.entities.location,
  date: context.AI_Assisted_Dialogs.userDetails.entities.date,
  lossAmount: context.AI_Assisted_Dialogs.userDetails.entities.lossAmount
};
  • Then use context.requestPayload as the body in your Service Node.
  • Validate data types
    Ensure that lossAmount is a number and not a string (since it’s not in quotes in your JSON). Incorrect typing can cause the API call to fail silently or return unexpected results.
  • MockAPI-specific note
    If you’re using an external mock API platform (like Mocky, Beeceptor, etc.), make sure it supports the request structure and method you’re using. Some mock APIs have limitations on headers or content types.

Let us know if this helps.

Thank you,
Srujan Madderla