Reputation: 75
I try to authentificate myself in my account for DirectEnergie using google app script. When I put the request on POSTMAN with Chrome it works, but when I try to as followed, it returns me the HTML of the first page without the authentification.
function getSumParr(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
url = "https://particuliers.direct-energie.com/mon-espace-client/?tx_deauthentification[login]=login&tx_deauthentification[password]=motdepasse&tx_deauthentification[form_valid]=1&tx_deauthentification[redirect_url]= "
var resultat = UrlFetchApp.fetch(url);
Logger.log(resultat);
}
When I follow the history of the request with postman, I have this : Response [303], Response [307]
Anybody has an idea on how to figure it out ?
Upvotes: 0
Views: 191
Reputation: 6791
You may want to check this tutorial about GET and POST Requests in Google Apps Script:
With Google Apps Script, you can easily create a Web App that serves HTML, JSON, XML or plain text output using the HTML service. When published as an app, the script gets a public URL that can be called using either GET or POST requests with parameters.
Here is their code snippet:
function testPOST() {
var url = ScriptApp.getService().getUrl();
var payload =
{
"name" : "labnol",
"blog" : "ctrlq",
"type" : "post",
};
var options =
{
"method" : "POST",
"payload" : payload,
"followRedirects" : true,
"muteHttpExceptions": true
};
var result = UrlFetchApp.fetch(url, options);
if (result.getResponseCode() == 200) {
var params = JSON.parse(result.getContentText());
Logger.log(params.name);
Logger.log(params.blog);
}
}
This sample also follows the documentation on how to make a request to fetch a URL using optional advanced parameters.
Hope this helps.
Upvotes: 1