• Rahul Agarwal 40
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I want to connect Salesforce to Mailchimp so I can send an Apex Callout with a REST PUT request to update a subscriber in Mailchimp.  I've connected Postman (https://www.getpostman.com/) to Mailchimp and go the core REST statement defined and working.  As part of this I needed to set-up the OAuth connection.  This was straight forward to do:
1. In Mailchimp, set-up the connecting App, this generates the Client ID and Client Secet to use.
2. In Postman, request a new Access Token, as shown
User-added image
3. In Postman, use the Access Token as authentication in the REST Header, like this

GET /3.0/Lists/ HTTP/1.1
Host: us16.api.mailchimp.com
Authorization: Bearer c36db89lkjh8hkh8l6ae0005bfc3

I'm really struggling to set-up the same for Salesforce.....  
1. Connected Apps aren't relevant as that is for apps that wish to get data from Salesforce, I want the other way around
2. Named Credentials seems to be the right place but this asks for an Authentication Provider, 
User-added image

3. The Authentication Provider picklist doesn't include Mailchimp, unless there is a "generic" one to use
User-added image
So to get it to work I've had to hard code the Access Token I got for Postman into the request in the Apex Callout as shown

public class Mailchimp {

    public static string  getMailChimp() {          
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('https://us16.api.mailchimp.com/3.0/Lists/'); 
    request.setHeader('Authorization', 'Bearer c36dbf7jhv89jbnjnkuf6a7a16ae0005bfc3');
    request.setMethod('GET');
    HttpResponse response = http.send(request);   
    string a = response.getBody();      
    system.debug('Here you go - ' + a);
    Return a;
    }     
}

What am I missing??