Salesforce MobileSDK: The Rest API is not enabled for this Organization
Asked Answered
I

1

7

I am trying to use Salesforce Mobile SDK for native Android. Requirement:

  1. Allow any user with Salesforce account to login
  2. Fetch his/her contacts list
  3. Fetch particular contact details

Please let me know if those are not part of the Mobile SDK.

I followed https://github.com/forcedotcom/SalesforceMobileSDK-Android:

  1. Cloned it
  2. Installed NPM and installed the required submodules
  3. Created a new Android application using native forcedroid
  4. Changed the bootconfig.xml values with the values of my connected app.

It logs in fine but when I try to fetch the contacts, it says:

The Rest API is not enabled for this Organization

enter image description here

The login response seems to be fine. Client object json credentials:

{
  "clientId": "*******",
  "loginUrl": "https://login.salesforce.com",
  "identityUrl": "https://login.salesforce.com/id/99VVHJHGF5688/00548000003yOKeAAM",
  "instanceUrl": "https://ap2.salesforce.com",
  "userId": "**********",
  "orgId": "*********",
  "communityUrl": null,
  "refreshToken": "*************",
  "accessToken": "************",
  "communityId": null,
  "userAgent": "SalesforceMobileSDK/4.3.0 android mobile/7.0 (Nexus 6P) SFTest/1.0 Native uid_32aea9bdde1b8b7e"
}

EDIT 1 : Code to get Contacts list:

public void onFetchContactsClick(View v) throws UnsupportedEncodingException {
    sendRequest("SELECT Name FROM Contact");
}

private void sendRequest(String soql) throws UnsupportedEncodingException {
    RestRequest restRequest = RestRequest.getRequestForQuery(ApiVersionStrings.getVersionNumber(this), soql);

    client.sendAsync(restRequest, new AsyncRequestCallback() {
        @Override
        public void onSuccess(RestRequest request, final RestResponse result) {
            result.consumeQuietly(); // consume before going back to main thread
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        listAdapter.clear();
                        JSONArray records = result.asJSONObject().getJSONArray("records");
                        for (int i = 0; i < records.length(); i++) {
                            listAdapter.add(records.getJSONObject(i).getString("Name"));
                        }
                    } catch (Exception e) {
                        onError(e);
                    }
                }
            });
        }

        @Override
        public void onError(final Exception exception) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(MainActivity.this,
                            MainActivity.this.getString(SalesforceSDKManager.getInstance().getSalesforceR().stringGenericError(), exception.toString()),
                            Toast.LENGTH_LONG).show();
                }
            });
        }
    });
}

EDIT 2 : Some more findings:

I think it has to do with my account/connected app settings. Because when I signedup using https://developer.salesforce.com/signup and used the username it works fine. Here again if I used the email instead it shows the same error of API not enabled. I created multiple usernames using the same email and the signup form, they all work fine, but not the email.

BTW I am currently using a trial version of salesforce.

Incorporeal answered 3/10, 2016 at 10:2 Comment(4)
I think you made JsonArrayRequest to API.Luciano
@Bansal The request code is generated by the SDK so it is standard.Incorporeal
Perhaps try one of Salesforce's Android native sample apps e.g. github.com/forcedotcom/SalesforceMobileSDK-Android/tree/master/…Orgell
@CliveSeebregts please check Edit-2Incorporeal
K
1

regular trial accounts are for Professional Edition, which doesn't include API access, which is the error you're getting. You need to use an account with API access such as a free developer edition account, or an enterprise edition account.

Kynan answered 5/10, 2016 at 5:26 Comment(6)
So if my salesforce.com/form/signup/freetrial-sales.jsp account is paid and have a connected app, on integration with my Android app, any user with a salesforce account can login and access the APIs? I just want to make sure that it need not be a developer account.Incorporeal
Are you building an app for your companies salesforce users, or are you building an app for other companies salesforce users [i.e. a partner or ISV situation]?Kynan
Not for my company users. Ideally any salesforce user of any company should be able to login through my Android app and use the APIs.Incorporeal
sign up for a developer edition account, create your connected app settings there, and you're good to go.Kynan
That is where I started. Please check EDIT 2.Incorporeal
As my answer states, not all account types have API access, so there will be some user accounts that can't use your app. Also you can't login with email address, only usernames.Kynan

© 2022 - 2024 — McMap. All rights reserved.