Hi I am using REST API to create new USER, when i am extracting the meta data using the


the label for 'Email' field is shown as 'E-mail' whereas on salesforce GUI it is 'Email' and the corresponding name for it is given as 'Email'

when i am executing the request i am getting a 'Bad Request' 400 error.

Please help

My code for building http request is

        public void createUser()
        DefaultHttpClient httpClient = new DefaultHttpClient();
        String json = "{ \"LastName\" : \"kumar\" , \"Alias\" : \"Shal\", \"Email\": \"shal@xyz.com\", \"Username\" : \"shailesh\" , \"CommunityNickname\" : \"shailesh\"}";

        StringEntity sentity = new StringEntity(json);

        String query1 = "/services/data/v20.0/sobjects/User/";
        HttpPost get1 = new HttpPost(environment + query1);
        get1.addHeader("Authorization", "OAuth " + accessToken);
        get1.addHeader("Content-Type", "application/json");

        HttpResponse response1 = httpClient.execute(get1);

i am able to create new Account and Contact using the same function but when i am creating the Users i am getting Bad Request so my JSON must only be wrong.

| improve this question | | | | |
  • post your actual api request. – superfell May 7 '13 at 5:02
  • Hi @superfell i have edited the question, i think my JSON is wrong but i am unable to findout what it is. can you please help me. – Shaiesh Pant May 7 '13 at 6:46
  • Have you got spare user licences on your org? Is the email address unique (shal@xyz.com has not been created as a user in any other org)? – Doug B May 7 '13 at 9:21
  • Hi @DougB yes the email id shal@xyz.com is unique, and yes i have spare user licences (i am new to Salesforce and i have a developer edition account, i have created only one user so i guess i have more user licences, please correct me if i am wrong) – Shaiesh Pant May 7 '13 at 12:51
  • The response body will have more details on what's wrong with the request, looks like you're missing some additional required fields. – superfell May 7 '13 at 14:22

Your Answer

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

Browse other questions tagged or ask your own question.