Cannot pass Dynamic Variables via requests
# support
c
a
Heychukarslan Thank you for creating the ticket! A member of our team will reach out to you shortly.
v
@chukarslan Certainly! To pass a dynamic variable like
{{questions}}
from your frontend to the VAPI assistant, you'll need to ensure that your frontend is correctly capturing the variable and then sending it as part of the API request to VAPI. Here's a simplified example of how you might implement this: 1. Capture the
{{questions}}
variable in your frontend code. 2. Make an API request to VAPI and include the
{{questions}}
variable in the request body or as a query parameter. For instance, if you're using JavaScript and AJAX to make the API call, it might look something like this:
Copy code
javascript
// Assume `questions` is the variable you want to pass to the VAPI assistant
let questions = getQuestionsFromUserInput(); // Your function to get the questions

// Prepare the API request
let apiRequestData = {
  type: "assistant-request",
  call: {
    // ... other call object properties
    questions: questions // Add the dynamic variable here
  }
};

// Make the API call
$.ajax({
  url: 'https://api.yourvapiendpoint.com/call', // Replace with your actual VAPI endpoint
  type: 'POST',
  contentType: 'application/json',
  data: JSON.stringify(apiRequestData),
  success: function(response) {
    // Handle success
    console.log('Questions sent to VAPI assistant:', questions);
  },
  error: function(error) {
    // Handle error
    console.error('Error sending questions to VAPI assistant:', error);
  }
});
Make sure that your backend is configured to accept this variable and pass it to the VAPI assistant accordingly. If you're still having trouble, please ensure that: - The variable name in the API request matches what the VAPI assistant expects. - The variable is being correctly serialized and included in the API request. - Your VAPI assistant is configured to handle dynamic variables passed in the request. If you've checked all of these and the issue persists, please ask support for more info on this.
You can continue this conversation by mentioning me in the message.
Got it. Tagging @User for additional help.
c
Any help 😦 @User
s
Hey @chukarslan To help track down this issue, could you share: - The call ID This would really help me figure out what went wrong!
@chukarslan a gentle reminder to continue this thread.
c
Hi Shubham, it’s all resolved thank you for your assistance! Turns out I wasn’t including the braces around the “question”
k
Sounds, good.
2 Views