简体   繁体   中英

Retrieve mailchimp list details via ajax (iron-ajax, polymer)

I am trying to call the mailchimp API to show details of a list but I can't figure out how to send the auth credentials to show the list. I've tried a few things, I'm not really sure if I'm on the right track. This is what I've tried:

<iron-ajax
    auto
    url='https://us3.api.mailchimp.com/3.0/lists/{{listid}}'
    handle-as='json'
    method='get'
    headers='{"Authorization": "Basic base64credentials"}'
    debounce-duration='300'
    last-response='{{json}}'></iron-ajax>


<iron-ajax
    auto
    url='https://us3.api.mailchimp.com/3.0/lists/{{listid}}'
    handle-as='json'
    method='get'
    headers='{"user": "username:apikey"}'
    debounce-duration='300'
    last-response='{{json}}'></iron-ajax>


<iron-ajax
    auto
    url='https://us3.api.mailchimp.com/3.0/lists/{{listid}}'
    handle-as='json'
    method='get'
    headers='{"Authorization": "Basic username:apikey"}'
    debounce-duration='300'
    last-response='{{json}}'></iron-ajax>

Use the btoa function:

<iron-ajax
auto
url='https://us3.api.mailchimp.com/3.0/lists/{{listid}}'
handle-as='json'
method='get'
headers='{"Authorization": "Basic [[basicAuth(username, apiKey)]]"}'
debounce-duration='300'
last-response='{{json}}'></iron-ajax>
<script>
    Polymer({
        ...
        basicAuth(username, password) {
            return window.btoa(username + ':' + password)
        },
        ...
    });
</script>

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