I’m connecting my Bubble to an app that uses a return header via a 308 redirect on their API. Using the API connector I can’t grab these headers, despite having ‘Capture response headers’ enabled - I get a ‘416 Requested Range Not Satisfiable’ response.
In postman I can switch off ‘Automatically follow redirects’ in the Settings for that API call and this turns the 416 response into a 308 response, that includes the headers I need for the next step in an API sequence.
Like all other API calls, I am using the Bubble API Connector plugin for this action - are there any other methods I can use to capture this 308 response, to disable redirects and to grab the header response? I can’t see anyone else who’s managed to overcome this issue on here - hence asking for help.
(I’ve also asked the API source to change their way of working, to send the response as a JSON payload but I suspect they’ve set it up that way for a good reason.)
I have solved this by using the Toolbox plugin’s Server Script. It uses the outputs from that plugin to capture the 308 header response. It’s working but still some tweaking to ensure errors are handled properly.
Here’s an edited version of my script (for any future problem hunters).
const url = properties.keyvaluesobj['api_url'];
const apiToken = properties.keyvaluesobj['api_token'];
const payload = properties.keyvaluesobj['api_payload'];
if (!url) throw new Error('api_url is not defined or invalid');
if (!apiToken) throw new Error('api_token is not defined or invalid');
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json'
},
redirect: 'manual'
});
const headers = [...response.headers.entries()]; // Convert headers to array of key-value pairs
const locationHeader = response.headers.get('location'); // Extract location from header
return {
output1: response.status,
output2: locationHeader || 'Location header not found',
// outputlist1: headers // Return all headers for debugging
};
} catch (error) {
return { output1: "500", output2: '', output3: error.message };
}