Issue: 0Auth to Salesforce

Hi,

I am having some issues connecting to my salesforce org.

I have set up a connected app on the salesforce end with 0auth and relevant access.

The salesforce org is a sandbox.

I am trying to use the REST POST node to get the 0auth token but keep getting code 400 return.

I am using the URL. https://test.salesforce.com/services/oauth2/token

and the body (replacing the relevant values) username=username&client_id=client_id&password=password&client_secret=client_secret&grant_type=password

I am not sure where I am going wrong with 0auth. Any help would be great.

Thanks.

Hi @UndefinedFate ,

What do you mean by this? I am 99.9999% sure that’s not how these are used/passed. The documentation of the API should tell you how to pass these values, probably either as a JSON or an XML if in the body, or maybe as headers.

Hi Bruno,

Thanks for the response in the documentation they have given a curl example of connecting with 0auth

“Send a request to the Salesforce OAuth endpoint using this cURL template:
curl https://MyDomainName.my.salesforce.com/services/oauth2/token -d ‘grant_type=password’
-d ‘client_id=consumer-key’ -d ‘client_secret=consumer-secret’ -d
‘username=my-login@domain.com’ -d ‘password=my-password’”

Would this map to the post node request body or should I put these as heaers?

Hi @UndefinedFate,

please let me point you to the salesforce extension from which I often times used the Salesforce Authentication node in conjunction with the Salesforce Authentication Extractor node - so luckily, there’s no need to get the bearer “manually” :wink: In the Salesforce Authentication Nodes configuration windows there is a tab where you can choose between the production and sandbox environment.

@bruno29a, regarding the request nodes: it works either way, putting the headers in the URL or with the header tab (the header tab does nothing else but format it in the same fashion). The header tab approach I’d label as more versatile as it makes it easier to parametrize the headers dynamically via flow variables.

Best Regards,
Lukas

3 Likes

Hi @LukasS ,

Thank you for the response, I have had a look through the salesforce exentension and works great. I am working on a couple of API integrations with knime and would love to understand where I am going wrong with doing it manually through the REST nodes for my own understanding.

Do you know if there is anything that I am doing wrong from the knime end. I have configured a connected app in salesforce and got the relevant 0auth clientID and secret.

In Knime, I am using the REST POST node with the following configuration.

Connection settings:

URL https://MyDomainName.my.salesforce.com/services/oauth2/token (replacing the domain name with my sf domain)

One header configured (“Header Key: Content-Type”, “Header Value: application/x-www-form-urlencoded”, “Value Kind: Constant”

And as I mentioned before I am putting in the body:

username=myusername&client_id=myclientid&password=mypassword&client_secret=mysecret&grant_type=password

From this are you able to see anything that I’ve done wrong from the Knime end?

Thanks.

Hi @UndefinedFate,

ah, I’m sorry, I misread your second question: the

-d ‘grant_type=password’
-d ‘client_id=consumer-key’ -d ‘client_secret=consumer-secret’ -d
‘username=my-login@domain.com’ -d ‘password=my-password’

part maps to the Request Headers tab. So what you put in the body now should go in there like so:


So in total, you have six headers.

Some background on RESTful URLs like https://www.myurl.com/?key=value&key2=value2: The key - value pairs are headers, (? denoting the end of the address, key and value is separated by a “=”, pairs being separated by “&”, key and value should be urlecoded (" " → “%20”)), which can also be passed to e.g. a GET or DELETE Request. If you type in an address in your browser that’s nothing but a GET Request: you ask the Server to give you back the website (try it with the url you are creafting right now!). If you want to send (larger amounts of) data, you’d use a POST Request (e.g. workflows on a KNIME Server can be interacted with like that). So in your case, you’d actually want a GET Request node, if I’m not mistaken, as you don’t want to send much data but “get” the bearer back.

Some more tips that I found useful when developing REST calls:

  • I like using postman to craft the call correctly - I find it less tedious than reconfiguring the node. Transforming the command to KNIME is easily done once its working.
  • What tripped me from time to time was an extra whitespace (" ") e.g. at the end of a header name.
  • in KNIME 4.4 and below there is the Extract Missing Value Cause node to get more information about why no body could be returned. Since KNIME 4.5.0 this is an option in the Error Handling tab:

I very much appreciate your attitude to strive to understand things :slight_smile:

Festive Greetings,
Lukas

2 Likes

Fantastic thank you so much for you help @LukasS . Really appreciate you taking the time.

In the end the issue I was having was special characters being passed in the body password. I ran them through a Palladian node to generate the body an it added % signs around some of the special characters. Not sure what the syntax is of the body. but this fixed the issue.

Thanks again.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.