//認証用ヘッダー
h={ "X-Sansan-Api-Key" : input.SansanAPIKey };
//リクエストURL
u="https://api.sansan.com/v1/bizCards/search";
//範囲(me|all)
range="all";
//パラメーターのエンコード
encodedEmail=encodeUrl(input.email);
//リクエスト送信
r = getUrl(u + "?range=" + range + "&email=" + encodedEmail,h,false);
//レスポンスの取得
responseText=r.get("responseText");
responseCode=r.get("responseCode");
info responseText;
//正常に取得できた場合
if(responseCode == "200")
{
//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",input.leadID.toString(),m);
info updateR;
if(updateR.get("message").contains("successfully"))
{
message="更新しました";
}
else
{
message=updateR.get("message");
}
return message;
}
//エラーが発生した場合
else
{
return "Sansanからの情報の取得中にエラーが発生しました";
}