C# SDKのサンプルコード - RESTクライアント操作

組織の詳細の取得

/** To get Organization details */
public void GetOrganizationDetails()
{
    /** Get Organization Data */
    ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
    APIResponse response = restClient.GetOrganizationDetails();
    Console.WriteLine(response.HttpStatusCode);
    ZCRMOrganization organization = (ZCRMOrganization)response.Data;
    Console.WriteLine(organization.OrgId);
    Console.WriteLine(organization.Alias);
    Console.WriteLine(organization.City);
    Console.WriteLine(organization.CompanyName);
    Console.WriteLine(organization.Country);
    Console.WriteLine(organization.CountryCode);
    Console.WriteLine(organization.CurrencyLocale);
    Console.WriteLine(organization.CurrencySymbol);
    Console.WriteLine(organization.Description);
    Console.WriteLine(organization.EmployeeCount);
    Console.WriteLine(organization.Fax);
    Console.WriteLine(organization.GappsEnabled);
    Console.WriteLine(organization.IsoCode);
    Console.WriteLine(organization.McStatus);
    Console.WriteLine(organization.Mobile);
    Console.WriteLine(organization.Phone);
    Console.WriteLine(organization.PrimaryEmail);
    Console.WriteLine(organization.PrimaryZuid);
    Console.WriteLine(organization.State);
    Console.WriteLine(organization.Street);
    Console.WriteLine(organization.Timezone);
    Console.WriteLine(organization.Website);
    Console.WriteLine(organization.Zgid);
    Console.WriteLine(organization.ZipCode);
}
 
現在のユーザーのデータの取得

/** Get Current user data */
public void CurrentUser()
{
    ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
    APIResponse response = restClient.GetCurrentUser();
    Console.WriteLine(response.HttpStatusCode); //Based on API Response    
    ZCRMUser user = (ZCRMUser)response.Data;
    Console.WriteLine(user.Id);
    Console.WriteLine(user.ZuId);
    Console.WriteLine(user.Alias);
    Console.WriteLine(user.City);
    Console.WriteLine(user.Confirm);
    Console.WriteLine(user.Country);
    Console.WriteLine(user.CountryLocale);
    Console.WriteLine(user.CreatedTime);
    Console.WriteLine(user.DateFormat);
    Console.WriteLine(user.EmailId);
    Console.WriteLine(user.Fax);
    Console.WriteLine(user.FirstName);
    Console.WriteLine(user.FullName);
    Console.WriteLine(user.Language);
    Console.WriteLine(user.LastName);
    Console.WriteLine(user.Locale);
    Console.WriteLine(user.Mobile);
    Console.WriteLine(user.ModifiedTime);
    Console.WriteLine(user.NameFormat);
    Console.WriteLine(user.Phone);
    Console.WriteLine(user.State);
    Console.WriteLine(user.Status);
    Console.WriteLine(user.Street);
    Console.WriteLine(user.TimeFormat);
    Console.WriteLine(user.TimeZone);
    Console.WriteLine(user.Website);

    ZCRMUser CreatedBy = user.CreatedBy;
    if (CreatedBy != null)
    {
        Console.WriteLine(CreatedBy.Id);
        Console.WriteLine(CreatedBy.FullName);
    }

    ZCRMUser ModifiedBy = user.ModifiedBy;
    if (ModifiedBy != null)
    {
        Console.WriteLine(ModifiedBy.Id);
        Console.WriteLine(ModifiedBy.FullName);
    }

    ZCRMProfile Profile = user.Profile;
    if (Profile != null)
    {
        Console.WriteLine(Profile.Id);
        Console.WriteLine(Profile.Name);
    }

    ZCRMUser ReportingTo = user.ReportingTo;
    if (ReportingTo != null)
    {
        Console.WriteLine(ReportingTo.Id);
        Console.WriteLine(ReportingTo.FullName);
    }

    ZCRMRole Role = user.Role;
    if (Role != null)
    {
        Console.WriteLine(Role.Id);
        Console.WriteLine(Role.Name);
    }
}
 
タブのリストの取得

/** Get list of modules */
public void GetAllModules()
{
    ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
    BulkAPIResponse<ZCRMModule> response = restClient.GetAllModules();
    Console.WriteLine(response.HttpStatusCode); //Based on API Response    
    List<ZCRMModule> modules = response.BulkData; // modules - list of ZCRMModule instances
    foreach(ZCRMModule module in modules)
    {
        Console.WriteLine(module.ApiName);
        Console.WriteLine(module.Id);

        Console.WriteLine(module.ModifiedTime);
        Console.WriteLine(module.PluralLabel);
        Console.WriteLine(module.SingularLabel);
        Console.WriteLine(module.SystemName);
        List<ZCRMProfile> AccessibleProfiles = module.AccessibleProfiles;
        foreach (ZCRMProfile profile in AccessibleProfiles)
        {
            Console.WriteLine(profile.Id);
            Console.WriteLine(profile.Name);
        }
        Console.WriteLine(module.ApiSupported);
        List<string> BussinessCardFields = module.BussinessCardFields;
        foreach (string BussinessCardField in BussinessCardFields)
        {
            Console.WriteLine(BussinessCardField);
        }
        Console.WriteLine(module.Convertable);
        Console.WriteLine(module.Creatable);
        Console.WriteLine(module.CustomModule);
        Console.WriteLine(module.Deletable);
        Console.WriteLine(module.Editable);

        ZCRMUser ModifiedBy = module.ModifiedBy;
        if (ModifiedBy != null)
        {
            Console.WriteLine(ModifiedBy.Id);
            Console.WriteLine(ModifiedBy.FullName);
        }
        List<ZCRMModuleRelation> relations = module.RelatedLists;
        foreach (ZCRMModuleRelation relation in relations)
        {
            Console.WriteLine(relation.ApiName);
            Console.WriteLine(relation.Id);
        }
        Console.WriteLine(module.Viewable);
    }
}
 
タブのメタデータ

/** Module Meta Data */
public void GetModule()
{
    ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
    APIResponse response = restClient.GetModule("Leads"); //module api name
    Console.WriteLine(response.HttpStatusCode); //Based on API Response    
    ZCRMModule module = (ZCRMModule)response.Data;
    Console.WriteLine(module.ApiName);
    Console.WriteLine(module.Id);

    Console.WriteLine(module.ModifiedTime);
    Console.WriteLine(module.PluralLabel);
    Console.WriteLine(module.SingularLabel);
    Console.WriteLine(module.SystemName);
    List<ZCRMProfile> AccessibleProfiles = module.AccessibleProfiles;
    foreach (ZCRMProfile profile in AccessibleProfiles)
    {
        Console.WriteLine(profile.Id);
        Console.WriteLine(profile.Name);
    }
    Console.WriteLine(module.ApiSupported);
    List<string> BussinessCardFields = module.BussinessCardFields;
    foreach (string BussinessCardField in BussinessCardFields)
    {
        Console.WriteLine(BussinessCardField);
    }
    Console.WriteLine(module.Convertable);
    Console.WriteLine(module.Creatable);
    Console.WriteLine(module.CustomModule);
    Console.WriteLine(module.Deletable);
    Console.WriteLine(module.Editable);

    ZCRMUser ModifiedBy = module.ModifiedBy;
    if (ModifiedBy != null)
    {
        Console.WriteLine(ModifiedBy.Id);
        Console.WriteLine(ModifiedBy.FullName);
    }
    List<ZCRMModuleRelation> relations = module.RelatedLists;
    foreach (ZCRMModuleRelation relation in relations)
    {
        Console.WriteLine(relation.ApiName);
        Console.WriteLine(relation.Id);
    }
    Console.WriteLine(module.Viewable);
}
 
リポジトリへのファイルのアップロード

public void UploadFileToRepository(string filePath)
{
    ZCRMRestClient restClient = ZCRMRestClient.GetInstance();

    APIResponse uploadFileResponse = restClient.UploadFileToRepository(filePath); 

    /**
    FileInfo fileInfo = new FileInfo(filePath);

    APIResponse uploadFileResponse = restClient.UploadFileToRepository(fileInfo.OpenRead(), fileInfo.Name); // Upload file as stream
    **/

    Console.WriteLine(uploadFileResponse.HttpStatusCode);

    Console.WriteLine(uploadFileResponse.Message);

    Console.WriteLine(uploadFileResponse.ResponseJSON);

    Console.WriteLine(uploadFileResponse.Status);

    ZCRMFiles files = (ZCRMFiles)uploadFileResponse.Data;

    Console.WriteLine(files.FileName);

    Console.WriteLine(files.FileId);

}