https://retellai.com/?utm_source=discord&utm_medium=seo logo
i am trying to use dynamic variable in call transf...
# ❓・ai-evy-support
k
@AI Evy i am trying to use dynamic variable in call transfer function , can i call another function and get the phone number via n8n and use that as dynamic variable
a
Thanks for tagging me @kartik. I'll look through relevant sources and get back to you shortly.
### Answer --- Yes, you can use dynamic variables for the transfer destination phone number in the Call Transfer Node. [(1) ]() Here's the approach: 1. Set up a custom function that calls your n8n webhook to fetch the phone number 2. Store the result in a dynamic variable (e.g.,
{{transfer_target}}
) 3. Configure the Call Transfer Node to use that dynamic variable as the transfer destination In the Call Transfer Node, you can set the transfer number to a dynamic variable that gets substituted at runtime. Key points: - The phone number should be in E.164 format (e.g.,
+12137771234
) - Dynamic variables work in tool configurations including custom function URLs and tool descriptions [(2) ]() - You can update the dynamic variable during the call flow before triggering the transfer [(3) ]() So your flow would be: 1. Call your n8n custom function to retrieve the phone number 2. Store the returned number in a dynamic variable 3. The Call Transfer Node uses
{{transfer_target}}
(or whatever you name it) as the destination This allows the transfer number to be different for every call based on your n8n logic. ---
​ To learn more, see the sources I considered: [[1] Call Transfer Node](https://docs.retellai.com/build/conversation-flow/call-transfer-node) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[3] Routing Calls to Dynamic Number](https://discord.com/channels/1186424376300679209/1346575575963144273) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer I don't see an image or screenshot of your n8n workflow in your message—it appears the attachment didn't come through. Could you re-share the workflow screenshot or describe the setup? I'd be happy to review it once I can see the details. In the meantime, based on the sources, the key format for returning dynamic variables from n8n to Retell depends on whether it's an inbound or outbound call: [(1) ]() For outbound calls (via custom function response) :
Copy code
json
{
  "retell_llm_dynamic_variables": {
    "transfer_target": "+12137771234"
  }
}
[(2) ]() For inbound calls (webhook response) :
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
      "transfer_target": "+12137771234"
    }
  }
}
[(1) ]() Once you share your workflow, I can confirm if the structure is correct for your use case.
​ To learn more, see the sources I considered: [[1] Dynamic Variable and n8n](https://discord.com/channels/1186424376300679209/1357551375416037469) [[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.
k
do i need agent id in returning variables , and i am using webhook and respond to webhook
@AI Evy do i need agent id in returning variables , and i am using webhook and respond to webhook
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer --- No, you do not need to include the agent ID when returning dynamic variables via the inbound webhook—it's optional. [(1) ]() For an inbound call webhook response, all fields are optional. Here's the expected format:
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
      "transfer_target": "+12137771234"
    }
  }
}
The
override_agent_id
field is only needed if you want to change which agent handles the call. If you already have an inbound agent set on the phone number and just want to pass dynamic variables, you can omit it entirely. Optional fields you can include: -
override_agent_id
– only if you want to switch agents -
override_agent_version
– only if you want a specific agent version -
dynamic_variables
– your custom variables -
metadata
– additional call metadata -
agent_override
– to override specific agent settings So your n8n "Respond to Webhook" node just needs to return the
call_inbound.dynamic_variables
object with your phone number variable. ---
​ To learn more, see the sources I considered: [[1] Inbound webhook](https://docs.retellai.com/features/inbound-call-webhook) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
@AI Evy this is the tool result of function that i am using mid call to retrieve the agent phone number- Tool Result tool_call_id: 2c2101e26a68d0e1 {"call_inbound":{"dynamic_variables":{"agent_phone":"+917508966856"}}} and this is the error i get when in transfer function- tool_call_id: ab1f6c6bc76b17d6 {"status":"Error transferring: Transfer destination number is a dynamic variable that's not populated."}
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer --- The issue is the response format you're returning from your custom function. The
call_inbound
structure is specifically for the inbound webhook response when a call first comes in—not for mid-call custom function responses. [(1) ]() For a custom function called mid-call, the response format should be different. Custom functions return data that the LLM can use, but to update dynamic variables mid-call, you need to return the value directly so it can be stored. The problem: Your function returns:
Copy code
json
{"call_inbound":{"dynamic_variables":{"agent_phone":"+917508966856"}}}
This nested structure isn't being parsed correctly to populate the
{{agent_phone}}
variable for the transfer node. Suggested approach: 1. Have your custom function return the phone number directly:
Copy code
json
{
  "agent_phone": "+917508966856"
}
2. In your conversation flow, after calling the custom function, you need to extract and store that returned value into a dynamic variable before the transfer node uses it. 3. Make sure the transfer node is configured to use
{{agent_phone}}
and that this variable is properly set before the transfer is triggered. The error
"Transfer destination number is a dynamic variable that's not populated"
confirms that
{{agent_phone}}
isn't being recognized as set at the time of transfer. [(2) ]() Check out these potentially useful sources for more details on dynamic variable handling: - [Dynamic Variables]() Would you like a general answer on mid-call variable updates, or can you share how your conversation flow stores the function result?
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[2] Dynamic Variables](https://discord.com/channels/1186424376300679209/1340177140204699649) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
this is the json of the function that is extracting the agent phone from n8n , change this as well to receive the input
@AI Evy this is the json of the function that is extracting the agent phone from n8n , change this as well to receive the input-{ "type": "object", "properties": { "call_inbound": { "type": "object", "properties": { "dynamic_variables": { "type": "object", "properties": { "agent_phone": { "type": "string", "description": "Phone number to transfer the call to" } }, "required": [ "agent_phone" ] } }, "required": [ "dynamic_variables" ] } }, "required": [ "call_inbound" ] }
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer The
call_inbound
structure you're using is specifically for inbound webhook responses when a call first arrives—not for mid-call custom function responses. [(1) ]() For a custom function that returns data mid-call, you should simplify your JSON schema to return the phone number directly:
Copy code
json
{
  "type": "object",
  "properties": {
    "agent_phone": {
      "type": "string",
      "description": "Phone number to transfer the call to"
    }
  },
  "required": [
    "agent_phone"
  ]
}
And your n8n webhook should return:
Copy code
json
{
  "agent_phone": "+917508966856"
}
The
call_inbound.dynamic_variables
format is used when responding to the inbound webhook (set via
inbound_webhook_url
on the phone number) to inject variables at call start. , [(2) ]() , [(3) ]() For outbound calls, dynamic variables are passed via
retell_llm_dynamic_variables
in the API request. [(4) ]() , [(5) ]() Mid-call custom functions should return the data directly so your conversation flow can use it.
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
@AI Evy this is agent phone fetching function result [{"agent_phone":"+917508966856"},{"agent_phone":"+917508966856"},{"agent_phone":"+917508966856"},{"agent_phone":"+917508966856"}] and this is transfer call result {"status":"Error transferring: Transfer destination number is a dynamic variable that's not populated."}
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer --- The issue is that your n8n webhook is returning an array instead of a **single object**:
Copy code
json
[{"agent_phone":"+917508966856"},{"agent_phone":"+917508966856"},{"agent_phone":"+917508966856"},{"agent_phone":"+917508966856"}]
Custom function responses are converted to string before being processed, and this array format isn't being properly extracted into your dynamic variable. [(1) ]() Fix your n8n workflow to return a single object:
Copy code
json
{"agent_phone":"+917508966856"}
Additionally, make sure you're using the response variables feature in your custom function to extract the value. You need to configure "Set response variables" to extract
agent_phone
from the response and save it as a dynamic variable. Also, based on a similar issue, ensure the dynamic variable is referenced in the description of your custom function parameters using the
{{variable_name}}
syntax (e.g.,
{{agent_phone}}
) . [(2) ]() Steps to verify: 1. Update n8n to return a single object, not an array 2. In your custom function node, configure response variables to extract
agent_phone
and store it 3. Ensure the transfer node uses
{{agent_phone}}
as the destination [(3) ]()
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Dynamic Variable is not sending via custom function.](https://discord.com/channels/1186424376300679209/1430715756030722149) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
@AI Evy explain all three steps in detail
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer --- ### Step 1: Update n8n to return a single object, not an array Your current n8n response returns:
Copy code
json
[{"agent_phone":"+917508966856"},{"agent_phone":"+917508966856"},...]
This is an array. Custom function responses are converted to string before sending to the LLM for processing, and an array format won't properly populate your dynamic variable. [(1) ]() In your n8n workflow, modify your response node to return a **single object**:
Copy code
json
{"agent_phone":"+917508966856"}
If you're getting multiple results from a previous node, use an n8n "Item Lists" or "Code" node to select just the first item before returning it. --- ### Step 2: Configure response variables to extract and store the value In your custom function configuration, use the "Set response variables" feature to extract the phone number from the API response and save it as a dynamic variable. [(2) ]() , [(1) ]() For example, if your response body is:
Copy code
json
{
  "agent_phone": "+917508966856"
}
You would configure the response variable extraction to map
agent_phone
from the response to a dynamic variable (e.g.,
{{agent_phone}}
) . This allows you to reference it later using
{{agent_phone}}
. [(2) ]() , [(1) ]() --- ### Step 3: Use the dynamic variable in the transfer node Dynamic variables can be used in transfer call phone numbers. [(3) ]() In your Call Transfer Node, set the transfer destination to
{{agent_phone}}
. This placeholder will be substituted at runtime with the value extracted from your custom function response. Make sure: - The custom function that fetches the phone number runs before the transfer node in your conversation flow - The phone number is in proper format (e.g.,
+917508966856
) - The variable name matches exactly between your response variable configuration and the transfer node ---
​ 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.
Thanks for the follow-up, @kartik. I'll get back to you soon.
k
@AI Evy is this correct json in agent phonr extraction function { "type": "object", "properties": { "pets": { "type": "boolean", "description": "Whether caller has pets." }, "parking": { "type": "boolean", "description": "Whether caller needs parking." }, "amenities": { "type": "array", "items": { "type": "string" } }, "city": { "type": "string" }, "bathrooms": { "type": "integer" }, "bedrooms": { "type": "integer", "description": "Number of bedrooms." }, "movein_date": { "type": "string", "description": "Move-in date requested by caller." }, "caller_phone": { "type": "string" }, "dialed_number": { "type": "string" }, "price": { "type": "string" }, "caller_email": { "type": "string" }, "lead_type": { "type": "string", "description": "What caller is interested in.", "enum": [ "apartment", "room", "parking", "sales", "landlord", "property_management", "other" ] }, "location_preference": { "type": "array", "items": { "type": "string" } }, "budget": { "type": "string" } }, "required": [ "city", "budget", "caller_phone", "caller_email", "amenities", "location_preference", "dialed_number" ] }
a
### Answer --- The JSON schema you shared appears to be for a lead qualification or **intake function**—not specifically for extracting an agent phone number for call transfer. If your goal is to fetch a phone number from n8n to use in a transfer, your custom function schema should be much simpler. [(1) ]() For an agent phone extraction function, use:
Copy code
json
{
  "type": "object",
  "properties": {
    "agent_phone": {
      "type": "string",
      "description": "Phone number to transfer the call to"
    }
  },
  "required": [
    "agent_phone"
  ]
}
The schema you shared includes many unrelated fields (
pets
,
parking
,
amenities
,
city
, etc.) which are useful for collecting lead information but won't help extract a transfer phone number. Key points: - Custom function parameters define what the LLM sends to your endpoint - If you only need to fetch a phone number, keep the schema minimal - Your n8n endpoint should return a single object like
{"agent_phone": "+917508966856"}
- Then configure response variables to extract
agent_phone
and store it as a dynamic variable for use in the transfer node [(2) ]() If you're using this function for both lead capture and phone extraction, you may want to split them into two separate functions for clarity.
​ 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.
k
@AI Evy i mean this
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
k
@AI Evy i mean this { "type": "object", "properties": { "agent_phone": { "type": "string", "description": "Phone number to transfer the call to" } }, "required": [ "agent_phone" ] }
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer I don't see an image or attachment in your message—it appears the screenshot didn't come through. Could you re-share the image or describe what you're asking about? Based on the thread context, if you're asking about the JSON schema for your agent phone extraction function, here's the correct format for a simple phone number retrieval:
Copy code
json
{
  "type": "object",
  "properties": {
    "agent_phone": {
      "type": "string",
      "description": "Phone number to transfer the call to"
    }
  },
  "required": [
    "agent_phone"
  ]
}
[(1) ]() And your n8n should return a single object (not an array) :
Copy code
json
{
  "agent_phone": "+917508966856"
}
Then use response variables in your custom function to extract
agent_phone
from the response and store it as a dynamic variable for use in the transfer node. , [(2) ]() Please re-share what you meant to show and I can review it.
​ 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.
### Answer Yes, that JSON schema is correct for a custom function that fetches an agent phone number. [(1) ]()
Copy code
json
{
  "type": "object",
  "properties": {
    "agent_phone": {
      "type": "string",
      "description": "Phone number to transfer the call to"
    }
  },
  "required": [
    "agent_phone"
  ]
}
This follows the proper JSON schema format for custom function parameters. , [(2) ]() Next steps to complete your setup: 1. Make sure your n8n webhook returns a single object (not an array) :
Copy code
json
{"agent_phone": "+917508966856"}
[(1) ]() 2. Configure response variables in your custom function to extract
agent_phone
from the response and save it as a dynamic variable for later use. , [(2) ]() 3. In your Call Transfer Node, use
{{agent_phone}}
as the transfer destination. The schema defines what the LLM sends to your endpoint, and the response variables feature extracts data from what your endpoint returns. [(1) ]() , [(2) ]()
​ 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) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
extraction function tool result - {"agent_phone":"+917508966856"} and transfer function tool result - {"status":"Error transferring: Transfer destination number is a dynamic variable that's not populated."}
@AI Evy extraction function tool result - {"agent_phone":"+917508966856"} and transfer function tool result - {"status":"Error transferring: Transfer destination number is a dynamic variable that's not populated."}
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer --- Your extraction function is returning the correct format, but the dynamic variable isn't being stored before the transfer node tries to use it. Based on a similar issue, you need to reference the dynamic variable in the description field of your custom function parameters using the
{{variable_name}}
syntax. [(1) ]() Try updating your custom function parameter description to include the variable reference:
Copy code
json
{
  "type": "object",
  "properties": {
    "agent_phone": {
      "type": "string",
      "description": "Use this as the agent phone: {{agent_phone}}"
    }
  },
  "required": [
    "agent_phone"
  ]
}
Additionally, ensure you have configured "Set response variables" in your custom function node to extract
agent_phone
from the response and save it as a dynamic variable. The response from your endpoint needs to be explicitly mapped to a variable that persists for use in subsequent nodes. Key checklist: 1. In your custom function, configure response variables to extract
agent_phone
and store it 2. Include
{{agent_phone}}
in the description field of your function parameters 3. Verify the variable is extracted by checking the call history data tab [(2) ]() 4. Ensure the transfer node runs after the extraction function completes and the variable is stored
​ To learn more, see the sources I considered: [[1] Dynamic Variable is not sending via custom function.](https://discord.com/channels/1186424376300679209/1430715756030722149) [[2] dynamic variables](https://discord.com/channels/1186424376300679209/1392149155660431380) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
@AI Evy transfer to in transfer function is {{agent_phone}}
a
Thanks for the follow-up, @kartik. I'll get back to you soon.
### Answer --- Since you have
{{agent_phone}}
set in your transfer function and your extraction function is returning
{"agent_phone":"+917508966856"}
, the issue is likely that the variable isn't being saved/extracted from the response before the transfer executes. Based on a similar reported issue, you need to include the dynamic variable reference
{{agent_phone}}
in the description field of your custom function parameters. [(1) ]() Update your extraction function description like this:
Copy code
json
{
  "type": "object",
  "properties": {
    "agent_phone": {
      "type": "string",
      "description": "Use this as the agent phone: {{agent_phone}}"
    }
  },
  "required": [
    "agent_phone"
  ]
}
Additionally: - Make sure you have configured "Set response variables" in your custom function node to explicitly extract
agent_phone
from the response and store it as a dynamic variable [(2) ]() - Verify in your call history logs that the variable is actually being extracted after the function runs [(1) ]() - Ensure the extraction function completes before the transfer node triggers The error
"Transfer destination number is a dynamic variable that's not populated"
confirms
{{agent_phone}}
isn't recognized as set at transfer time—even though your function returns the value, it may not be properly mapped to a stored dynamic variable. ---
​ To learn more, see the sources I considered: [[1] Dynamic Variable is not sending via custom function.](https://discord.com/channels/1186424376300679209/1430715756030722149) [[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.