Jul 06, 2024 04:31 AM
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)
Jul 10, 2024 06:15 AM
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.
Jul 12, 2024 09:38 PM
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.