2015-07-12 56 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沒有尾隨斜線。