2015-07-12 110 views
1

我正尝试在Java客户端上使用REST API在SFDC中创建用户。 请在下面看到我的代码,并帮助我了解为什么我收到以下错误信息:如何使用REST API创建SalesForce'用户'?

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){} 
+0

也许您的帐户无权访问用户对象? – superfell

回答

1

我使用Chrome的邮差插件张贴如下:

POST request to Salesforce REST API

请注意,资源URL被设置为:(我假设你在AP1基于pod identifier在ProfileId中)。

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

我得到的回应:

[ 
    { 
     "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" 
     ] 
    } 
] 

这很好用于测试目的。它可能会使用不同的用户名和免费许可证。

请确认您的PostMethod URL设置为:

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

特别是要检查有上instanceURL没有尾随斜线。