Problem via calling REST API Magento 2 from Google App Script - ROBOTS Exception

299 Views Asked by At

Can we do something like this using Google App Script? -> Pushing orders into magento 2 using REST API, order will be fetched by Google Sheet. -> When I try to do it gives

<head>
<meta name="robots" content="noindex,nofollow">
<script src="/_Incapsula_Resource?SWJIYLWA=5074a744e2e3d891814e9a2dace20bd4,719d34d31c8e3a6e6fffd425f7e032f3">
</script>
<body>
</body></html>

Although when I use the authenticate API it runs well and returns the token, I am using the token in the next GET Request (to test I using REST API for product fetch). It looks like Magento is considering Google App Script as a bot.

This is my code.

function myFunction() {

var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();

var url1 = "https://www.traditionalfood...";

var options1 = {
'headers': { 'Content-Type': "application/json", 'Accept':"application/json"},
'method': "post",
'payload' : JSON.stringify({"username": "*****", "password":"********"})
};
var response1 = UrlFetchApp.fetch(url1, options1);

var json1 = response1.getContentText();
Logger.log("###################"+json1.replace(/\"+/g,"")); /// this request is fine, returning the token

var url2 = "http://www.traditionalfoods... Cedar Gum";

var options2 = {
'headers': {
'Content-Type': "application/json",
'Accept': "application/json",
'Authorization': "Bearer "+json1.replace(/\"+/g,""),
'method': "get"
}
};

var response2 = UrlFetchApp.fetch(url2, options2);

var json2 = response2.getContentText(); /// Here it is giving the response above mentioned.
Logger.log("###################"+json2);

}
0

There are 0 best solutions below