I'm trying to automate an API request into Google spreadsheets using Apps Script, the GET request seems to work fine in python, but when I try to replicate the same request using UrlFetchApp.fetch
method it throws a 422 error, ignoring headers apparently.
Here is the working python code:
url = "https://api.granatum.com.br/v1/relatorios/fluxo_caixa?access_token={}".format(token)
r = requests.get(url = caixa, params= {'data_inicio' : '2018-01-01',
'data_fim' : '2022-02-01',
'regime':'caixa'})
But when I try to replicate it to Apps Script, it seems to ignore those parameters
var link = "https://api.granatum.com.br/v1/relatorios/fluxo_caixa?access_token=my_access_token";
headers = {
'data_inicio': '2020-01-01',
'data_fim': '2020-06-30',
'regime': 'caixa',
};
var options = {
"method" : "get",
"contentType":"application/json",
'headers': headers,
};
Logger.log(options);
var res = UrlFetchApp.fetch(link, options)
It throws the following error message:
Exception: Request failed for https://api.granatum.com.br returned code 422. Truncated server response: {"errors":{"data_inicio":["é obrigatório"],"data_fim":["é obrigatório"],"regime":["é obrigatório","inválido"]}} (use muteHttpExceptions option to examine full response)
Translating the response, it asks for those three parameters informed above, as if it haven't received them.