+ Start a Discussion
Sanchivan SivadasanSanchivan Sivadasan 

Calling Apex Rest API without oAuth

Hi there,

I have an Apex Rest Webservice that I need to call but without oAuth. I want to use my username and password to authenticate. Is this possible? If yes, how can I do this? Assume that I will be calling this from either Java or C#. Thanks.

SS.

 
Sanchivan SivadasanSanchivan Sivadasan
Hi there,

I found this link https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_username_password_flow.htm&language=en

What is the client_id and client_secret that needed to be passed? 
gbu.varungbu.varun
Hi if you want you use your username and password to call Apex Rest API then you will have to use Username-Password Flow. 
First of all you will have to create a connected app to get client_id and client_secret then you can given steps in the given link.
https://help.salesforce.com/HTViewHelpDoc?id=remoteaccess_oauth_username_password_flow.htm&language=en_US
ThousifAli99ThousifAli99
Hi
You can also directly make a http login call to salesforce by passing the required details like below

    String pwd='';
    String userName='';

HttpRequest request= new HttpRequest();
        request.setEndpoint('https://test.salesforce.com/services/Soap/u/22.0');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
        request.setHeader('SOAPAction', '""');
        request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + userName+ '</username><password>' + pwd+ '</password></login></Body></Envelope>');
        Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement()
          .getChildElement('Body', 'http://schemas.xmlsoap.org/soap/envelope/')
          .getChildElement('loginResponse', 'urn:partner.soap.sforce.com')
          .getChildElement('result', 'urn:partner.soap.sforce.com');

        final String SERVER_URL = resultElmt.getChildElement('serverUrl', 'urn:partner.soap.sforce.com') .getText().split('/services')[0];
        final String SESSION_ID = resultElmt.getChildElement('sessionId', 'urn:partner.soap.sforce.com') .getText();