Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 607
Housefly Avatar asked Oct 03 '16 10:10

Housefly


People also ask

Is there a REST API in rails for Salesforce?

The REST API is not enabled for this Organization (Salesforce API using databasedotcom gem) in Rails Ask Question Asked8 years, 4 months ago Active6 years, 11 months ago

Where is the API permission in Salesforce?

Sep 3 '13 at 6:53 API Enabled permission will be on the Users Permission Section in the Profile. API Enabled option will be there only for Users of Profile System Administrator or Cloned profiel of System Administrator. na4.salesforce.com/help/doc/en/admin_userperms.htm

Why can't I see the API in my organization?

Here's how to fix that. First, check on the organization settings. Enterprise, Unlimited and Developer editions has the API enabled by default. Professional Customers can purchase this feature.

What org should I use to access the REST API?

You should fine using a developer org .Sign up with a developer org and you can access REST and SOAP API's


1 Answers

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.

like image 127
superfell Avatar answered Oct 02 '22 18:10

superfell