I am experiencing an issue while making an API call in my Bubble application.
The error message I encountered is as follows:
Plugin server side action console output
START RequestId: e3651254-a696-4495-9d1e-8626e7f14884
Version: $LATEST
2023-11-03T03:21:32.430Z
e3651254-a696-4495-9d1e-8626e7f14884
ERROR Erro ao processar a solicitação: TypeError: Request with GET/HEAD method cannot have body.
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at async fetchEtiquetas (eval at build_function (/var/task/util/util_harness.js:38:12), <anonymous>:34:22)
at async /var/task/plugin_api_v4_alpha.js:198:29
at async harness (/var/task/harness.js:115:15)
at async /var/task/harness.js:154:64
at async withGlobalHandlers (/var/task/harness.js:66:10)
at async Runtime.myHandler [as handler] (/var/task/harness.js:154:10)
END RequestId: e3651254-a696-4495-9d1e-8626e7f14884
REPORT RequestId: e3651254-a696-4495-9d1e-8626e7f14884
Duration: 620.61 ms
Billed Duration: 621 ms
Memory Size: 128 MB
Max Memory Used: 97 MB
I am attempting to make a GET request that requires a JSON body, and it seems like the Bubble platform is throwing a “Request with GET/HEAD method cannot have body” error. This limitation is preventing me from accessing the required data through the API.
I would appreciate your assistance in resolving this issue or providing guidance on how to work around it, as making a GET request with a JSON body is essential for my application’s functionality.
You should consoder sending the data as query string
Thanks for the response. However, the third-party development company requires sending a JSON body in the GET request. I managed to do it via Postman, but not with Bubble. I’m trying to develop a plugin, but I’m still getting this error. Below is the JSON from the plugin and the editor:
async function fetchEtiquetas(properties, context) {
try {
const formato = properties.formato;
const apiKey = properties.authorization;
const idsVendas = properties.idsVendas;
// Codifique o JSON como uma string
const jsonData = JSON.stringify({
idsVendas: idsVendas
});
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", `Bearer ${apiKey}`);
myHeaders.append("Cookie", "PHPSESSID=e7hud62kcmjil0gb3fgv08n2ie");
const requestOptions = {
method: 'GET',
headers: myHeaders,
body: jsonData, // Coloque o JSON no corpo da solicitação
redirect: 'follow'
};
const url = `https://www.bling.com.br/Api/v3/logisticas/etiquetas?formato=${formato}`;
const response = await fetch(url, requestOptions);
if (response.ok) {
const result = await response.json();
if (result.data && result.data.length > 0) {
const link = result.data[0].link;
return link;
} else {
console.error('Nenhum resultado encontrado');
}
} else {
console.error('Erro na requisição:', response.status, response.statusText);
}
} catch (error) {
console.error(‘Erro ao processar a solicitação:’, error);
}
}
as you can see from the error, and easily search on internet, fetch does not support a body in GET requests.
If you need it you may want to search for another http client library that you can import in your server action.
1 Like