Getting owner's CompanyId using Agent Web API

lock
push_pin
done
Beantwortet
7

Hi,

We're migrating from the SOAP API to the Agent Web API and need to get the owner's CompanyId (i.e. company ID associated with the license).

Previously, we able to do it using the SoPrincipal service and its GetSystemInfo method.

Since the SoPrincipal agent for the Web API does not exist, what's the correct way to do it?

9. Juli 2024 | 07:49 AM

Alle Antworten (7)

Hi Dmitry!

You can use the UserAgent.GetCurrentPrincipal() and inspect the Result.ContactOwner.

Hope this helps!

 

9. Juli 2024 | 01:06 PM

9. Juli 2024 | 01:18 PM
Hi Tony!

Thanks for the sample.
Unfortunately, the ContactOwner field seems to be always '0' when connecting using a system user token.
It works for 'normal' users (using AuthorizationAccessToken).
I was able to get the name of the owner contact using the LicenseAgent and the GetLicenseForAllOwnersFromDBAsync method, but it doesn't provide the ID - only the name.
9. Juli 2024 | 01:39 PM

We ended up with retrieving CompanyName from the license info returned by the License agent and then using it with the Archive agent to retrieve the owner's contact ID by its name.

11. Juli 2024 | 07:52 AM

HI Dmitry,

Instead of doing a heavy API call to retrieve the license info, you could use the owner contact archive provider: OwnerContacts

If you specifically want the license owner contact id, you could do a dynamic query like this:

./api/v1/Archive/Dynamic?$select=company.ownerContactId&$filter=company.company_id eq 1

11. Juli 2024 | 07:57 AM
Hi David,

Thanks, I'll give it a try!
11. Juli 2024 | 09:36 AM
The Dynamic archive provider approach worked like a charm!
I was even able to extract the serial number as company.serialNo (I was using the License agent for this before).
11. Juli 2024 | 09:59 AM

Antwort hinzufügen