//認証用ヘッダー
h={ "X-Sansan-Api-Key" : input.SansanAPIKey };
//リクエストURL
//範囲(me|all)
range="all";
//パラメーターのエンコード
encodedEmail=encodeUrl(email);
//リクエスト送信
r = getUrl(u + "?range=" + range + "&email=" + encodedEmail,h,false);
//レスポンスの取得
responseText=r;
responseStatusCode=r.get("statusCode");
info responseText;
//正常に取得できた場合(ステータスコードはレスポンスに含まれていない)
if(responseStatusCode == null)
{
//CRMデータ更新用マップ
m=map();
//複数ある場合も最初のデータのみ取得
d=responseText.executeXPath("/root/data[1]").toXmlList();
//属性情報の取得
lastName = d.toString().executeXPath("/data/lastName/text()");
firstName = d.toString().executeXPath("/data/firstName/text()");
companyName = d.toString().executeXPath("/data/companyName/text()");
departmentName = d.toString().executeXPath("/data/departmentName/text()");
title = d.toString().executeXPath("/data/title/text()");
tel = d.toString().executeXPath("/data/tel/text()");
mobile = d.toString().executeXPath("/data/mobile/text()");
fax = d.toString().executeXPath("/data/fax/text()");
postalCode = d.toString().executeXPath("/data/postalCode/text()");
prefecture = d.toString().executeXPath("/data/prefecture/text()");
city = d.toString().executeXPath("/data/city/text()");
street = d.toString().executeXPath("/data/street/text()");
building = d.toString().executeXPath("/data/building/text()");
url = d.toString().executeXPath("/data/url/text()");
//更新用マップに情報をセット
m.put("Last_Name",lastName);
m.put("First_Name",firstName);
m.put("Company",companyName);
m.put("Title",departmentName + " " + title);
m.put("Phone",tel);
m.put("Mobile",mobile);
m.put("Fax",fax);
m.put("Zip_Code",postalCode);
m.put("State",prefecture);
m.put("City",city);
m.put("Street",street + " " + building);
m.put("Web_site",url);
//CRMデータの更新
updateR = zoho.crm.updateRecord("Leads",leadID,m);
info updateR;
if(updateR.get("message").contains("successfully"))
{
message="更新しました";
}
else
{
message=updateR.get("message");
}
return message;
}
//エラーが発生した場合
else
{
return "Sansanからの情報の取得中にエラーが発生しました、エラーコード:" + responseStatusCode + responseText;
}