You need to sign in to do that
Don't have an account?

Defining the OAuth connection for an Apex Callout
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
3. The Authentication Provider picklist doesn't include Mailchimp, unless there is a "generic" one to use
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
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,
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,
3. The Authentication Provider picklist doesn't include Mailchimp, unless there is a "generic" one to use
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??
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??
All Answers
I'm stuck at similar situation. Can you share your solution on this ?
Did you write code in Apex class to get the auth token ?
Can you share your findings.
Can you please share the code for oAuth2.
Regards,
Yohan
First, you have to create an external Auth provider (https://help.salesforce.com/articleView?id=sso_provider_openid_connect.htm&type=5#register_application)
Secondly, you have to created a named credential (https://developer.salesforce.com/docs/atlas.en-us.224.0.apexcode.meta/apexcode/apex_callouts_named_credentials.htm) as Robin did.
And then you will be able to see your Auth provider in the lookup.