Help

CORS problem when used airtable variable

33315 2
cancel
Showing results for 
Search instead for 
Did you mean: 
gunkimsong
4 - Data Explorer
4 - Data Explorer

I can call my endpoint (with hardcode variable) it's successful in requesting ( got a response ), but when I try to use a variable, params from the record. It's stuck on the CORS problem, but I am not sure why,

(both variables are the same, the difference is the one from the variable does not worked,
and one from hardcode is worked)

//if I used hardcode in data, it work fine.

const requestApi = async (params) => {
	const myHeaders = new Headers();
	myHeaders.append("api-key", "xxxxxxxxx");
	myHeaders.append("Content-Type", "application/json");
	try {
		const requestOptions = {
			method: "POST",
			headers: myHeaders,
			body: params,
			// JSON.stringify({
			// "pid": "xxxxxx",
			// "firstName": "xxxxxx",
			// "lastName": "xxxxxxx",
			// "birthDay": "xxxxxx",
			// "laser": "xxxxxx"
			// }),
		};
	const response = await remoteFetchAsync("https://xxxxxxxx", requestOptions);
	const result = await response.text();
	console.log("Record updated successfully.");
} catch (error) {
	console.error('Error:', error);
}}

let table = base.getTable("Juristic");
let selectedRecord = await input.recordAsync('Select a record to use', table);

const data = JSON.stringify({
"pid": selectedRecord?.getCellValue("authorized1_id_card"),
"firstName": selectedRecord?.getCellValue("authorized1_firstname"),
"lastName": selectedRecord?.getCellValue("authorized1_lastname"),
"birthday": selectedRecord?.getCellValue("authorized1_dob").replace(RegExp('-', 'g'),""),
"laser": selectedRecord?.getCellValue("authorized1_laser_id"),
})

await requestApi(data)

 

 

2 Replies 2
SilverTaza
5 - Automation Enthusiast
5 - Automation Enthusiast

If the only difference between the two requests is the data itself, you should see what is the exact data you're building, and use this as the hardcoded version and see if it fixes it. Don't create the hardcoded data yourself.  You'll see the difference between these two faster this way.

sflorez
4 - Data Explorer
4 - Data Explorer

@gunkimsong 

If the data is the same between the hardcoded test and the record you are pulling in, you could try moving the extension code over to an automation and using fetch. Although remoteAsyncFetch is meant as a work around for CORS issues it could point you in the right direction.

Sebastian at Stradia Partners