1

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);

}
1
  • I have found in several posts like this one : posible solution that you can avoid Incapsula by setting up the headers, especially the User-Agent header let me know if this worked for you. Commented Jul 28, 2020 at 1:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.