Help

Re: Problem with a script / config

2727 7
cancel
Showing results for 
Search instead for 
Did you mean: 
Jesper_Lauridse
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi All.

I found the following script code for sending a webhook from Airtable to Make but the input.config() in the first line demands an argument.

anyone knows why?

Jesper

let inputConfig = input.config();

let recordID = inputConfig.inputRecord;

console.log(recordID);

let url=‘https://hook.eu1.make.com/7emn6wadgl4bn494kgibfvtop3lf4h6s

console.log(url);

let request= url.concat(‘?recordID=’,recordID)

console.log(request);

await fetch(request);

8 Replies 8

Are you writing a script using the Scripting Extension/App or an automation?

The code looks like code for an automation script. If you want to run the script from a button you don’t need to use input.config() to get the triggering record. Instead, use await input.recordAsync() with the appropriate parameters.

Hi again Kuovonne :winking_face:
Thank again fro taking the time.
I’m just trying to get an id from Airtable to Make and I don’t understand how it can be so hard :winking_face:

The first version should be a script called from a button. When I changed the input to a array it now came up with this error.

TypeError: URL is not valid or contains user credentials.
at fetch
at asyncFunctionResume
at promiseReactionJobWithoutPromise
at promiseReactionJob

Here is the code

// Get the airtabel webhook URL
let webhook = ‘https://hook.eu1.make.com/7emn6wadgl4bn494kgibfvtop3lf4h6s

// Airtable script button name.
let actionDescription = ‘Sending images to processing’

let tableName = ‘MakeTestTable’

let fieldsToSend = [‘Brand2’]

let table = base.getTable(tableName);
let record = await input.recordAsync(actionDescription, table);
let queryParams = ‘/?id=$(record.id)’
if(fieldsToSend.length > 0){
function buildParams(fieldName) {
let fieldValue = record.getCellValueAsString(fieldName)
queryParams += ‘&${encodeURIComponent(fieldName)}=${encodeURIComponent(fieldValue)}’
}

fieldsToSend.forEach(buildParams);

}
const returnedpayload = await fetch(‘${webhook}${queryParams}’);
var payloadResponse = await returnedpayload.json()
let result = payloadResponse.result;
output.text(result)

Can you find the error?

Thanks / Jesper

Nope. But it is also really hard to read your code because the forum is messing with the display of your code. When you include code in a post it is helpful to use the code formatting button at the top of the editor.

You could also try using remoteFetchAsync Instead of fetch. See this documentation page for more info.

// Get the airtabel webhook URL
let webhook = 'https://hook.eu1.make.com/uiob4x9vxuob2np2wwifebvlqfqenae4';

// Airtable script button name.
let actionDescription = 'Sending images to processing';

let tableName = 'Make test table'

let fieldsToSend = 'Brand 2'

let table = base.getTable(tableName);

let record = await input.recordAsync(actionDescription,table);
let queryParams = '/?id=$(record.id)'
if(fieldsToSend.length > 0){
    function buildParams(fieldName) {
        let fieldValue = record.getCellValueAsString(fieldName)
        queryParams += '&${encodeURIComponent(fieldName)}=${encodeURIComponent(fieldValue)}'
    }
    
    fieldsToSend.forEach(buildParams);
}
    const returnedpayload = await fetch('${webhook}${queryParams}');
    var payloadResponse = await returnedpayload.json()
    let result = payloadResponse.result;
    output.text(result)





let inputConfig = input.config();
let recordID = inputConfig.inputRecord;
console.log(recordID);
let url='https://hook.eu1.make.com/7emn6wadgl4bn494kgibfvtop3lf4h6s'
console.log(url);
let request= url.concat('?recordID=',recordID)
console.log(request);
await fetch(request);

Hi Kuovonne.

I’ve now sent you the two versions I’m trying to get working. Does that help ?

Hope you can find the problem.

Jesper

It looks like your fieldsToSend variable got turned back into a text string, instead of an array.

You also didn’t try remoteFetchAsync.

If those things don’t do the trick, try posting screen shots of the error messages as well. I may not have time to further troubleshoot for you, but someone else might be able to.

Ok Kuovonne but thanks a lot for the effort. Great of you to take the time. :winking_face: