Using Salesforce’s API

Hi Bubblers! :wave:

I’m not super proficient with my APIs, but I can manage usually :sweat_smile: Has anyone utilized Salesforce’s API through the API connector, not the plugin?

What does your setup look like for authenticating the calls?

Yes I use it. Not easy to configure and mostly because doc is not well made and huge. There’s a lot to learn with Salesforces API

Hi @Jici, thanks for your reply! Do you have any examples of your setup for it?

Not actually. Which kind of auth will you use?

I want to be able to grab contact info based off their Salesforce id

So I guess you are calling a specific company SF domain. You can use password auth with Custom oAuth2 token.

https://na82.salesforce.com/services/oauth2/token?grant_type=password&client_id=<clientid>&client_secret=<clientsecret>&username=<username>&password=<password>

And after you need to build the query. Normally directly in querystring.

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_cdp_query.htm

3 Likes

Hey @Jici and @jonny, I’m setting up Salesforce in the API connector and I can’t get it to work… Did you use OAuth 2 User-Agent Flow?

My POST request seems perfect but I think the authentication is what’s failing.

Mostly using server to server auth. Can you share what you have set?
What do you mean with POST seem to work but authentication is failing?

Okay, for sure I can share.

In short, I need to pull accounts and opportunity data for my client. So nothing too complicated.

  1. I set up the Connected App in Salesforce and have Client ID and Client Secret
  2. Checked to use OAuth 2

Then for the POST to authenticate and get token I have this…

and get this

if you want to user password, this is server to server auth, and you should use custom auth token isntead of user-agent

user-agent flow is to let your user use SF as an auth provider (like google, microsoft, facebook…). This process will also create a user in your DB. If you want your user to connect their own SF account, but create their account with Bubble login process, you will need to manually configure each step.

Thank you, this is helpful and hopefully helps others get setup. This is exactly what I need, just server to server.

After this is set, do you still run an authentication POST? Or would you just begin initializing a GET request?

I’m still using this… Seems redundant.

Then for the POST to authenticate and get token I have this…

You don,t need to run anyhing else for auth. This is done in the custom oAuth2 and Bubble will automatically add the authorization header to all call. You can delete the token endpoint but set this in oAuth2 custom token call like in my screenshot.

Simple get user call to validate my auth is working

If you look correctly, you need to call the correct server endpoint for this type of auth. It’s not the same as user-agent/authorization_code flow (UPDATE: tested with https://login.salesforce.com/services/oauth2/token and it’s also work fine)

And best is to use client_credentials if possible. This is also done in custom auth if I remember

Closing this out.

As Jici mentioned above, Server to Server connections use the OAuth2 Custom Token set up.

My host was different and I connected to the endpoint following the salesforce docs here:

POST /services/oauth2/token HTTP/1.1
Host: MyDomainName.my.salesforce.com
grant_type=client_credentials&
client_id=*******************&
client_secret=*******************

That translates to “https://mydomain.my.salesforce.com/services/oauth2/token?grant_type=client_credentials&cleint_id=<your_client_id>&client_secret=<your_client_secret>”

The biggest thing is the actual setup on the Salesforce “Connected App” side. A weekend of research and videos and you’ll get a base understanding of “API Integration Users”, “Permissions Sets”, and “Connected Apps”. After a few failed attempts, logged a case and had the user properly permissioned in 15 min with their API support team.

Thanks again Jici, you set me on the right path! Appreciate it!

1 Like