PHP 客户端库 - 示例
下面是一些示例代码,可以帮助您更好地理解和使用PHP客户端库。
模块 API
获取模块列表
try{
$ins=ZCRMRestClient::getInstance();
$moduleArr=$ins->getAllModules()->getData();
foreach ($moduleArr as $module)
{
echo "ModuleName:".$module->getModuleName();
echo "SingLabel:".$module->getSingularLabel();
echo "PluLabel:".$module->getPluralLabel();
echo "BusinesscardLimit:".$module->getBusinessCardFieldLimit();
echo "ApiName:".$module->getAPIName();
$fields=$module->getFields();
if($fields==null)
{
continue;
}
foreach ($fields as $field)
{
echo $field->getApiName().", ";
echo $field->getLength().", ";
echo $field->IsVisible().", ";
echo $field->getFieldLabel().", ";
echo $field->getCreatedSource().", ";
echo $field->isMandatory().", ";
echo $field->getSequenceNumber().", ";
echo $field->isReadOnly().", ";
echo $field->getDataType().", ";
echo $field->getId().", ";
echo $field->isCustomField().", ";
echo $field->isBusinessCardSupported().", ";
echo $field->getDefaultValue().", ";
}
}
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}
元数据 API
模块元数据
try{
$ins=ZCRMRestClient::getInstance();
$apiResponse=$ins->getModule("Leads");//模块 API 名称
$module=$apiResponse->getData();
echo "ModuleName:".$module->getModuleName();
echo "SingLabel:".$module->getSingularLabel();
echo "PluLabel:".$module->getPluralLabel();
echo "BusinesscardLimit:".$module->getBusinessCardFieldLimit();
echo "ApiName:".$module->getAPIName();
$fields=$module->getFields();
if($fields==null)
{
continue;
}
foreach ($fields as $field)
{
echo $field->getApiName().", ";
echo $field->getLength().", ";
echo $field->IsVisible().", ";
echo $field->getFieldLabel().", ";
echo $field->getCreatedSource().", ";
echo $field->isMandatory().", ";
echo $field->getSequenceNumber().", ";
echo $field->isReadOnly().", ";
echo $field->getDataType().", ";
echo $field->getId().", ";
echo $field->isCustomField().", ";
echo $field->isBusinessCardSupported().", ";
echo $field->getDefaultValue().", ";
}
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}字段元数据
try{
$moduleIns=ZCRMModule::getInstance(“Leads”);
$apiResponse=$moduleIns->getAllFields();
$fields=$apiResponse->getData();
foreach ($fields as $field)
{
echo $field->getApiName().", ";
echo $field->getLength().", ";
echo $field->IsVisible().", ";
echo $field->getFieldLabel().", ";
echo $field->getCreatedSource().", ";
echo $field->isMandatory().", ";
echo $field->getSequenceNumber().", ";
echo $field->isReadOnly().", ";
echo $field->getDataType().", ";
echo $field->getId().", ";
echo $field->isCustomField().", ";
echo $field->isBusinessCardSupported().", ";
$fieldLayoutPerm=$field->getFieldLayoutPermissions();
foreach ($fieldLayoutPerm as $perm)
{
echo $perm.", ";
}
$lookupField=$field->getLookupField();
if($lookupField!=null)
{
echo $lookupField->getModule().", ";
echo $lookupField->getDisplayLabel().", ";
echo $lookupField->getId().", ";
}
$pickListFields=$field->getPickListFieldValues();
foreach ($pickListFields as $pickList)
{
echo $pickList->getDisplayValue().", ";
echo $pickList->getSequenceNumber().", ";
echo $pickList->getActualValue().", ";
echo $pickList->getMaps().", ";
}
echo $field->isUniqueField().", ";
echo $field->isCaseSensitive().", ";
echo $field->isCurrencyField().", ";
echo $field->getPrecision().", ";
echo $field->getRoundingOption().", ";
echo $field->isFormulaField().", ";
echo $field->getFormulaReturnType().", ";
echo $field->getFormulaExpression().", ";
echo $field->isAutoNumberField().", ";
echo $field->getPrefix().", ";
echo $field->getSuffix().", ";
echo $field->getStartNumber().", ";
echo $field->getDecimalPlace().", ";
$convertMap=$field->getConvertMapping();
if($convertMap!=null)
{
foreach ($convertMap as $key=>$value)
{
echo $key.":".$value;
}
}
}
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}基于ID获取字段
try{
$moduleIns=ZCRMModule::getInstance(“Leads”);
$apiResponse=$moduleIns->getFieldDetails(410405000000351019);//字段 ID
$field=$apiResponse->getData();
echo $field->getApiName().", ";
echo $field->getLength().", ";
echo $field->IsVisible().", ";
echo $field->getFieldLabel().", ";
echo $field->getCreatedSource().", ";
echo $field->isMandatory().", ";
echo $field->getSequenceNumber().", ";
echo $field->isReadOnly().", ";
echo $field->getDataType().", ";
echo $field->getId().", ";
echo $field->isCustomField().", ";
echo $field->isBusinessCardSupported().", ";
$fieldLayoutPerm=$field->getFieldLayoutPermissions();
foreach ($fieldLayoutPerm as $perm)
{
echo $perm.", ";
}
$lookupField=$field->getLookupField();
if($lookupField!=null)
{
echo $lookupField->getModule().", ";
echo $lookupField->getDisplayLabel().", ";
echo $lookupField->getId().", ";
}
$pickListFields=$field->getPickListFieldValues();
foreach ($pickListFields as $pickList)
{
echo $pickList->getDisplayValue().", ";
echo $pickList->getSequenceNumber().", ";
echo $pickList->getActualValue().", ";
echo $pickList->getMaps().", ";
}
echo $field->isUniqueField().", ";
echo $field->isCaseSensitive().", ";
echo $field->isCurrencyField().", ";
echo $field->getPrecision().", ";
echo $field->getRoundingOption().", ";
echo $field->isFormulaField().", ";
echo $field->getFormulaReturnType().", ";
echo $field->getFormulaExpression().", ";
echo $field->isAutoNumberField().", ";
echo $field->getPrefix().", ";
echo $field->getSuffix().", ";
echo $field->getStartNumber().", ";
echo $field->getDecimalPlace().", ";
$convertMap=$field->getConvertMapping();
if($convertMap!=null)
{
foreach ($convertMap as $key=>$value)
{
echo $key.":".$value;
}
}
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}基于ID获取布局
$zcrmModuleIns = ZCRMModule::getInstance("Products");
$apiResponse= $zcrmModuleIns->getLayoutDetails(410405000001021001);//布局 ID
$layout =$apiResponse->getData();
Here $layout is ZCRMLayout instance布局
$zcrmModuleIns = ZCRMModule::getInstance("Products");
$apiResponse= $zcrmModuleIns->getAllLayouts();
$layouts =$apiResponse->getData();
Here $layouts is an array of ZCRMLayout instances相关列表
$zcrmModuleIns = ZCRMModule::getInstance("Leads");
$apiResponse= $zcrmModuleIns->getAllRelatedLists();
$relatedLists =$apiResponse->getData();
Here $relatedLists is the array of ZCRMModuleRelatedList instance基于ID获取相关列表
try{
$moduleInstance=ZCRMModule::getInstance("Leads");
$responseIns=$moduleInstance->getRelatedListDetails(410405000000002730);
$relatedList=$responseIns->getData();
echo $relatedList->getModule();
echo $relatedList->getId();
echo $relatedList->getName();
echo $relatedList->getDisplayLabel();
echo $relatedList->getApiName();
echo $relatedList->isVisible();
echo $relatedList->getHref();
echo $relatedList->getType();
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}自定义视图
$zcrmModuleIns = ZCRMModule::getInstance("Products");
$apiResponse=$zcrmModuleIns->getAllCustomViews();
$zcrmCustomViews=$apiResponse->getData();
Here $zcrmCustomViews is an array of ZCRMCustomView instances基于ID获取自定义视图
$zcrmModuleIns = ZCRMModule::getInstance("Products");
$apiResponse=$zcrmModuleIns->getCustomView(410405000005108011);//custom view ID
$zcrmCustomView=$apiResponse->getData();
Here $zcrmCustomView is an instance of ZCRMCustomView获取所有职位
try{
$response=ZCRMOrganization::getInstance()->getAllRoles();
$roles=$response->getData();
foreach ($roles as $role)
{
echo $role->getId();
echo $role->getName();
echo $role->getLabel();
echo $role->isAdminRole();
$reportingTo=$role->getReportingTo();
if($reportingTo!=null)
{
echo $reportingTo->getId();
echo $reportingTo->getName();
}
}
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}获取所有角色
try{
$response=ZCRMOrganization::getInstance()->getAllProfiles();
$profiles=$response->getData();
foreach ($profiles as $profile)
{
echo $profile->getId();
echo $profile->getName();
echo $profile->getCreatedTime();
echo $profile->getModifiedTime();
echo $profile->getDescription();
echo $profile->getCategory();
$createdBy=$profile->getCreatedBy();
if($createdBy!=null)
{
echo $createdBy->getId();
echo $createdBy->getName();
}
$modifiedBy=$profile->getModifiedBy();
if($modifiedBy!=null)
{
echo $modifiedBy->getId();
echo $modifiedBy->getName();
}
}
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}更新自定义视图设置
try{
$moduleInstance=ZCRMModule::getInstance("Leads");
$customViewInstance=ZCRMCustomView::getInstance("Leads",410405000001077005);
$customViewInstance->setSortBy("City");
$customViewInstance->setSortOrder("desc");
$responseIns=$moduleInstance->updateCustomView($customViewInstance);
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}更新模块设置
try{
$moduleInstance=ZCRMModule::getInstance("Leads");
$businessCards=array("Email","Phone","Fax","Mobile","Industry");
$moduleInstance->setBusinessCardFields($businessCards);
$moduleInstance->setPerPage(20);
$moduleInstance->setDefaultCustomViewId(410405000001077005);
$relatedListProp=ZCRMRelatedListProperties::getInstance();
$relFields=array("First_Name","Last_Name","Company","Email","Lead_Source","Lead_Status","Phone");
$relatedListProp->setFields($relFields);
$relatedListProp->setSortOrder('asc');
$relatedListProp->setSortBy('Company');
$moduleInstance->setRelatedListProperties($relatedListProp);
$responseIns=$moduleInstance->updateModuleSettings($moduleInstance);
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}
用户 API
获取用户
try{
$bulkAPIResponse=ZCRMOrganization::getInstance()->getAllUsers();
$users=$bulkAPIResponse->getData();
foreach($users as $userInstance)
{
echo $userInstance->getCountry();
$roleInstance=$userInstance->getRole();
echo $roleInstance->getId();
echo $roleInstance->getName();
$customizeInstance=$userInstance->getCustomizeInfo();
if($customizeInstance!=null)
{
echo $customizeInstance->getNotesDesc();
echo $customizeInstance->getUnpinRecentItem();
echo $customizeInstance->isToShowRightPanel();
echo $customizeInstance->isBcView();
echo $customizeInstance->isToShowHome();
echo $customizeInstance->isToShowDetailView();
}
echo $userInstance->getCity();
echo $userInstance->getSignature();
echo $userInstance->getNameFormat();
echo $userInstance->getLanguage();
echo $userInstance->getLocale();
echo $userInstance->isPersonalAccount();
echo $userInstance->getDefaultTabGroup();
echo $userInstance->getAlias();
echo $userInstance->getStreet();
$themeInstance=$userInstance->getTheme();
if($themeInstance!=null)
{
echo $themeInstance->getNormalTabFontColor();
echo $themeInstance->getNormalTabBackground();
echo $themeInstance->getSelectedTabFontColor();
echo $themeInstance->getSelectedTabBackground();
}
echo $userInstance->getState();
echo $userInstance->getCountryLocale();
echo $userInstance->getFax();
echo $userInstance->getFirstName();
echo $userInstance->getEmail();
echo $userInstance->getZip();
echo $userInstance->getDecimalSeparator();
echo $userInstance->getWebsite();
echo $userInstance->getTimeFormat();
$profile= $userInstance->getProfile();
echo $profile->getId();
echo $profile->getName();
echo $userInstance->getMobile();
echo $userInstance->getLastName();
echo $userInstance->getTimeZone();
echo $userInstance->getZuid();
echo $userInstance->isConfirm();
echo $userInstance->getFullName();
echo $userInstance->getPhone();
echo $userInstance->getDob();
echo $userInstance->getDateFormat();
echo $userInstance->getStatus();
}
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}基于ID获取单个用户
try{
$apiResponse=ZCRMOrganization::getInstance()->getUser($userId); // $userId - 需要获取数据的用户ID。
$users=array($apiResponse->getData());
foreach($users as $userInstance)
{
echo $userInstance->getCountry();
$roleInstance=$userInstance->getRole();
echo $roleInstance->getId();
echo $roleInstance->getName();
$customizeInstance=$userInstance->getCustomizeInfo();
if($customizeInstance!=null)
{
echo $customizeInstance->getNotesDesc();
echo $customizeInstance->getUnpinRecentItem();
echo $customizeInstance->isToShowRightPanel();
echo $customizeInstance->isBcView();
echo $customizeInstance->isToShowHome();
echo $customizeInstance->isToShowDetailView();
}
echo $userInstance->getCity();
echo $userInstance->getSignature();
echo $userInstance->getNameFormat();
echo $userInstance->getLanguage();
echo $userInstance->getLocale();
echo $userInstance->isPersonalAccount();
echo $userInstance->getDefaultTabGroup();
echo $userInstance->getAlias();
echo $userInstance->getStreet();
$themeInstance=$userInstance->getTheme();
if($themeInstance!=null)
{
echo $themeInstance->getNormalTabFontColor();
echo $themeInstance->getNormalTabBackground();
echo $themeInstance->getSelectedTabFontColor();
echo $themeInstance->getSelectedTabBackground();
}
echo $userInstance->getState();
echo $userInstance->getCountryLocale();
echo $userInstance->getFax();
echo $userInstance->getFirstName();
echo $userInstance->getEmail();
echo $userInstance->getZip();
echo $userInstance->getDecimalSeparator();
echo $userInstance->getWebsite();
echo $userInstance->getTimeFormat();
$profile= $userInstance->getProfile();
echo $profile->getId();
echo $profile->getName();
echo $userInstance->getMobile();
echo $userInstance->getLastName();
echo $userInstance->getTimeZone();
echo $userInstance->getZuid();
echo $userInstance->isConfirm();
echo $userInstance->getFullName();
echo $userInstance->getPhone();
echo $userInstance->getDob();
echo $userInstance->getDateFormat();
echo $userInstance->getStatus();
}
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}获取所有管理员用户
try{
$bulkAPIResponse=ZCRMOrganization::getInstance()->getAllAdminUsers();
$users=$bulkAPIResponse->getData();
foreach($users as $userInstance)
{
echo $userInstance->getCountry();
$roleInstance=$userInstance->getRole();
echo $roleInstance->getId();
echo $roleInstance->getName();
$customizeInstance=$userInstance->getCustomizeInfo();
if($customizeInstance!=null)
{
echo $customizeInstance->getNotesDesc();
echo $customizeInstance->getUnpinRecentItem();
echo $customizeInstance->isToShowRightPanel();
echo $customizeInstance->isBcView();
echo $customizeInstance->isToShowHome();
echo $customizeInstance->isToShowDetailView();
}
echo $userInstance->getCity();
echo $userInstance->getSignature();
echo $userInstance->getNameFormat();
echo $userInstance->getLanguage();
echo $userInstance->getLocale();
echo $userInstance->isPersonalAccount();
echo $userInstance->getDefaultTabGroup();
echo $userInstance->getAlias();
echo $userInstance->getStreet();
$themeInstance=$userInstance->getTheme();
if($themeInstance!=null)
{
echo $themeInstance->getNormalTabFontColor();
echo $themeInstance->getNormalTabBackground();
echo $themeInstance->getSelectedTabFontColor();
echo $themeInstance->getSelectedTabBackground();
}
echo $userInstance->getState();
echo $userInstance->getCountryLocale();
echo $userInstance->getFax();
echo $userInstance->getFirstName();
echo $userInstance->getEmail();
echo $userInstance->getZip();
echo $userInstance->getDecimalSeparator();
echo $userInstance->getWebsite();
echo $userInstance->getTimeFormat();
$profile= $userInstance->getProfile();
echo $profile->getId();
echo $profile->getName();
echo $userInstance->getMobile();
echo $userInstance->getLastName();
echo $userInstance->getTimeZone();
echo $userInstance->getZuid();
echo $userInstance->isConfirm();
echo $userInstance->getFullName();
echo $userInstance->getPhone();
echo $userInstance->getDob();
echo $userInstance->getDateFormat();
echo $userInstance->getStatus();
}
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}获取所有活跃的用户
try{
$bulkAPIResponse=ZCRMOrganization::getInstance()->getAllActiveUsers();
$users=$bulkAPIResponse->getData();
foreach($users as $userInstance)
{
echo $userInstance->getCountry();
$roleInstance=$userInstance->getRole();
echo $roleInstance->getId();
echo $roleInstance->getName();
$customizeInstance=$userInstance->getCustomizeInfo();
if($customizeInstance!=null)
{
echo $customizeInstance->getNotesDesc();
echo $customizeInstance->getUnpinRecentItem();
echo $customizeInstance->isToShowRightPanel();
echo $customizeInstance->isBcView();
echo $customizeInstance->isToShowHome();
echo $customizeInstance->isToShowDetailView();
}
echo $userInstance->getCity();
echo $userInstance->getSignature();
echo $userInstance->getNameFormat();
echo $userInstance->getLanguage();
echo $userInstance->getLocale();
echo $userInstance->isPersonalAccount();
echo $userInstance->getDefaultTabGroup();
echo $userInstance->getAlias();
echo $userInstance->getStreet();
$themeInstance=$userInstance->getTheme();
if($themeInstance!=null)
{
echo $themeInstance->getNormalTabFontColor();
echo $themeInstance->getNormalTabBackground();
echo $themeInstance->getSelectedTabFontColor();
echo $themeInstance->getSelectedTabBackground();
}
echo $userInstance->getState();
echo $userInstance->getCountryLocale();
echo $userInstance->getFax();
echo $userInstance->getFirstName();
echo $userInstance->getEmail();
echo $userInstance->getZip();
echo $userInstance->getDecimalSeparator();
echo $userInstance->getWebsite();
echo $userInstance->getTimeFormat();
$profile= $userInstance->getProfile();
echo $profile->getId();
echo $profile->getName();
echo $userInstance->getMobile();
echo $userInstance->getLastName();
echo $userInstance->getTimeZone();
echo $userInstance->getZuid();
echo $userInstance->isConfirm();
echo $userInstance->getFullName();
echo $userInstance->getPhone();
echo $userInstance->getDob();
echo $userInstance->getDateFormat();
echo $userInstance->getStatus();
}
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}获取所有休眠的用户
try{
$bulkAPIResponse=ZCRMOrganization::getInstance()->getAllDeactiveUsers();
$users=$bulkAPIResponse->getData();
foreach($users as $userInstance)
{
echo $userInstance->getCountry();
$roleInstance=$userInstance->getRole();
echo $roleInstance->getId();
echo $roleInstance->getName();
$customizeInstance=$userInstance->getCustomizeInfo();
if($customizeInstance!=null)
{
echo $customizeInstance->getNotesDesc();
echo $customizeInstance->getUnpinRecentItem();
echo $customizeInstance->isToShowRightPanel();
echo $customizeInstance->isBcView();
echo $customizeInstance->isToShowHome();
echo $customizeInstance->isToShowDetailView();
}
echo $userInstance->getCity();
echo $userInstance->getSignature();
echo $userInstance->getNameFormat();
echo $userInstance->getLanguage();
echo $userInstance->getLocale();
echo $userInstance->isPersonalAccount();
echo $userInstance->getDefaultTabGroup();
echo $userInstance->getAlias();
echo $userInstance->getStreet();
$themeInstance=$userInstance->getTheme();
if($themeInstance!=null)
{
echo $themeInstance->getNormalTabFontColor();
echo $themeInstance->getNormalTabBackground();
echo $themeInstance->getSelectedTabFontColor();
echo $themeInstance->getSelectedTabBackground();
}
echo $userInstance->getState();
echo $userInstance->getCountryLocale();
echo $userInstance->getFax();
echo $userInstance->getFirstName();
echo $userInstance->getEmail();
echo $userInstance->getZip();
echo $userInstance->getDecimalSeparator();
echo $userInstance->getWebsite();
echo $userInstance->getTimeFormat();
$profile= $userInstance->getProfile();
echo $profile->getId();
echo $profile->getName();
echo $userInstance->getMobile();
echo $userInstance->getLastName();
echo $userInstance->getTimeZone();
echo $userInstance->getZuid();
echo $userInstance->isConfirm();
echo $userInstance->getFullName();
echo $userInstance->getPhone();
echo $userInstance->getDob();
echo $userInstance->getDateFormat();
echo $userInstance->getStatus();
}
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}创建用户
try{
$user1=ZCRMUser::getInstance(null,null);
$user1->setLastName("user1");
$user1->setEmail("user1@email.com");
$profile=ZCRMProfile::getInstance(410405000000015975,"Standard");
$user1->setProfile($profile);
$role=ZCRMRole::getInstance(410405000000015969,"Manager");
$user1->setRole($role);
$user1->setCity("Chennai");
$responseIns=ZCRMOrganization::getInstance()->createUser($user1);
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}
catch(ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}
机构 API
获取机构详情
try{
$restIns=ZCRMRestClient::getInstance();
$res=$restIns->getOrganizationDetails();
$orgIns=$res->getData();
echo $orgIns->getCompanyName();
echo $orgIns->getOrgId();
echo $orgIns->getCountryCode();
echo $orgIns->getCountry();
echo $orgIns->getCurrencyLocale();
echo $orgIns->getFax();
echo $orgIns->getAlias();
echo $orgIns->getDescription();
echo $orgIns->getStreet();
echo $orgIns->getCity();
echo $orgIns->getState();
echo $orgIns->getZgid();
echo $orgIns->getWebSite();
echo $orgIns->getPrimaryEmail();
echo $orgIns->getPrimaryZuid();
echo $orgIns->getIsoCode();
echo $orgIns->getPhone();
echo $orgIns->getMobile();
echo $orgIns->getEmployeeCount();
echo $orgIns->getCurrencySymbol();
echo $orgIns->getTimeZone();
echo $orgIns->getMcStatus();
echo $orgIns->isGappsEnabled();
echo $orgIns->isPaidAccount();
echo $orgIns->getPaidExpiry();
echo $orgIns->getPaidType();
echo $orgIns->getTrialType();
echo $orgIns->getTrialExpiry();
echo $orgIns->getZipCode();
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getExceptionDetails();
echo $e->getMessage();
echo $e->getTraceAsString();
}
记录 API
获取记录列表
$zcrmModuleIns = ZCRMModule::getInstance("Contacts");
$bulkAPIResponse=$zcrmModuleIns->getRecords();
$recordsArray = $bulkAPIResponse->getData()); // $recordsArray - ZCRMRecord 实例数组插入记录
$zcrmModuleIns = ZCRMModule::getInstance("Contacts");
$bulkAPIResponse=$zcrmModuleIns->createRecords($recordsArray); // $recordsArray - 包含创建所需数据的 ZCRMRecord 实例数组。
$entityResponses = $bulkAPIResponse->getEntityResponses();
foreach($entityResponses as $eachEntityResponse)
{
if(“success”==$entityResponse->getStatus())
{
echo "Status:".$entityResponse->getStatus();
echo "Message:".$entityResponse->getMessage();
echo "Code:".$entityResponse->getCode();
$createdRecordInstance=$entityResponse->getData();
echo "EntityID:".$createdRecordInstance->getEntityId();
echo "moduleAPIName:".$createdRecordInstance->getModuleAPIName();
….
}
}
Sample Invoice record instance with filled data
$record=ZCRMRecord::getInstance("Invoices",null);
$record->setFieldValue("Subject","Iphone sale to John");
$record->setFieldValue("Account_Name","410405000001016021");
$productInstance=ZCRMRecord::getInstance("Products",410405000001108011);
$lineItem=ZCRMInventoryLineItem::getInstance($productInstance);
$taxInstance1=ZCRMTax::getInstance("Sales Tax");
$taxInstance1->setPercentage(2);
$taxInstance1->setValue(10);
$lineItem->addLineTax($taxInstance1);
$taxInstance1=ZCRMTax::getInstance("Vat");
$taxInstance1->setPercentage(12);
$taxInstance1->setValue(60);
$lineItem->addLineTax($taxInstance1);
$lineItem->setQuantity(100);
$lineItem->setDiscount(0.5);
$record->addLineItem($lineItem);更新记录
$idList=array(410405000001076001,410405000001021027,410405000000497012);
$zcrmModuleIns = ZCRMModule::getInstance("Contacts");
$bulkAPIResponse=$zcrmModuleIns->updateRecords($idList,"Account_Name","NewAccount");
$entityResponses = $bulkAPIResponse->getEntityResponses();
foreach($entityResponses as $eachEntityResponse)
{
if(“success”==$entityResponse->getStatus())
{
echo "Status:".$entityResponse->getStatus();
echo "Message:".$entityResponse->getMessage();
echo "Code:".$entityResponse->getCode();
$recordIns=$entityResponse->getData();
echo "EntityID:".$recordIns->getEntityId();
echo "moduleAPIName:".$recordIns->getModuleAPIName();
….
}
}插入或更新(Upsert)
$zcrmModuleIns = ZCRMModule::getInstance("Contacts");
$bulkAPIResponse=$zcrmModuleIns->upsertRecords($recordsArray); // $recordsArray - 包含了upsert所需数据的 ZCRMRecord 实例数组。
$entityResponses = $bulkAPIResponse->getEntityResponses();
foreach($entityResponses as $eachEntityResponse)
{
if(“success”==$entityResponse->getStatus())
{
echo "Status:".$entityResponse->getStatus();
echo "Message:".$entityResponse->getMessage();
echo "Code:".$entityResponse->getCode();
$upsertData=$entityResponse->getUpsertDetails();
echo "UPSERT_ACTION:".$upsertData[“action”];
echo "UPSERT_DUPLICATE_FIELD:".$upsertData[“duplicate_field”];
$createdRecordInstance=$entityResponse->getData();
echo "EntityID:".$createdRecordInstance->getEntityId();
echo "moduleAPIName:".$createdRecordInstance->getModuleAPIName();
….
}
}删除记录 - 删除多个记录
$idList=array(410405000001076001,410405000001021027,410405000000497012);
$zcrmModuleIns = ZCRMModule::getInstance("Contacts");
$bulkAPIResponse=$zcrmModuleIns->deleteRecords($idList); // $idList - 联系人 ID 列表
$entityResponses = $bulkAPIResponse->getEntityResponses();
foreach($entityResponses as $eachEntityResponse)
{
if(“success”==$entityResponse->getStatus())
{
echo "Status:".$entityResponse->getStatus();
echo "Message:".$entityResponse->getMessage();
echo "Code:".$entityResponse->getCode();
}
}获取已删除记录列表
获取所有被删除的记录
$response=ZCRMModule::getInstance($moduleAPIName)->getAllDeletedRecords(); // $moduleAPIName - 模块的 API 名称。
获取回收站中的所有记录
$response=ZCRMModule::getInstance($moduleAPIName)->getRecycleBinRecords();
获取永久删除的所有记录
$response=ZCRMModule::getInstance($moduleAPIName)->getPermanentlyDeletedRecords();
$records=$response->getData();
try{
foreach ($records as $record){
echo $record->getEntityId();
echo $record->getDisplayName();
echo $record->getType();
$createdBy=$record->getCreatedBy();
$deletedBy=$record->getDeletedBy();
if($createdBy!=null)
{
echo $createdBy->getId();
}
if($deletedBy!=null)
{
echo $deletedBy->getId();
}
echo $record->getDeletedTime();
}
}
catch (ZCRMException $ex)
{
echo $ex->getMessage();
echo $ex->getExceptionCode();
echo $ex->getFile();
}搜索记录
$zcrmModuleIns = ZCRMModule::getInstance("Products");
$bulkAPIResponse=$zcrmModuleIns->searchRecords("ip");
$records = $bulkAPIResponse->getData(); // $records - ZCRMRecord 实例数组。
单个记录 API
获取特定记录
$apiResponse=ZCRMModule::getInstance('Leads')->getRecord(410405000001519001); // 410405000001519001 - 线索 ID
$record=$apiResponse->getData();
echo $record->getEntityId();
echo $record->getModuleApiName();
echo $record->getLookupLabel();
echo $record->getCreatedBy()->getId();
echo $record->getModifiedBy()->getId();
echo $record->getOwner()->getId();
echo $record->getCreatedTime();
echo $record->getModifiedTime();
$map=$record->getData();
foreach ($map as $key=>$value)
{
if($value instanceof ZCRMRecord)
{
echo "\n".$value->getEntityId().":".$value->getModuleApiName().":".$value->getLookupLabel();
}
else
{
echo $key.":".$value;
}
}更新特定记录
$zcrmRecordIns = ZCRMRecord::getInstance("Leads", 410405000001304021);
$zcrmRecordIns->setFieldValue("Product_Name", “iPhone 6s Plus”);
$apiResponse=$zcrmRecordIns->update();插入新记录
$zcrmRecordIns = ZCRMRecord::getInstance("Products",null);
$ownerIns = ZCRMUser::getInstance(410405000000085001,null);
$zcrmRecordIns->setOwner($ownerIns);
$zcrmRecordIns->setFieldValue(“Product_Name”, “iPhone 6 Plus”);
$zcrmRecordIns->setFieldValue(“Product_Code”, “iP6P");
$apiResponse=$zcrmRecordIns->create();删除特定记录
$zcrmRecordIns = ZCRMRecord::getInstance("Products", 410405000001042005); //记录 ID
$apiResponse=$zcrmRecordIns->delete();转化线索
$record=ZCRMRecord::getInstance("Leads",410405000001518001); // 410405000001518001 - 记录 ID。
$modIns=ZCRMModule::getInstance("Deals");
$record_deal=$modIns->getRecord(410405000001519001)->getData(); // 410405000001519001 - 商机 ID。
$responseMap=$record->convert($record_deal,410405000001516001); // 410405000001516001 - 用户 ID
echo "Contact ID:".$responseMap['Contacts'];
if(isset($responseMap[“Accounts”]))
{
echo "Account ID:".$responseMap[“Accounts”];
}
if(isset($responseMap[“Deals”]))
{
echo "Deal ID:".$responseMap[“Deals”];
}
相关列表 API
获取相关的记录
$zcrmRecordIns = ZCRMRecord::getInstance(“Products", 410405000001108011);
$bulkAPIResponse=$zcrmRecordIns->getRelatedListRecords(“Deals”);
$relatedRecordsList=$bulkAPIResponse->getData()); // $relatedRecordsList - 与给定产品相关的ZCRMRecord实例数组。更新相关的记录
Try{
$parentRecord=ZCRMRecord::getInstance("Products", 410405000001446001);
$junctionRecord=ZCRMJunctionRecord::getInstance("Price_Books",
410405000001404743);
$junctionRecord->setRelatedData("list_price", 140);
$responseIns=$parentRecord->addRelation($junctionRecord);
echo "HTTP Code:".$responseIns->getHttpStatusCode();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
}解除链接
Try{
$parentRecord=ZCRMRecord::getInstance("Products", 410405000001446001);
$junctionRecord=ZCRMJunctionRecord::getInstance("Price_Books",
410405000001404743);
$responseIns=$parentRecord->removeRelation($junctionRecord);
echo "HTTP Code:".$responseIns->getHttpStatusCode();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails();
}catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
}
备注 API
创建相关备注
try{
$record=ZCRMRecord::getInstance("Leads",410405000001111007);
$responseIns=$record->getNotes(null,null,1,50);
$records=$responseIns->getData();
foreach ($records as $note)
{
echo "\n";
echo $note->getId();
echo $note->getTitle();
echo $note->getContent();
$parentRecord=$note->getParentRecord();
echo $parentRecord->getEntityId();
echo $note->getParentName();
echo $note->getParentId();
$createdBy=$note->getCreatedBy();
echo $createdBy->getId();
echo $createdBy->getName();
$modifiedBy=$note->getModifiedBy();
echo $modifiedBy->getId();
echo $modifiedBy->getName();
$owner=$note->getOwner();
echo $owner->getId();
echo $owner->getName();
echo $note->getCreatedTime();
echo $note->getModifiedTime();
echo $note->isVoiceNote();
echo $note->getSize();
$attchments=$note->getAttachments();
if($attchments!=null)
{
foreach ($attchments as $attchmentIns)
{
echo "\nATTACHMENTS::\n";
echo $attchmentIns->getId();
echo $attchmentIns->getFileName();
echo $attchmentIns->getFileType();
echo $attchmentIns->getSize();
echo $attchmentIns->getParentModule();
$parentRecord=$attchmentIns->getParentRecord();
echo $parentRecord->getEntityId();
echo $attchmentIns->getParentName();
echo $attchmentIns->getParentId();
$createdBy=$attchmentIns->getCreatedBy();
echo $createdBy->getId();
echo $createdBy->getName();
$modifiedBy=$attchmentIns->getModifiedBy();
echo $modifiedBy->getId();
echo $modifiedBy->getName();
$owner=$attchmentIns->getOwner();
echo $owner->getId();
echo $owner->getName();
echo $attchmentIns->getCreatedTime();
echo $attchmentIns->getModifiedTime();
}
}
}
}catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}添加备注
try{
$record=ZCRMRecord::getInstance('Accounts',410405000000497012);
$noteIns=ZCRMNote::getInstance($record);
$noteIns->setTitle("Title_API1");
$noteIns->setContent("This is test content");
$responseIns=$record->addNote($noteIns);
$zcrmNote=$responseIns->getData();
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
echo "Entity Id:".$zcrmNote->getId();
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}更新备注 - ZCRMNote
try{
$record=ZCRMRecord::getInstance('Accounts',410405000000497012); // 410405000000497012 - 客户 ID。
$noteIns=ZCRMNote::getInstance($record,410405000000498056); // , 410405000000498056 - 备注 ID。
$noteIns->setTitle("Title_API22..");
$noteIns->setContent("This is test content");
$responseIns=$record->updateNote($noteIns);
$zcrmNote=$responseIns->getData();
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
echo "Entity Id:".$zcrmNote->getId();
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}删除备注
try{
$record=ZCRMRecord::getInstance('Accounts',410405000000497012); // 410405000000497012 - 客户 ID
$noteIns=ZCRMNote::getInstance($record,410405000000498056); // 410405000000498056 - 备注 ID
$responseIns=$record->deleteNote($noteIns);
$zcrmNote=$responseIns->getData();
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}
catch (ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}
文件和附件 API
获取相关附件
try{
$record=ZCRMRecord::getInstance("Leads",410405000001111007);
$responseIns=$record->getAttachments(1,50);
$records=$responseIns->getData();
foreach ($records as $attchmentIns)
{
echo $attchmentIns->getId();
echo $attchmentIns->getFileName();
echo $attchmentIns->getFileType();
echo $attchmentIns->getSize();
echo $attchmentIns->getParentModule();
$parentRecord=$attchmentIns->getParentRecord();
echo $parentRecord->getEntityId();
echo $attchmentIns->getParentName();
echo $attchmentIns->getParentId();
$createdBy=$attchmentIns->getCreatedBy();
echo $createdBy->getId();
echo $createdBy->getName();
$modifiedBy=$attchmentIns->getModifiedBy();
echo $modifiedBy->getId();
echo $modifiedBy->getName();
$owner=$attchmentIns->getOwner();
echo $owner->getId();
echo $owner->getName();
echo $attchmentIns->getCreatedTime();
echo $attchmentIns->getModifiedTime();
}
}catch (ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}上传附件
try{
$record=ZCRMRecord::getInstance(“Leads”,”410405000001111007”);
$responseIns=$record->uploadAttachment($filePath); // $filePath - 要上传附件的绝对路径
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}catch(ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}下载附件
try{
$record=ZCRMRecord::getInstance(“Accounts”,410405000001519001);
$fileResponseIns=$record->downloadAttachment(410405000001519501); // 410405000001519501 - 附件 ID。
$fp=fopen($filePath.$fileResponseIns->getFileName(),"w"); // $filePath - 下载文件存储的绝对路径。
echo "HTTP Status Code:".$fileResponseIns->getHttpStatusCode();
echo "File Name:".$fileResponseIns->getFileName();
$stream=$fileResponseIns->getFileContent();
fputs($fp,$stream);
fclose($fp);
}catch (ZCRMException $e)
{
echo $e->getMessage();
echo $e->getExceptionCode();
echo $e->getCode();
}上传照片
try{
$record=ZCRMRecord::getInstance(“Leads”,”410405000001111007”);
$responseIns=$record->uploadPhoto($photoPath); // $photoPath - 照片上传的绝对路径。
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}catch(ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}下载照片
try{
$record=ZCRMRecord::getInstance(“Leads”,”410405000001111007”);
$fileResponseIns=$record->downloadPhoto();
echo "HTTP Status Code:".$fileResponseIns->getHttpStatusCode();
echo "File Name:".$fileResponseIns->getFileName();
$fp=fopen($filePath.$fileResponseIns->getFileName(),"w"); // $filePath - 下载照片存储的绝对路径。
$stream=$fileResponseIns->getFileContent();
fputs($fp,$stream);
fclose($fp);
}catch(ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
}