8

I want to login a customer community user using rest api or at least using soap api.

I have created a user using the REST API. To create the user, first I created one contact with account and provided the profile id of a cloned profile of type community login user with api enabled option.

To Login user, I used the URL

https://my-domain-1-developer-edition.ap2.force.com/investor/services/oauth2/token

params

client_id,client_secret,username,password,
grant_type="password", response_type="code",content-type="application/x-www-form-urlencoded"

got response

{
  "error": "unsupported_grant_type",
  "error_description": "grant type not supported"
}

I have also tried to set 'application/x-www-form-urlencoded' as content-type. in header.

I have also tried to do it using SOAP endpoint

https://my-domain-1-developer-edition.ap2.force.com/investor/services/Soap/u/36.0

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <n1:login xmlns:n1="urn:partner.soap.sforce.com">
      <n1:username>username</n1:username>
      <n1:password>password</n1:password>
    </n1:login>
  </env:Body>
</env:Envelope> 

got the response

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>sf:INVALID_LOGIN</faultcode>
            <faultstring>INVALID_LOGIN: Invalid username, password, security token; or user locked out.</faultstring>
            <detail>
                <sf:LoginFault xsi:type="sf:LoginFault">
                    <sf:exceptionCode>INVALID_LOGIN</sf:exceptionCode>
                    <sf:exceptionMessage>Invalid username, password, security token; or user locked out.</sf:exceptionMessage>
                </sf:LoginFault>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

I am using developer license.

  • Hi saurabh, welcome to SFSE! Please take the time to visit the Help center and read How do I ask a good question. It's not clear to me exactly what your question is. If you post what you've written so far and where you're stuck, I'm confident you'll find plenty of people willing to assist you. – crmprogdev Feb 24 '16 at 15:06
  • @crmprogdev edited the answer, I didn't add it earlier because I thought the it would imply it ;-) Thanks!!! – saurabh Feb 24 '16 at 15:26
  • @saurabh It is not possible to login with the community user credentials as you would with a regular user. OAuth has different flows. The username / password flow is not supported for community user. – abhi Feb 24 '16 at 21:08
  • @abhi but I could not find this stated clearly in documentation. – saurabh Feb 25 '16 at 6:42
10

Since community usernames are not globally unique, you need to use SOAP login with LoginScopeHeader to identify the org:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:partner.soap.sforce.com">
  <SOAP-ENV:Header>
    <ns1:LoginScopeHeader>
      <ns1:organizationId>00DB00000001234</ns1:organizationId>
    </ns1:LoginScopeHeader>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:login>
      <ns1:username>user@example.com</ns1:username>
      <ns1:password>p455w0rd</ns1:password>
    </ns1:login>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
  • thanks!! I will try this but we can't do this using REST API ? – saurabh Feb 25 '16 at 6:40
  • 1
    Hey it worked! But need to add portalId too. Also I had not activated profile for the organization. – saurabh Feb 25 '16 at 13:27
  • Hmm - that worked for me without portalId - I guess it depends on your config? – metadaddy Feb 25 '16 at 19:25
  • my community user is not able to login using the above solution so I have posted a similar question on the community salesforce.stackexchange.com/questions/200408/… – harshal jadhav Nov 29 '17 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.