Help

Re: Unable to make a GET request with body

5093 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Giacomo_Lanzi
5 - Automation Enthusiast
5 - Automation Enthusiast

I should make a GET request with body (I know, it’s strange, but this is what I have to do).

Here below my script:

let inputConfig = input.config();
let deliveryNote = inputConfig.deliveryNote; // array
let courier = inputConfig.corriere;          // array
let deliveryDate = inputConfig.dataRitiro;   // array
let token = inputConfig.token;               // string

let authToken = String("Bearer " + token);
var trackingHeaders = new Headers();
trackingHeaders.append("Authorization", authToken);
trackingHeaders.append("Content-Type","application/json");

var trackRaw = JSON.stringify({
	"deliveryNote": "2501461270",
	"courier": "DHL",
	"deliveryDate": "2022-05-05"
});
var trackReqOption = {
  method: 'GET',
  headers: trackingHeaders,
  body: trackRaw
}
await fetch("https://api.retelogisticastorage.it/api/externalServices/trackDelivery", trackReqOption)
  .then(response => response.json())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

The first few variables, should be used in the actual request’s body (trackRaw). In order to test, I set the body with static fields.
The token variable comes from a previous script.

Since I know that sending a GET request with body is an anomaly, I am asking you: am I doing this right? Airtable allows this kind of request?

The problem is: I always get this response:

"error"
Error {name: "TypeError"}
name: "TypeError"
9 Replies 9

How sure are you that you need to include a body with your GET request? Can you use url parameters instead?

Could there be an authentication issue?

  1. I am sure I need a body with that GET request, and I am very aware that it is strange
  2. Using url parameters doesn’t work
  3. Auth method is correct: using another endpoint with the same method gives no error

For reference, here the code from Postman, where I conducted the tests:

var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer ***");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "deliveryNote": "4714249116",
  "courier": "DHL",
  "deliveryDate": "2022-05-03"
});

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://api.retelogisticastorage.it/api/externalServices/trackDelivery", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Postman allows GET request to be sent with body and the code above works perfectly.
I tried using a POST request or to add parameters to url, it didn’t work. This is not the first time I had this kind of issue where the system refuses to send the GET request because of the body. That happens, for example, using custom app in Make/Integromat, but with the “generic request” module, I was able to pull the GET request with body.

Question would probably be: does Airtable script allow for a GET request to be sent with body?

Thanks for the clarification that you do need a body with the GET request and that you are able to do this successfully on a different platform. This forum gets people with a wide variety of experience and it can be hard to tell at first.

Airtable fetch requests do have limitations that other environment do not have. This is the first time I’ve heard of this use case, so I don’t know if this is another limitation or not. I suggest contacting Airtable support, but support will probably have to ask engineering for the actual answer.

Cool, I will contact support.
Thanks

Just FYI: GET requests with body are not supported.

Support answered me confirming that

Thank you so much for reporting back with your findings. Sorry it was not the answer that you were looking for.

Could you chain together a solution by using a post request to call a service that turns around and replaces the request as a get?

I already have a solution, this time it was more a search for optimisation. In my quest I discovered that this type of requests are very uncommon and mostly not supported.

Scenario is: e-commerce requests deliveries with API and fill a Base in Airtable to further track the delivery and send a message asking for a review, a couple days after the arriving of the shipment.
The GET requests is the one that returns the delivery statuses.

The solution for me was to use Make/Integromat (where I built all the above automation) and use a generic HTTP module. In fact, custom app in Make/Integromat, doesn’t support GET requests with body.

The scenario that checks every delivery and update the delivery status, uses a lot of operations. Scripting within Airtable would have been a great way to further optimise this part of the automation.

Operations_ACM
5 - Automation Enthusiast
5 - Automation Enthusiast

@Giacomo_Lanzi don't suppose you have had any luck with scripting for this? Secretly hopeful that with the time that has passed you may be able to do this without previous limitations? 🤞

Giacomo_Lanzi
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi @Operations_ACM

I got no luck and since I made that question, I also changed the service I use, so don't need to make a GET request with body anymore.