简体   繁体   中英

How to pass jS variable for API integration?

As part of a membership solution I am building, I am using jS and JSON to manage membership data, I have the following code which does as it should:

$(document).on('click', '#triggerLink', function() {

    MemberStack.onReady.then(async function(member) {

        var metadata = await member.getMetaData() <--- returns all metadata as JSON
        var email = member["email"]; <--- pull user email into `email` jS variable

        /*Do other unrelated stuff here which is working.*/
        window.location.href = "https://URL.com/test";

    })

});

Now that I have the users email address stored in a variable called email , I need to connect this to Mailchimp via one of their approved methods . The problem is I don't see an option that I could call in this scenario, I was hoping for a $.ajax type method but there isn't one.

Is it possible to pass the jS variable email into one of these options using my current code?

What i understood is, i just need to call fetch method and send email id. eg.

$(document).on('click', '#triggerLink', function() {

    MemberStack.onReady.then(async function(member) {

        var metadata = await member.getMetaData() <--- returns all metadata as JSON
        var email = member["email"]; <--- pull user email into `email` jS variable

fetch(`https://server.api.mailchimp.com/3.0/automations/{workflow_id}/emails/${email}}`)
  .then(response => response.json());
  
        /*Do other unrelated stuff here which is working.*/
        window.location.href = "https://URL.com/test";

    })

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM