Skip to main content

Hello 
fetch('https://a.klaviyo.com/api/v2/list/Xa9enW/members?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxx&emails=ABC123@gmail.com', {
            mode: "no-cors",
            method: "GET",
            headers: {
                "Accept": "application/json"
            }
    }).then(function (response) {
                return response.json();
            })
            .then(function (data) {
                appendData(data);
            })
            .catch(function (err) {
                console.log('error: ' + err);
            });
        function appendData(data) {
            alert(data0.id]);  // not working
    var mainContainer = document.getElementById("myData");
            for (var i = 0; i < data.length; i++) {
                var div = document.createElement("div");
                  div.innerHTML = 'Name: ' + datai].id + ' ' + datai].created;
                mainContainer.appendChild(div);
            }
        }


Hello I am running this api to get whether this email is in list or  i am getting data inside response.json  but i have created appenddata function in which i want to show this email in page but it is returning  nothing    appendData(data); this is not returning anything  what wrong i am doing i dont know please help 

Also please help me how to pass dynamic email in api for example
​​​​​​https://a.klaviyo.com/api/v2/list/Xa9enW/members?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxx&emails={{cutomer.emial}}
when i am passing this it is giving me error 

 

Hello@guptaanjali538,

Thanks for sharing your question with the Klaviyo Community.

You will need to change alert(dataa0.id]) to alert(dataa0].id) in your appendData function.

Thanks and have a great day.


I have tried this in my append function but it is not working giving me error of 
“error: TypeError: Cannot read property 'id' of undefined”


@guptaanjali538 This seems like it could be an issue with what is being passed through your Promise chain. I would recommend adding logging at each step of the way so you can be sure of what data is being passed and what the structure looks like. At least logging the data that you are passing into your appendData function to see if it is in the structure that you think it is.

.then(function (response) {
return response.json();
})
.then(function (data) {
// ADD THE LINE BELOW THIS
console.log(data);
appendData(data);
})

Or you can add the console.log to the first line of the appendData function itself to see what argument is being passed into it. This should give you an idea of what is going wrong. If they only log `undefined` then you’ll want to try moving the log earlier in the Promise chain. Let me know how that goes.


Yes I have updated this code but again not working
giving error - error: TypeError: Cannot read property 'emails' of undefined


@guptaanjali538 that means somewhere in your code you are using `.emails` on something that is undefined.


Reply