Placeholders in JSON Body Not Replaced Dynamically in Custom Connector

I am creating a custom connector in UiPath Integration Service for an API. My JSON body contains placeholders mapped to parameters with the Form type. However, these placeholders are not being dynamically replaced during runtime, causing the API to return a 400 Bad Request with the error:
"JSON decode error".

Example JSON Body:

json

{
  "model": "llama-3.1-sonar-small-128k-online",
  "messages": [
    {
      "content": "{prompt}",
      "role": "user"
    }
  ],
  "max_tokens": 20,
  "temperature": 0,
  "search_domain_filter": [
    "perplexity.ai"
  ],
  "top_p": 0.9
}
  • The parameter prompt is defined as a Form type with String as the data type.
  • When testing, the placeholder {prompt} is not replaced dynamically, and the API fails.
  • If I use a Header parameter type instead, the API works correctly but doesn’t follow the required JSON body structure.

Question: How can I ensure that placeholders in the JSON body are dynamically replaced with values from Form parameters in UiPath Integration Service?
TIA.

Hey @Ahsan_01 Welcome to @UiPath_Community

Use Proper Placeholder Syntax:

In the JSON body, UiPath expects placeholders to be wrapped in double curly braces for dynamic replacement.

{
  "model": "llama-3.1-sonar-small-128k-online",
  "messages": [
    {
      "content": "{{prompt}}",
      "role": "user"
    }
  ],
  "max_tokens": 20,
  "temperature": 0,
  "search_domain_filter": [
    "perplexity.ai"
  ],
  "top_p": 0.9
}

Have a try : )

Happy Automation!

Best regards,
Ajay Mishra

Thanks for your response. I have tried this as well but still getting this error.
{
“requestId”: “674c7b77e4b05a2a551a5174”,
“providerErrorCode”: 400,
“message”: “Bad Request”,
“providerMessage”: “error - {message=["At body → 0: JSON decode error"], type=bad_request, code=400}”
}

Kindly let me know how to resolve it.

Hey @Ahsan_01

Construct the JSON body dynamically using string manipulation in UiPath Studio:

  1. Use the Assign activity:
jsonBody = "{""model"": ""llama-3.1-sonar-small-128k-online"", ""messages"": [{""content"": """ & promptVariable & """, ""role"": ""user""}], ""max_tokens"": 20, ""temperature"": 0, ""search_domain_filter"": [""perplexity.ai""], ""top_p"": 0.9}"

Note: promptVariable stores the value that you have to pass in JSON body.

Pass jsonBody to the API request.

Best regards,
Ajay Mishra