For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inBook a demo
HomeGuidesAPI ReferenceGlossary
HomeGuidesAPI ReferenceGlossary
  • Home
    • Overview
      • Overview
      • Entities
      • Entity Groups
      • Entity Users
      • Foreign ID
      • Transactions
      • Notifications
      • RBAC
      • Webhooks
      • JWT Tokens
      • Custom Fields
      • Business Representative
    • Testing and Errors
Logo
Sign inBook a demo
On this page
  • API Reference
  • Creating a Group
  • Email Inbox
  • Managing Users
  • Authentication
  • Example
  • Create a group
  • Add a user to all entities in the group with the same role
  • Add a user to specific entities in the group with different roles
  • Add another entity to the group
  • Sync Users
HomeCommon Concepts

Entity Groups

Was this page helpful?
Previous

Entity Users

Next
Built with

API Reference

Many times, you want to manage a group of businesses as a group. Some examples of this include:

  1. A group of franchise businesses owned by the same person, where each location is a separate LLC
  2. A parent company with multiple subsidiaries
  3. An accountant who is managing the finances for multiple unrelated companies

Entity groups make managing these multi-entity situations much easier.

Creating a Group

An entity group consists of a list of entities. Entities can be added to more than one group, though this is typically not recommended.

You can create a group without any entities and add them later, or create the entities first and then add them to the group.

POST
/entityGroup
1curl -X POST https://api.mercoa.com/entityGroup \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "emailToName": "acmegroup",
6 "entityIds": [
7 "ent_8545a84e-a45f-41bf-bdf1-33b42a55812c",
8 "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d"
9 ],
10 "foreignId": "your-group-id",
11 "name": "AcmeConglomerate"
12}'
Try it

Email Inbox

Entity groups have an email inbox that is independent of the entities in the group. Invoices that are sent to this inbox get created in the UNASSIGNED state, and then can be assigned to an entity in the group for further processing.

Managing Users

Many times, you will want to manage users at the group level. For example, the same admin user might need access to all entities in the group. Mercoa uses the user’s foreignId to identity users across a group. Users can be added and removed from all entities in the group in a single API call, and roles can be managed on a per-entity basis.

POST
/entityGroup/:entityGroupId/user
1curl -X POST https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "foreignId": "MY-DB-ID-12345",
6 "email": "john.doe@acme.com",
7 "name": "John Doe",
8 "entities": [
9 {
10 "roles": [
11 "admin",
12 "approver"
13 ],
14 "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d"
15 },
16 {
17 "roles": [
18 "viewer"
19 ],
20 "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90"
21 }
22 ]
23}'
Try it

Authentication

Entity groups allow you to create a JWT token at the group level or group user level. This token gives access to all entities in the group without needed to generate an unique token for every entity in the group.

POST
/entityGroup/:entityGroupId/user/:foreignId/token
1curl -X POST https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "expiresIn": "1h"
6}'
Try it

This token can be used in the Mercoa API, SDKs, and React Library.

Example

In this example, we have three entities that are part of the same group.

  1. A west coast business called “West Coast Corp” with an entity id if ent_e8c2af94-61cd-4036-a765-80341209167b
  2. A east coast business called “East Coast Inc” with an entity id of ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b
  3. A southern business called “Southern Company” with an entity id of ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be

Create a group

First, we can create this group with these three entities:

POST
/entityGroup
1curl -X POST https://api.mercoa.com/entityGroup \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "emailToName": "coastalcorp",
6 "entityIds": [
7 "ent_e8c2af94-61cd-4036-a765-80341209167b",
8 "ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b",
9 "ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be"
10 ],
11 "foreignId": "your-group-id",
12 "name": "Coastal Corporation"
13}'
Try it

Add a user to all entities in the group with the same role

Next, let’s say we want to add a user to all entities in the group with the “admin” role.

POST
/entityGroup/:entityGroupId/user
1curl -X POST https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "foreignId": "MY-DB-ID-12345",
6 "email": "john.doe@acme.com",
7 "name": "John Doe",
8 "entities": [
9 {
10 "roles": [
11 "admin",
12 "approver"
13 ],
14 "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d"
15 },
16 {
17 "roles": [
18 "viewer"
19 ],
20 "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90"
21 }
22 ]
23}'
Try it

Add a user to specific entities in the group with different roles

Next, let’s say we want to add a user to all entities in the group, but we want to give the user a different role for each entity.

POST
/entityGroup/:entityGroupId/user
1curl -X POST https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "foreignId": "MY-DB-ID-12345",
6 "email": "john.doe@acme.com",
7 "name": "John Doe",
8 "entities": [
9 {
10 "roles": [
11 "admin",
12 "approver"
13 ],
14 "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d"
15 },
16 {
17 "roles": [
18 "viewer"
19 ],
20 "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90"
21 }
22 ]
23}'
Try it

Add another entity to the group

Next, let’s say we want to add another entity to the group.

When adding an entity to a group, you can optionally copy the users from an existing entity in the group. Do this using the copyUsersFrom field. You can specify an entity ID or set this to true to copy users from the entity with the most users that has been updated most recently.

Sync Users

If at any point users have been added to a specific entity in the group instead of the group itself, you can sync the users from the entity to the group.

This will let you make sure that all entities in the group have the same users as needed.

POST
/entityGroup/:entityGroupId/sync-users
1curl -X POST https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "filterRoles": [
6 "approver",
7 "viewer"
8 ]
9}'
Try it