My variable is not fetched in the workflow
# support
r
I am trying to pass the variable {{Name}} through API request in workflow but I am not getting the variable value I am returning the following response of external API requested : { "Name": "Ramy", } and the following is the JSON code of the workflow containing the API request details : { "name": "cGacela bland Production 20240207", "nodes": [ { "name": "start_node", "type": "start", "metadata": { "position": { "x": 181.55967712402344, "y": 107.2077579498291 } } }, { "name": "say_1744321833350", "type": "say", "metadata": { "position": { "x": 80.05967712402344, "y": 599.8674926757812 } }, "prompt": "", "exact": "hello {{ Name }}" }, { "name": "apiRequest_1744499802069", "type": "apiRequest", "metadata": { "position": { "x": 80.05967712402344, "y": 273.7540168762207 } }, "method": "POST", "url": "https://hook.eu2.make.com/47datqc8j2xtfsqgc5sgm7poobuv3out", "headers": { "type": "object", "properties": {} }, "body": { "type": "object", "properties": { "customerID": { "type": "string", "description": "", "value": "+18603215551" } } }, "output": { "type": "object", "properties": { "Name": { "type": "string", "description": "name of the customer", "target": "" } } }, "mode": "blocking", "hooks": [] } ], "edges": [ { "from": "apiRequest_1744499802069", "to": "say_1744321833350" }, { "from": "start_node", "to": "apiRequest_1744499802069" } ] }
v
Hi there! 👋 I see you're having trouble with the
{{Name}}
variable not being fetched in your workflow. I noticed that while you're trying to access the variable, I can't help with the exact runtime behavior without logs, but I can definitely help with the configuration issue I spotted in your workflow JSON! Looking at your workflow configuration, I found the issue! In your
apiRequest_1744499802069
node, the
target
field is empty in the output properties. This is critical because the target field specifies the name of the output variable that will store the extracted value. According to the [API Request Task documentation](https://docs.vapi.ai/workflows/tasks/api-request), when defining output values to extract data from an API's JSON response, you need to configure three properties: - **Key**: The key within the JSON payload to extract (which you have as "Name") - **Target**: The name of the output variable for the extracted value (which is currently empty) - **Type**: The data type of the extracted value (which you have as "string") To fix this issue, you should update your workflow JSON by adding a value to the
target
field. For example:
Copy code
json
"output": {
  "type": "object",
  "properties": {
    "Name": {
      "type": "string",
      "description": "name of the customer",
      "target": "Name"  // Add this value
    }
  }
}
The
target
field should match the variable name you want to use in subsequent nodes, which in your case is "Name" since you're trying to use
{{ Name }}
in your say node. Additionally, make sure that: 1. The API is actually returning the expected JSON structure with the "Name" field 2. The variable name in your say node matches exactly (including case sensitivity) with the target variable name Is there anything else you'd like me to help with regarding your Vapi workflow? Source: - [API Request Task](https://docs.vapi.ai/workflows/tasks/api-request)
r
How to define the expected JSON structure of the returning API @Vapi Support Bot
v
Hi there! 👋 I'd be happy to explain how to define the expected JSON structure of the returning API in Vapi workflows! To define the expected JSON structure of the returning API in Vapi workflows, you need to configure the output properties in your API request node. Here's how: ## Basic Configuration According to the [API Request Task documentation](https://docs.vapi.ai/workflows/tasks/api-request), you need to configure the Output Values section with three key properties: 1. **Key**: The key within the JSON payload to extract 2. **Target**: The name of the output variable for the extracted value 3. **Type**: The data type of the extracted value (string, number, boolean, etc.) For example, in your workflow JSON, you should update the output section like this:
Copy code
json
"output": {
  "type": "object",
  "properties": {
    "Name": {
      "type": "string",
      "description": "name of the customer",
      "target": "Name"  // This is what was missing in your configuration
    }
  }
}
## Expected JSON Format The expected JSON structure for API responses in Vapi should follow this format:
Copy code
json
{
  "results": [
    {
      "toolCallId": "X", 
      "result": "Y"
    }
  ]
}
Where: - The
result
field should be a valid JSON string without line breaks - If you need to include line breaks in your response, use the escape sequence
\\n
For example:
Copy code
json
{
  "results": [
    {
      "toolCallId": "call_EPeJcpGomST5L4XEwR85tCy4",
      "result": "Unfortunately, that time isn't available. How about one of these instead?\\n9:00 AM\\n12:30 PM\\n2:30 PM"
    }
  ]
}
## Using JSON Schema Validation For more complex structures, you can use JSON schema validation to define the expected structure: 1. Use the
structuredDataSchema
property within the
analysisPlan
of the
assistantOverrides
object: ```json "assistantOverrides": { "analysisPlan": { "structuredDataSchema": { "type": "object", "properties": {
"field1": { "type": "string" }, "field2": { "type": "number" } }, "required": ["field1", "field2"] }, "structuredDataPrompt": "Extract all of the information needed for the desired properties of the call." } } ``` This schema specifies that the expected JSON structure is an object with two fields:
field1
(a string) and
field2
(a number), both of which are required. ## Important Formatting Notes - JSON responses need to be stringified - The response should be a string without line breaks - Line breaks within strings should be represented by the escape sequence
\\n
- Avoid nested JSON in the
result
field Would you like me to explain any specific aspect of defining the expected JSON structure in more detail? Sources: - [API Request Task](https://docs.vapi.ai/workflows/tasks/api-request) - [Discord Thread](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1334658296291921920) - [Discord Thread](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1329542939160084624) - [Discord Thread](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1336548894896816222)
r
Are yu sure of your result you want me to use the same Server Response JSON format of Custom tools to return the variable values of API request response in workflows ? @Vapi Support Bot
v
Hi there! 👋 I understand you're asking for confirmation about the JSON format for API responses in workflows. Based on the information I have, I can't definitively confirm whether you must use exactly the same Server Response JSON format as Custom tools in all scenarios. However, I can tell you what format is expected for API responses in Vapi workflows. According to the documentation I found, the expected JSON structure for API responses in Vapi workflows should follow this format:
Copy code
json
{
  "results": [
    {
      "toolCallId": "X", 
      "result": "Y"
    }
  ]
}
Where: - The
result
field should be a valid JSON string without line breaks - If you need to include line breaks, use the escape sequence
\\n
This format is mentioned in several sources, including [Discord discussions](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1329542939160084624) where it's specified that "the expected JSON structure should be a string format, such as `{\"results\": [{\"toolCallId\": \"X\", \"result\": \"Y\"}]}`" and that "the
result
field should be a valid JSON string without line breaks." Would you like me to provide more details about any specific aspect of the API response format? Source: - [Discord Thread](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1329542939160084624)
r
so the result field should contain the variable of workflow API request ? @Vapi Support Bot
v
Hi there! 👋 Based on the information I have, I can't definitively confirm whether the
result
field should specifically contain the variable from your workflow API request. What I can tell you is that according to the documentation, the expected JSON structure for API responses in Vapi workflows should follow this format:
Copy code
json
{
  "results": [
    {
      "toolCallId": "X", 
      "result": "Y"
    }
  ]
}
Where the
result
field should be a valid JSON string without line breaks. This is mentioned in [Discord discussions](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1329542939160084624) where it's specified that "the expected JSON structure should be a string format" and "the
result
field should be a valid JSON string without line breaks." The documentation doesn't explicitly state that the variable from your workflow API request must be placed in the
result
field, but this is the standard format for returning data from API calls in Vapi workflows. Is there something specific about your use case that you're trying to implement with the API request variable? Source: - [Discord Thread](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1329542939160084624)
r
@User
k
Hey! To help track down this issue, could you share: - The call ID - What response you expected to get - What response you actually got instead This would really help us figure out what went wrong!