Getting owner's CompanyId using Agent Web API

lock
push_pin
done
Besvart
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. jul. 2024 | 07:49 a.m.

Alle Svar (7)

Hi Dmitry!

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

Hope this helps!

 

9. jul. 2024 | 01:06 p.m.

9. jul. 2024 | 01:18 p.m.
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. jul. 2024 | 01:39 p.m.

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. jul. 2024 | 07:52 a.m.

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. jul. 2024 | 07:57 a.m.
Hi David,

Thanks, I'll give it a try!
11. jul. 2024 | 09:36 a.m.
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. jul. 2024 | 09:59 a.m.

Legg til svar