Help

Automation Script JSON to var?

Topic Labels: Scripting extentions
3030 7
cancel
Showing results for 
Search instead for 
Did you mean: 
Sebastien
4 - Data Explorer
4 - Data Explorer

Hello,

My input are:
idStock
getURL
getApiKeylabel
getApiKey

My code:

let table = base.getTable("Stocks");
let query = await table.selectRecordsAsync();
console.log(query.records);
let inputConfig = input.config();
console.log(`The value of idStock is ${inputConfig.idStock}`);
console.log(`The value of getApiKey is ${inputConfig.getApiKey}`);
console.log(`The value of getURL is ${inputConfig.getURL}`);
let mergeAPI = (`${inputConfig.getApiKeylabel}=${inputConfig.getApiKey}`);
let mergeURL = (`${inputConfig.getURL}${inputConfig.idStock}?${mergeAPI}`);
console.log(`The value of mergetURL is ${mergeURL}`);
let response = await fetch(`${mergeURL}`);
console.log(await response.json("price:"));

I want to output my json result to a field.Is it possible?

7 Replies 7

Welcome to the Airtable community!

Yes, an automation can update field value for a record. You use the updateRecordAsync method on the table object. If you want to create a new record, use createRecordAsync. If you are updating the triggering record, you’ll need an input variable for the triggering record’s record ID.

These are all explained in the scripting documentation.

I recommend a long text field for storing the JSON.

Thank you @kuovonne for your answer. I have a hard time to figure it out lol.

Hello,

I really tried to understand the documentation. Is there anyone know how to pass json() to a Output in automation?

output.set( jason()) ??

The documentation for how to use output.set is here.

Thanks, but I already know that page. however, it’s lack of details and information. The reason why I am looking now in the forum for help.

As the documentation states, output.set() takes a key/value pair. Your example is trying to pass a value without a key.

Seems like all you’d need to do is, instead of just console logging it, setting await response.json('price:') as a variable such as responseJSON and then on the next line write output.set('myJSONoutput', responseJSON).

^ From there you can use an Update Record action step using the output myJSONoutput in a LongTextField as kuovonne suggested.

Can you clarify why you want to use output.set()? output.set() is used in an automation to pass a value to a different action further down in the automation. It is not used directly to set field values.