function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KoroyukiKoroyuki 

カスタマーポータルユーザでのWebServiceAPIの利用について

PartberWSDLをダウンロードし、Eclipse(java)を使ってWebServiceAPIを利用する時に、

管理者のユーザ名とパスワードを用いれば、login()に成功し、正しく動作できるのですが、

ここで管理者のユーザ名、パスワードではなく、カスタマーポータルユーザのユーザ名とパスワードで行うと

login()がうまくいきません。カスタマーポータルユーザでもうまくいく方法はないでしょうか。

 

アプリ側のユーザから、ログインをさせてAPIを実行させたいので、管理者で見にいくわけにはいきません。。

 

C#ですと、LoginScopeHeaderというのにportalId等を設定するところがあり、

いけそうな感じがするのですが、Javaだといろいろ調べてみても打開策が見つかりません。

(url:http://www.salesforce.com//us/developer/docs/api/Content/sforce_api_header_loginscopeheader.htm)

 

良い方法がありましたら、教えて頂きたいです。よろしくお願い致します。


 

Best Answer chosen by Admin (Salesforce Developers) 
tajimatajima

Javaでもほぼ同様です。
ログイン時のSOAPヘッダにportal Id と org Idをセットするのがポイントです。

 

 

package apisample; import java.rmi.RemoteException; import com.sforce.soap.enterprise.LoginResult; import com.sforce.soap.enterprise.LoginScopeHeader; import com.sforce.soap.enterprise.QueryOptions; import com.sforce.soap.enterprise.QueryResult; import com.sforce.soap.enterprise.SaveResult; import com.sforce.soap.enterprise.SessionHeader; import com.sforce.soap.enterprise.SforceServiceLocator; import com.sforce.soap.enterprise.SoapBindingStub; import com.sforce.soap.enterprise.fault.UnexpectedErrorFault; import com.sforce.soap.enterprise.sobject.Account; import com.sforce.soap.enterprise.sobject.SObject; /** * @author TAjima * */ public class Sample { /** ログインユーザ名 */ private static final String UN = "user@demo.com"; /** ログインパスワード */ private static final String PW = "password"; /** リクエストエンドポイントURL */ private static final String ENDPOINT_URL = "https://www.salesforce.com/services/Soap/c/18.0"; /** ポータルID */ private static final String PORTAL_ID = "06010000000NnXx"; /** 組織ID */ private static final String orgId = "00D10000000NXxx"; // APIコンテキスト private SoapBindingStub binding; /** * ログイン処理。 * * @return ログイン成功の場合はtrue、そうでなければfalse * @throws Exception */ private boolean login() throws Exception { LoginResult loginResult = null; try { // APIコンテキストの作成 SforceServiceLocator locator = new SforceServiceLocator(); locator.setSoapEndpointAddress(ENDPOINT_URL); binding = (SoapBindingStub) locator.getSoap(); // ポータルログインに必要な情報を入れるオブジェクト LoginScopeHeader lsh = new LoginScopeHeader(); lsh.setPortalId(PORTAL_ID); lsh.setOrganizationId(orgId); // SOAPヘッダにポータルへのログインに必要な情報をセット binding.setHeader( new SforceServiceLocator().getServiceName().getNamespaceURI(), "LoginScopeHeader", lsh); // ログイン処理 loginResult = binding.login(UN, PW); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Login fail."); return false; } System.out.println("Login was successful."); // APIサーバURLを取得して、SoapBindingStubオブジェクトにセットする binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl()); // セッションIDをSoapBindingStubオブジェクトにセットする SessionHeader sh = new SessionHeader(); sh.setSessionId(loginResult.getSessionId()); System.out.println("session id : " + loginResult.getSessionId()); binding.setHeader(new SforceServiceLocator().getServiceName() .getNamespaceURI(), "SessionHeader", sh); return true; } }

 

 

 

All Answers

tajimatajima

Javaでもほぼ同様です。
ログイン時のSOAPヘッダにportal Id と org Idをセットするのがポイントです。

 

 

package apisample; import java.rmi.RemoteException; import com.sforce.soap.enterprise.LoginResult; import com.sforce.soap.enterprise.LoginScopeHeader; import com.sforce.soap.enterprise.QueryOptions; import com.sforce.soap.enterprise.QueryResult; import com.sforce.soap.enterprise.SaveResult; import com.sforce.soap.enterprise.SessionHeader; import com.sforce.soap.enterprise.SforceServiceLocator; import com.sforce.soap.enterprise.SoapBindingStub; import com.sforce.soap.enterprise.fault.UnexpectedErrorFault; import com.sforce.soap.enterprise.sobject.Account; import com.sforce.soap.enterprise.sobject.SObject; /** * @author TAjima * */ public class Sample { /** ログインユーザ名 */ private static final String UN = "user@demo.com"; /** ログインパスワード */ private static final String PW = "password"; /** リクエストエンドポイントURL */ private static final String ENDPOINT_URL = "https://www.salesforce.com/services/Soap/c/18.0"; /** ポータルID */ private static final String PORTAL_ID = "06010000000NnXx"; /** 組織ID */ private static final String orgId = "00D10000000NXxx"; // APIコンテキスト private SoapBindingStub binding; /** * ログイン処理。 * * @return ログイン成功の場合はtrue、そうでなければfalse * @throws Exception */ private boolean login() throws Exception { LoginResult loginResult = null; try { // APIコンテキストの作成 SforceServiceLocator locator = new SforceServiceLocator(); locator.setSoapEndpointAddress(ENDPOINT_URL); binding = (SoapBindingStub) locator.getSoap(); // ポータルログインに必要な情報を入れるオブジェクト LoginScopeHeader lsh = new LoginScopeHeader(); lsh.setPortalId(PORTAL_ID); lsh.setOrganizationId(orgId); // SOAPヘッダにポータルへのログインに必要な情報をセット binding.setHeader( new SforceServiceLocator().getServiceName().getNamespaceURI(), "LoginScopeHeader", lsh); // ログイン処理 loginResult = binding.login(UN, PW); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Login fail."); return false; } System.out.println("Login was successful."); // APIサーバURLを取得して、SoapBindingStubオブジェクトにセットする binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl()); // セッションIDをSoapBindingStubオブジェクトにセットする SessionHeader sh = new SessionHeader(); sh.setSessionId(loginResult.getSessionId()); System.out.println("session id : " + loginResult.getSessionId()); binding.setHeader(new SforceServiceLocator().getServiceName() .getNamespaceURI(), "SessionHeader", sh); return true; } }

 

 

 

This was selected as the best answer
KoroyukiKoroyuki

返信ありがとうございます。

 

教えて頂いた方法で上手くいきました。

ありがとうございました!

 

しかし、Partnerでやっていたのですが、Enterpriseでないと無理なんでしょうかね。。