https://retellai.com/?utm_source=discord&utm_medium=seo logo
In custom functions(PUT), how do you map dynamic v...
# ❓・ai-evy-support
b
@AI Evy In custom functions(PUT), how do you map dynamic variables to the json schema?
a
Thanks for tagging me @bohraz. I'll look through relevant sources and get back to you shortly.
### Answer To map dynamic variables to the JSON schema for a custom function (including PUT) , use the double curly braces syntax (e.g., {{variable_name}}) in your parameter definitions. In the custom function setup, define your parameters using JSON schema, then use dynamic variables as values when the function is called. Retell will substitute the dynamic variable with its current value during execution. Example JSON schema:
Copy code
json
{
  "type": "object",
  "properties": {
    "user_id": {
      "type": "string",
      "description": "The user's unique identifier"
    }
  },
  "required": ["user_id"]
}
When configuring the function, you can set the value as {{user_id}}. If the dynamic variable user_id is set in the conversation, it will be injected into the request payload automatically [(1) ]() [(2) ]() .
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
b
@AI Evy Where do I find the parameter definitions you are talking about? I only see the json schema. Are you talking about the query parameters or something else?
a
Thanks for the follow-up, @bohraz. I'll get back to you soon.
### Answer In the context of Retell AI custom functions, the "parameter definitions" refer to how you define the expected arguments for your function using a JSON schema when configuring the custom function node (for POST, PUT, or PATCH methods) . You do this in the "Define parameters" section of the custom function setup—not in query parameters, but as the schema for the body of the request [(1) ]() [(2) ]() . For example, you define parameters like this:
Copy code
json
{
  "type": "object",
  "properties": {
    "city": {
      "type": "string",
      "description": "The city of the weather"
    }
  },
  "required": ["city"]
}
When your function is called, Retell will inject dynamic variable values (e.g.,
{{city}}
) into the request body fields that match the schema definition [(1) ]() [(3) ]() [(2) ]() . Query parameters are a separate optional section in the custom function configuration and are not the same as the JSON schema parameters [(1) ]() [(2) ]() . The schema is specifically for the request body payload.
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[3] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Thanks for the follow-up, @bohraz. I'll get back to you soon.
b
@AI Evy So are you telling me to name my dynamic variables after the keys in the json schema? or something else
a
### Answer You do not need to name your dynamic variables after the keys in the JSON schema, but the mapping works as follows: - You define the expected fields for your custom function’s request body in the JSON schema (for example, "user_id", "city", etc.) . - When calling the function, Retell will look for dynamic variables with names matching those keys (e.g., {{user_id}}, {{city}}) and inject their values into the request body at runtime. - So, if your JSON schema defines a property "city", you should have a dynamic variable named "city" (set earlier in the conversation or via API) for the value to be populated automatically. You are not strictly forced to use these names elsewhere, but the variable names must match the schema keys for the automatic mapping to work as intended [(1) ]() [(2) ]() .
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
b
@AI Evy I keep on getting error: Axios Error: error code: ERR_BAD_REQUEST, error message: Request failed with status code 400 response status: 400 response data: ["Customer number is required"]
a
Thanks for the follow-up, @bohraz. I'll get back to you soon.
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) ​
### Answer A 400 Bad Request error with the message ["Customer number is required"] indicates that your custom function endpoint expects a field (likely customer_number or similar) in the request body, but it is missing when Retell calls your function [(1) ]() [(2) ]() . This usually means: - Your JSON schema for the custom function defines a required property (e.g., "customer_number") in the "required" array. - There is no dynamic variable named customer_number set in the conversation context at the time the function is called, so Retell cannot populate this field. To resolve this: 1. Make sure your JSON schema includes "customer_number" in both the "properties" and "required" lists. 2. Ensure that a dynamic variable with the name customer_number is set before the function is called (e.g., via a previous flow node or prompt) . For example:
Copy code
json
{
  "type": "object",
  "properties": {
    "customer_number": {
      "type": "string",
      "description": "The customer's number"
    }
  },
  "required": ["customer_number"]
}
If the dynamic variable is not set, the function call will fail and your endpoint will see this error .
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
b
@AI Evy Should I put {{CustNo}} in the description of the variable in the schema?
a
Thanks for the follow-up, @bohraz. I'll get back to you soon.
### Answer No, you should not put {{CustNo}} in the description field of your JSON schema variable. The description field is just for human-readable context and does not affect how dynamic variables are mapped. What matters is that the property name in your JSON schema (e.g., "CustNo" or "customer_number") matches the name of the dynamic variable that will be set in the conversation context. Retell will automatically inject the value of the dynamic variable into the request body field with the same name as defined in your schema—there’s no need to use curly braces or dynamic variable syntax in the description itself [(1) ]() [(2) ]() [(3) ]() .
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[3] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
b
@AI Evy The name of the dynamic variable is CustNo, and in the schema it has a required property called "CustNo" so I'm not sure why it isn't mapping. Here is my schema:
Copy code
{
  "type": "object",
  "required": [
    "CellPhone",
    "Email",
    "Make",
    "State",
    "VIN",
    "Model",
    "FirstName",
    "City",
    "Odometer",
    "Address",
    "CustNo",
    "LastName",
    "Zip"
  ],
  "properties": {
    "Zip": {
      "type": "string",
      "description": "user's zip code"
    },
    "Email": {
      "type": "string",
      "description": "user's email address"
    },
    "Address": {
      "type": "string",
      "description": "user's address"
    },
    "FirstName": {
      "type": "string",
      "description": "user's first name"
    },
    "CellPhone": {
      "type": "string",
      "description": "user's cell phone number"
    },
    "Odometer": {
      "type": "number",
      "description": "user's vehicle odometer reading"
    },
    "Make": {
      "type": "string",
      "description": "user's vehicle make"
    },
    "City": {
      "type": "string",
      "description": "user's city"
    },
    "CustNo": {
      "type": "string",
      "description": "user's customer Id number"
    },
    "State": {
      "type": "string",
      "description": "user's state"
    },
    "Model": {
      "type": "string",
      "description": "user's vehicle model"
    },
    "VIN": {
      "type": "string",
      "description": "user's vehicle vin"
    },
    "LastName": {
      "type": "string",
      "description": "user's last name"
    }
  }
}
a
Thanks for the follow-up, @bohraz. I'll get back to you soon.
### Answer Your JSON schema setup is correct for mapping dynamic variables, as long as each required property (such as "CustNo") matches a dynamic variable set in the conversation context before the function call [(1) ]() . If the property name in the schema is "CustNo", then the dynamic variable must also be named "CustNo" (case-sensitive) for automatic injection to work . If you’re still getting errors about missing fields, possible issues include: - The dynamic variable "CustNo" is not set (or is empty) at the time the function is called. - The dynamic variable is set with a different name or casing than in your schema. - The value for "CustNo" is not being captured earlier in your workflow. Double-check that all required dynamic variables are set and populated in the conversation flow before the custom function executes .
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
b
@AI Evy the value for CustNo is definitely being caught, because it is a requirement as part of an equation for an earlier transition
a
Thanks for the follow-up, @bohraz. I'll get back to you soon.
### Answer If you see the value for CustNo being captured earlier (e.g., used in an equation for a transition) , but it isn't making it into your custom function call, the most common causes are: - The dynamic variable name must match the JSON schema property exactly, including case—so "CustNo" in both places [(1) ]() [(2) ]() . - The variable must be set as a string in the dynamic variable context before the function is triggered [(2) ]() [(3) ]() . - If the prompt or tool configuration doesn't reference the variable by the exact name, or if the tool isn't set up to use it, the value may not be injected—even if it appears in the data tab [(3) ]() . Check these points: 1. Confirm that "CustNo" appears in the dynamic variable context as a string (not a number or other type) before the function runs [(2) ]() [(3) ]() . 2. Verify your prompt or tool references "CustNo" exactly (case-sensitive) . 3. Make sure the correct tool/function is selected in the flow and that there are no typos or mismatches in naming [(3) ]() . If all of these are correct and it's still not mapping, review your outbound API payload and ensure that the dynamic variable is present and populated at the right step .
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[3] dynamic variables are not being used even though in data tab it was captured](https://discord.com/channels/1186424376300679209/1380529470468919320) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.