Calling Salesforce REST API using Community User

It’s been a long time I have not written anything on this platform. Today, we will talk about “Calling Salesforce REST API using Community User”. This is a process for PostMan, but you will get the idea 🙂

User setup for :Calling Salesforce REST API using Community User

First thing first. By default the community users profile are not allowed for API calls. So clone the community profile you want to update and add the below two permission under system permissions:

Calling Salesforce REST API using Community User
System permissions

Assign the new profile to the user we are going to test with. Then allow this profile to the community you want to test with.

Permission in community
Permission in community

Now let’s create a Connected App and get the client id and secret.

Once these are done we are ready to jump on to PostMan.

PostMan Steps

First step in this ? You guessed it : Open PostMan.

On a new tab prepare the URL to be hit for access token. The access token URL for Community will be :

https://<Salesforce community URL>/services/oauth2/authorize?response_type=token&client_id=<client_id from connected app created above>&redirect_uri=<redirect URI mentioned in the connected app>

The resource URI to be access needs to be added to the Postman tab:

https://<Salesforce Instance URL>/services/data/v48.0/query?q=select+id+,name+from+account (This can be any resource you want to query)

Note: This is not the Community URL

Postman tab: Calling Salesforce REST API using Community User
Postman tab

Go to Authorization tab and select type = OAuth 2.0

Authorization : Calling Salesforce REST API using Community User
Authorization

Click “Get New Access Token” to get the below window and fill it like the below screen.

new token page
new token page

Once all good and you click on the request token button it will popup with the window to enter your credentials :

OAuth window
OAuth window
Access token
Access token

Now you have the access token for your use. Click Use token and the PostMan will create the required header for use and get the resources. See the below screen for reference.

result screen
result screen

Conclusion

This helps reduce few steps we had to do earlier. But unless you want to go through that pain, this should be quick to test the API’s out. Please share your thoughts on this post “Calling Salesforce REST API using Community User” and keep reading and sharing….


Comments

11 responses to “Calling Salesforce REST API using Community User”

  1. No Workaround for the above solution

    1. Amit Sahu Avatar

      What do you mean ?

  2. This did not work for me. I want to use integration user to be used as integration user for my rest API. I have enabled the API permissions in the profile of the user. But it fails during authorization.

    1. Amit Sahu Avatar

      Any error you see ?

      1. Amit Sahu Avatar
        Amit Sahu

        There has been some changes to the Salesforce authentication for community, may that has something to do with it. Will check and update the post if needed. Thanks for letting me know.

        But looking at the log , it seems some grant type issue.

  3. It also didn’t work for me, That’s my Error:

    SLF4J: Actual binding is of type [org.slf4j.impl.Reload4jLoggerFactory]
    [17:17:28] INFO [salesforcerestsdk.SalesforceSession] – Logging into server sfsq3-17c0dd7f498.test1.pc-rnd.force.com for user community@na46xanda.com
    [17:17:28] INFO [com.salesforce.mobiletest.data.TestRestDelegate] – Background login complete for org ‘community’ with user ‘standard1’
    [17:17:30] INFO [salesforcerestsdk.SalesforceSession] – getStatusLine = HTTP/1.1 400 Bad Request
    [17:17:30] ERROR [salesforcerestsdk.SalesforceSession] – Error status code: 400
    [17:17:30] ERROR [salesforcerestsdk.SalesforceSession] – User: community@na46xanda.com had error: grant type not supported
    [17:17:30] WARN [salesforcerestsdk.SalesforceSession] – Failed to set org data for user: standard1, in org: community
    [17:17:30] INFO [salesforcerestsdk.SalesforceSession] – completeSetupThread join
    [17:17:30] INFO [salesforcerestsdk.SalesforceSession] – Session setup complete
    [17:17:31] INFO [salesforcerestsdk.SalesforceSession] – getStatusLine = HTTP/1.1 401 Unauthorized
    Exception in thread “main” java.lang.NullPointerException
    at com.salesforce.mobiletest.data.TestRestDelegate.hasLightningOnMobile(TestRestDelegate.java:95)
    at sfs.mobile.test.RunTest.decideTestPrefix(RunTest.java:118)
    at sfs.mobile.test.RunTest.main(RunTest.java:44)

    > Task :native:RunTest.main() FAILED

    Execution failed for task ‘:native:RunTest.main()’.
    > Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home/bin/java” finished with non-zero exit value 1

    1. Amit Sahu Avatar
      Amit Sahu

      Are you trying this from any rest client or from another salesforce system?

  4. Thanks for this post, Amit. I was able to get the Salesforce login page to show up, and I entered my admin credentials, but upon clicking “Log In”, I was stuck on a pop up in Postman that said:

    “Authenticate via browser

    This dialogue will automatically close once the auth callback is received. Make sure your browser is not blocking pop-up window.”

    It was stuck there for a long time, until I eventually cancelled the authorization.

    Any ideas why I was facing this?

    Some notes:
    1. The callback URL for my Connected App is: “https://”

    1. Amit Sahu Avatar
      Amit Sahu

      Hi CA,

      Did you check the login history of the user id you see any errors there ?

  5. Prathima Avatar
    Prathima

    Hi Amit,

    I tried this for the community user and as explained I gave community URL in callback, access token URL and even auth URL but that always errored out and never allowed me to login and get the access token.

    1. Amit Sahu Avatar
      Amit Sahu

      Sorry for the late response on this. But that seems to be a issue with the browser cache. Try cleaning the cache once or try using incognito mode/private mode in the browser .

Leave a Reply

Your email address will not be published. Required fields are marked *