TypebotT
Typebotโ€ข2y ago
JohnSmith

ChatGPT Function Calling

Hi all, I'm trying to use a chatGPT to function call an API to get data when a user enters a postcode - I've set up the function in the AssistantsAPI and in the prompt so its using the function when the postcode is inputted.

I'm having trouble with calling the API using the function and returning the response, I've tested the API keys and such and they are working - however when in typebot it returns:

"status": 500, "body": { "message": "400 1 validation error for Request\nbody -> tool_outputs -> 0 -> output\n field required (type=value_error.missing)", "code": "INTERNAL_SERVER_ERROR"

This is my code in the function:

' const baseUrl = https://epc.opendatacommunities.org/api/v1/domestic/search?postcode=BH10;
const encodedAPI = "BASE64 Encode"; // Pre-encoded API key

const requestOptions = {
method: "GET",
headers: {
Accept: "application/json",
Authorization: "Basic" + encodedAPI
}
};

try {
const response = await fetch(baseUrl, requestOptions);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log(data); // Log the response data
return data; // Return the parsed JSON data
} catch (error) {
console.error("Error fetching data:", error);
throw error; // Re-throw the error for handling outside the function
} '
Was this page helpful?