Help

Re: JSON problem while connecting to EmailJS

Solved
Jump to Solution
1398 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Xuewen_Zeng
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi, Professionals here,

I encounter a problem, I want to use EmailJS service to send HTML emails.
I try the automation of Airtable, the actions of “finding records” and “sending email”, but it is not as intelligent as I want, So I want to use EmailJS service.

So I wrote the below code in Airtable script.

let params = {
    service_id:'service_gbwx81a',
    template_id:'template_6euwe2d',
    user_id:'cxkTio1YLQSY241rj',
    template_params:{
        to_name:"Stone",
        from_name:"Stone",
        reply_to:"Stone",
        message: "ABC",
    }
}

let headers = {
    "Content-Type": "application/json",
};



let options = {
    method: 'POST',
    headers: headers,
    body:JSON.stringify(params),
};

console.log(JSON.stringify(params));

let emailJSURL = 'https://api.emailjs.com/api/v1.0/email/send';

await doRemoteFetch(emailJSURL, "POST", params);

async function doRemoteFetch(url, postOrGet, body = null) {
    let success = false
    let fetchedData = null
    let fetchOptions = {
        method: postOrGet,
        headers: {
            "Content-Type": "application/json",
        },
    }
    if (body) {
        fetchOptions.body = JSON.stringify(body)
    }
    await remoteFetchAsync(url, fetchOptions)
        .then((resp) => resp.json())
        .then(function (data) {
            output.inspect(data);
            success = true
            fetchedData = data
        })
        .catch(function (e) {
            output.markdown("ERROR!");
            output.markdown(e.message);
        })
    return {success: success, data: fetchedData}
}


But there is an error reported:

Unexpected token A in JSON at position 0

I checked the log in EmailJS account, no errors history there.

Can anyone help me to solve this problem?
Thanks a lot :slightly_smiling_face:

1 Solution

Accepted Solutions
Bill_French
17 - Neptune
17 - Neptune

You are stringifying body twice.

See Solution in Thread

2 Replies 2
Bill_French
17 - Neptune
17 - Neptune

You are stringifying body twice.

Hi Bill, many thanks for your support.
The problem solved. :blush: