Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to authenticate Salesforce using CL_HTTP_CLIENT

kjyothiraditya
Participant
0 Kudos
794

Hi experts,

I need to connect to Salesforce and for this I am thinkg of using CL_HTTP_CLIENT class. Salesforce uses 2 step authentication wherein it validates {username,pwd} and returns a token for further communication. But this class has only authenticate method and no response/token is received. Can you please let me know how to autheticate and connect to webservice in Salesforce using CL_HTTP_CLIENT. Also please let me know if there is any alternate method which can be achieved using ABAP without PI

11 REPLIES 11

SimoneMilesi
Active Contributor
291

Hello,

I think you should create a POST request with a RESTful approach (class cl_rest_http, like per blog https://blogs.sap.com/2014/11/09/calling-an-external-restful-service-from-abap-http-method-post/ ) and you'll receive the token in the response.

You can try invoking the Salesforce's login API with a tool like Postman

EDIT

Check here the login flow for Salesforce with all the given steps you need to perform in order to login

0 Kudos
291

Hi simone.milesi ,

We are on older version of SAP and we do not have class cl_rest_http_client available yet. Is there any alternate way other than using REST programming model ?

0 Kudos
291

Hi Everyone,

I am trying to implement using CL_HTTP_CLIENT class with below steps and it is going to dump.

1) Set the URL

2) Using authenticate and disable POPUP authentication

3) Then using receive method to get the token.

But the program is going to dump with "Exception condition "HTTP_COMMUNICATION_FAILURE" raised."

Can you please help me with this.

Regards

Jyothir Aditya

0 Kudos
291

jyothiraditya.k are you sure you can reach the url?
Do you have any proxy blocking it?

Can you ping your url from OS01?
Can you try to create a destination in SM59 and check if reachable?

0 Kudos
291

Hi Simon,

I think yes, because i am getting "authentication error". I am using URL and not an RFC.

0 Kudos
291

jyothiraditya.k "i think" isn't enough 🙂

Which error are you facing? Authentication or Communication? You wrote Communication in your previous answer...

If it's Authentication, again, create with Postman the same request and try to see what's happening.

SimoneMilesi
Active Contributor
0 Kudos
291

Hi Jyothir,

use comment instead of reply or it will be a nightmare follow the flow of replies 🙂

You can still use CL_HTTP_CLIENT: it's a bit longer to code but it will work as per https://answers.sap.com/questions/3572626/index.html

kjyothiraditya
Participant
0 Kudos
291

will check this.

closing request for now

mynynachau
Community Advocate
Community Advocate
0 Kudos
291

I reopened this question in order for you to receive helpful advice by other community members. Since you posted a new question on this topic, I deleted the new question and reopened this thread, so everyone can focus on one question. Thanks.

patriciachacon
Explorer
0 Kudos
291

How did they solve this?

0 Kudos
291

You can try as mentioned by Simone. You need to call 2 times. first to send credentials and then receive the token. Using this token send subsequent requests. havent used this as our system doesnt have this class yet. Also you need to add RFC destination and import certificates.