Jun 27, 2022 08:07 PM
Hi,
When I run the following in an individual script block on my Base it works without a hitch:
let table = base.getTable("SMS");
let view = table.getView("Real Clicks");
let query = await view.selectRecordsAsync({fields: ["Contact","Shortlink","URL","LinkID","Image"]});
var json_payload = [];
action_injection = {
'action': 'linkupdater'
};
json_payload.push(action_injection);
let individual_injection = {};
for (let record of query.records) {
let name = record.getCellValueAsString("Contact");
let shortlink = record.getCellValueAsString("Shortlink");
let URL = record.getCellValueAsString("URL");
let linkID = record.getCellValueAsString("LinkID");
let imageURL = record.getCellValue("Image");
individual_injection = {
'ID': record.id,
'Name': name,
'URL': URL,
'Shortlink' : shortlink,
'LinkID' : linkID
//'image' : imageURL[0]?.url //['url']
};
json_payload.push(individual_injection);
}
let response = await remoteFetchAsync('http://147.182.192.192/speech.php', {
method: 'POST',
body: JSON.stringify(json_payload),
headers: {
'Content-Type': 'application/json',
'Authorization' : 'Basic d2h5d29udHlvdWNvbm5lY3Q6Y2N1WSAxWWhkIDdsTmkgMzdWSSB5MVlyIDYySEs='
},
});
let body = await response.json();
console.log("The length of body is: " + body.length);
console.log(JSON.stringify(body));
for (var key in body) {
console.log("We are in loop number " + key);
RecordID = body[key].ID;
console.log("Record ID is: " + RecordID);
//ShortLink = body[key].shortURL;
//console.log("Shortlink is :" + ShortLink);
//LinkID = body[key].linkID;
//console.log("LinkID is: " + LinkID);
Clicks = body[key].clicks;
await table.updateRecordAsync(RecordID, {
//"LinkID": LinkID,
//"Shortlink": ShortLink
"Clicks": Clicks
});
}
However when I copy paste the exact same thing into an automation script block (script block to be triggered by webhook) - I get the following error:
Why does remoteFetchAsync seem to work on individual scripting blocks but not those triggered by Webhooks?
Or am I doing something wrong?
Thanks!
Jul 24, 2022 11:21 AM
I have similar issue. It looks like we cannot use remotefetch and can’t use loops in automation script.
As I have a simialr setup and it doesnt work, frustratingly enough.
Can someone correct me if i’m wrong and perhaps explain why the methods are so different from the blocks/ script extensions?
-Anna