1

I am trying to create a User in SFDC with REST API on Java Client. Please see my code below and help me to understand why I am getting the error message below:

HTTP Status 400 ::
{
errorCode: "NOT_FOUND"
message: "The requested resource does not exist"
}

CODE:

HttpClient httpClient = new HttpClient();
JSONObject user = new JSONObject();
String userId = null;

try{

    user.put("Username", "[email protected]");
    user.put("Alias", "DemoAPI");
    user.put("ProfileId", "00e90000000fKXB");
    user.put("Email", "[email protected]");
    user.put("EmailEncodingKey", "ISO-8859-1");
    user.put("LastName", "REST API Test");
    user.put("LanguageLocaleKey", "pt_BR");
    user.put("LocaleSidKey", "pt_BR");
    user.put("TimeZoneSidKey", "America/Sao_Paulo");

    PostMethod post = new PostMethod( instanceURL + "/services/data/v29.0/sobjects/User");
    post.setRequestHeader("Authorization", "OAuth " + accessToken);
    post.setRequestEntity(new StringRequestEntity(user.toString(), "application/json", null));

    httpClient.executeMethod(post);

}catch(Exception e){}
1
  • Perhaps your account doesn't have access rights to the User object? Commented Jul 12, 2015 at 19:42

1 Answer 1

4

I used the Chrome Postman plugin to POST the following:

POST request to Salesforce REST API

Note that the resource URL was set to: (I'm assuming you are on AP1 based the the pod identifier in the ProfileId).

https://na5.salesforce.com/services/data/v29.0/sobjects/User

I got the response:

[
    {
        "message": "Duplicate Username.<br>The username already exists in this or another Salesforce organization. Usernames must be unique across all Salesforce organizations. To resolve, use a different username (it doesn't need to match the user's email address). ",
        "errorCode": "DUPLICATE_USERNAME",
        "fields": [
            "Username"
        ]
    }
]

Which is fine for testing purposes. It would have probably worked with a different username and free licenses.

Please confirm that your PostMethod URL is set to:

https://ap1.salesforce.com/services/data/v29.0/sobjects/User

In particular, check that there is no trailing slash on instanceURL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.