Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get contacts by the "number" field #19

Open
sveinungf opened this issue Jan 8, 2025 · 5 comments
Open

Get contacts by the "number" field #19

sveinungf opened this issue Jan 8, 2025 · 5 comments

Comments

@sveinungf
Copy link

Hi,

We are currently working on integrating an internal system with SuperOffice, and we have the need to get contacts by the "number" field. We are using the SuperOffice.WebApi NuGet package, and from what we can see it only has options to get contacts by their SuperOffice contact ID using ContactAgent. Is there another way to get contacts within the package? Or would we have to resort to using the REST API directly (e.g. https://docs.superoffice.com/en/api/reference/restful/rest/Contact/v1ContactEntity_GetAll.html)?

Thanks,
Sveinung

@xt1
Copy link

xt1 commented Jan 9, 2025 via email

@sveinungf
Copy link
Author

Thanks for the quick reply. We will look at using the OData endpoint. Are there any plans for having this functionality built into the NuGet package as well? That would be really nice since the package already handles the authentication part and has strong types.

@SuperOfficeDevNet
Copy link
Contributor

SuperOfficeDevNet commented Jan 9, 2025

Hi @sveinungf!

That functionality is already available in the SuperOffice.WebApi package, and is exposed via the ArchiveAgent.

It is beneficial to have more knowledge about archive providers, the data sources behind OData queries.

Example SimpleContact provider, based on examples in this repo:

private async Task<ArchiveListItem[]> GetSimpleContactProviderResults(Tenant tenant)
{

    var tenantStatus = GetTenantStatus(tenant);
    if (tenantStatus.IsRunning)
    {

        var sysUserInfo = GetSystemUserInfo();
        var sysUserTicket = await GetSystemUserTicket(sysUserInfo);

        var config = new WebApiOptions(tenant.WebApiUrl);
        config.Authorization = new AuthorizationSystemUserTicket(sysUserInfo, sysUserTicket);

        using (ArchiveAgent agent = new ArchiveAgent(config))
        {
            ArchiveOrderByInfo orderBy = new ArchiveOrderByInfo { Direction = OrderBySortType.DESC, Name = "PrimaryKey" };

            // restriction: number 
            ArchiveRestrictionInfo restriction = new ArchiveRestrictionInfo
            {
                Name = "number",
                Operator = "=",
                Values = new string[] { "ABC1234" },
                IsActive = true
            };

            // entities - what do we want to see. 
            string[] desiredEntities = new string[] { "contact" };
            string[] columns = new string[] { "contactId", "nameDepartment" };


            // get first page, max 50 rows, of the matching invitations
            ArchiveListItem[] carrier = await agent.GetArchiveListByColumnsAsync("SimpleContact", columns,
                  new ArchiveOrderByInfo[] { orderBy },
                  new ArchiveRestrictionInfo[] { restriction},
                  desiredEntities, 0, 50);

            // for each row of the result...
            foreach (ArchiveListItem row in carrier)
            {
                // extract and display the displayValue of each cell
                // (you need to parse culturally sensitive values such as dates to get the correct client display format)
                foreach (ArchiveColumnData cell in row.ColumnData.Values)
                    Console.Write(CultureDataFormatter.ParseEncoded(cell.DisplayValue) + "\t");

                Console.WriteLine("Done...");
            }

            return carrier;
        }
    }

    return null;
}

@sveinungf
Copy link
Author

Ah, great! Thanks for the help!

@SuperOfficeDevNet
Copy link
Contributor

Ah, great! Thanks for the help!

You are welcome! By the way, I had to update the sample (that I took from docs) and adapted it to work with other examples in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants