Kavish
12/14/2024, 5:09 PMVapi
12/14/2024, 5:12 PMfetch
(built into modern browsers) or axios
to send HTTP requests. Here's a basic example using fetch
to make a GET request:
typescript
// Define the URL and any necessary headers
const url = 'https://api.vapi.ai/call';
const headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
};
// Define the async function to make the call
async function makeWebCall() {
try {
const response = await fetch(url, {
method: 'GET', // or 'POST' if you are sending data
headers: headers
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// Parse the JSON response
const data = await response.json();
console.log(data);
// Handle the data from the response
} catch (error) {
console.error('There was a problem with the fetch operation:', error);
}
}
// Call the function
makeWebCall();
Replace 'YOUR_ACCESS_TOKEN'
with your actual access token. If you're making a POST request or need to send data, you would include a body
property in the options object passed to fetch
.
Remember to handle the response and errors appropriately for your application's needs. If you're working in a Node.js environment, you'll need to use a library like node-fetch
or axios
since fetch
is not natively available in Node.js.Vapi
12/14/2024, 5:12 PMShubham Bajaj
01/05/2025, 9:37 PMKavish
01/06/2025, 1:46 PMShubham Bajaj
01/09/2025, 12:36 PM