Support Questions

Find answers, ask questions, and share your expertise

NiFi : InvokeHttp, authenticate to Salesforce's Bulk API V 2 , Oauth 2

avatar
Explorer

Hello everyone,

I am trying to authenticate with  InvokeHttp NiFi Processor to Salesforce by using Bulk API v2 and with OAuth 2.0 :

6-1606816870985.png

The InvokeHttp Processor is configured as follow :

7-1606817038511.png

The Remote URL is made by using this syntax:

 

https://< mydomain >.salesforce.com/services/oauth2/token?grant_type=password&client_id=<client_id>&client_secret=<client_secret>&username=<username>&password=<password + key>

As we are using the HTTPS protocol, we add a “SSL Context Service” by setting a new “SSL Context Controller Service”:

8-1606817459585.png

And the Post request is already tested and worked with Postman tool, by responding with an authentication token.

The blocking point for this use case is that, with InvokeHTTP NIFI Processor we have not been able to get a response from the Bulk API ( the first image show that we never receive any response from Salesforce )

 

If you have any suggestion, it's will be helpful.

 

Thank you in advance

KSAD

 

1 ACCEPTED SOLUTION

avatar
Explorer

@stevenmatisonthe solution that i find is to get the Oauth2 token from slaesforec by using command Curl. like is explained in this page : https://www.jitendrazaa.com/blog/salesforce/using-curl-with-salesforce-rest-api/

So i create a ExecuteProces NiFi Procesor. And as parameter i put :

Ksad_0-1606897337729.png

the file C:/loginInfo.txt contains :

grant_type=password&

client_id= 3MVG9iTxZANhwsdsdsdsdspr0LstjR3sRat &

client_secret=21961212323233121943 & username=jitendra.zaa@demo.com &

password=myPWDAndSecurityToken

and the i get a response with the authentication token 🙂

(you can use the cmd command Curl -x post -d @LoginInfo.txt Https://test.salesforce.com/.... to test the connection between the local machine and salesforce )

 

View solution in original post

5 REPLIES 5

avatar
Super Guru

@Ksad  Excellent work to completely show us what you have.  Also, excellent work to test and confirm your request work in postman first.  This is always one of the first things I do to make sure i have a valid test connection and all settings to connect to the API before attempting with InvokeHttp.    When you take this route, and you cannot get a response, this indicates a networking issue with Nifi to [salesforce domain].  You should test command line from NiFi node to [salesforce domain] using curl, wget, telnet, etc.    Next if you can confirm connectivity, attempt to adjust the processor time outs.   Some systems need longer than defaults.  For example I sometimes set to 50 and 150 by just adding a 0 to the 2 values (connection and read timeout).  f it did time out it should throw an error.  You can also set the processor log level to debug to expose more verbose output in the NiFi UI.  Last but not least,  tail the nifi-app.log file while doing all nifi flow debugging.  Sometimes more useful information is found there.

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.

 

Thanks,

Steven

avatar
Explorer

Thank you @stevenmatison for the quick answer.

The connection between my local machine (where NiFi is installed and executed) and salesforce server is working well, because i already tried with postman and it is working.

also, I increased the timeout as shown in the image below :

invokke http.png

 

and also activate the logging to debug level :

debug logging.JPG

But still have no output inthe Bulltin board of NiFi.

I let it run for 2minutes and had this log lines from the app.log file :

loging.JPG

i an wondering if there a parameter to add for the InvokeHttp processor like "authorization:OAuth2" or other ?

Thank you

 

 

avatar
Super Guru

You can leverage "Attributes to send"  or if you stop processor and click + you can add custom attributes right on bottom of processor config.   If you are not getting anything out of response (failure, retry, no-retry, etc) then you definitely have a connectivity issue from Nifi outbound... 

avatar
Explorer

Hi @stevenmatison , by using Curl command with my local machine , the authentication on salesforce is working and i get a token:

Ksad_0-1606840816127.png

And i already try the SOAP connection to Salesforce and it is working also. But with Oauth2.0 is not 😕

So the problem is on NiFi InvokeHTTP Processor

avatar
Explorer

@stevenmatisonthe solution that i find is to get the Oauth2 token from slaesforec by using command Curl. like is explained in this page : https://www.jitendrazaa.com/blog/salesforce/using-curl-with-salesforce-rest-api/

So i create a ExecuteProces NiFi Procesor. And as parameter i put :

Ksad_0-1606897337729.png

the file C:/loginInfo.txt contains :

grant_type=password&

client_id= 3MVG9iTxZANhwsdsdsdsdspr0LstjR3sRat &

client_secret=21961212323233121943 & username=jitendra.zaa@demo.com &

password=myPWDAndSecurityToken

and the i get a response with the authentication token 🙂

(you can use the cmd command Curl -x post -d @LoginInfo.txt Https://test.salesforce.com/.... to test the connection between the local machine and salesforce )