> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.mercoa.com/embedded-ap-ar/home/common-concepts/entity-groups/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mercoa.com/_mcp/server. ## [API Reference](/api-reference/entity-group/create) 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](/api-reference/entity-group/add-entities), or create the entities first and then add them to the group. ### Request POST [https://api.mercoa.com/entityGroup](https://api.mercoa.com/entityGroup) **`Default`** ```curl Default curl -X POST https://api.mercoa.com/entityGroup \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "emailToName": "acmegroup", "entityIds": [ "ent_8545a84e-a45f-41bf-bdf1-33b42a55812c", "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" ], "foreignId": "your-group-id", "name": "AcmeConglomerate" }' ``` **`Default`** ```python Default import requests url = "https://api.mercoa.com/entityGroup" payload = { "emailToName": "acmegroup", "entityIds": ["ent_8545a84e-a45f-41bf-bdf1-33b42a55812c", "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d"], "foreignId": "your-group-id", "name": "AcmeConglomerate" } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` **`Default`** ```typescript Default import { MercoaClient } from "@mercoa/javascript"; const client = new MercoaClient({ token: "YOUR_TOKEN" }); await client.entityGroup.create({ foreignId: "your-group-id", name: "AcmeConglomerate", emailToName: "acmegroup", entityIds: ["ent_8545a84e-a45f-41bf-bdf1-33b42a55812c", "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d"] }); ``` **`Default`** ```go Default package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.mercoa.com/entityGroup" payload := strings.NewReader("{\n \"emailToName\": \"acmegroup\",\n \"entityIds\": [\n \"ent_8545a84e-a45f-41bf-bdf1-33b42a55812c\",\n \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n ],\n \"foreignId\": \"your-group-id\",\n \"name\": \"AcmeConglomerate\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` **`Default`** ```ruby Default require 'uri' require 'net/http' url = URI("https://api.mercoa.com/entityGroup") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"emailToName\": \"acmegroup\",\n \"entityIds\": [\n \"ent_8545a84e-a45f-41bf-bdf1-33b42a55812c\",\n \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n ],\n \"foreignId\": \"your-group-id\",\n \"name\": \"AcmeConglomerate\"\n}" response = http.request(request) puts response.read_body ``` **`Default`** ```java Default import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.mercoa.com/entityGroup") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"emailToName\": \"acmegroup\",\n \"entityIds\": [\n \"ent_8545a84e-a45f-41bf-bdf1-33b42a55812c\",\n \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n ],\n \"foreignId\": \"your-group-id\",\n \"name\": \"AcmeConglomerate\"\n}") .asString(); ``` **`Default`** ```php Default request('POST', 'https://api.mercoa.com/entityGroup', [ 'body' => '{ "emailToName": "acmegroup", "entityIds": [ "ent_8545a84e-a45f-41bf-bdf1-33b42a55812c", "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" ], "foreignId": "your-group-id", "name": "AcmeConglomerate" }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` **`Default`** ```csharp Default using RestSharp; var client = new RestClient("https://api.mercoa.com/entityGroup"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"emailToName\": \"acmegroup\",\n \"entityIds\": [\n \"ent_8545a84e-a45f-41bf-bdf1-33b42a55812c\",\n \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n ],\n \"foreignId\": \"your-group-id\",\n \"name\": \"AcmeConglomerate\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` **`Default`** ```swift Default import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "emailToName": "acmegroup", "entityIds": ["ent_8545a84e-a45f-41bf-bdf1-33b42a55812c", "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d"], "foreignId": "your-group-id", "name": "AcmeConglomerate" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.mercoa.com/entityGroup")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ## Email Inbox Entity groups have an [email inbox](/accounts-payable/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. ### Request POST [https://api.mercoa.com/entityGroup/\{entityGroupId}/user](https://api.mercoa.com/entityGroup/\{entityGroupId}/user) **`Default`** ```curl Default curl -X POST https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": [ "admin", "approver" ], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": [ "viewer" ], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] }' ``` **`Default`** ```python Default import requests url = "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user" payload = { "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": ["admin", "approver"], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": ["viewer"], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` **`Default`** ```typescript Default import { MercoaClient } from "@mercoa/javascript"; const client = new MercoaClient({ token: "YOUR_TOKEN" }); await client.entityGroup.user.create("entg_8545a84e-a45f-41bf-bdf1-33b42a55812c", { foreignId: "MY-DB-ID-12345", email: "john.doe@acme.com", name: "John Doe", entities: [{ roles: ["admin", "approver"], entityId: "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { roles: ["viewer"], entityId: "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" }] }); ``` **`Default`** ```go Default package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user" payload := strings.NewReader("{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` **`Default`** ```ruby Default require 'uri' require 'net/http' url = URI("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` **`Default`** ```java Default import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}") .asString(); ``` **`Default`** ```php Default request('POST', 'https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user', [ 'body' => '{ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": [ "admin", "approver" ], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": [ "viewer" ], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` **`Default`** ```csharp Default using RestSharp; var client = new RestClient("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` **`Default`** ```swift Default import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ [ "roles": ["admin", "approver"], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" ], [ "roles": ["viewer"], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ## 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. ### Request POST [https://api.mercoa.com/entityGroup/\{entityGroupId}/user/\{foreignId}/token](https://api.mercoa.com/entityGroup/\{entityGroupId}/user/\{foreignId}/token) **`Default`** ```curl Default curl -X POST https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "expiresIn": "1h" }' ``` **`Default`** ```python Default import requests url = "https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token" payload = { "expiresIn": "1h" } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` **`Default`** ```typescript Default import { MercoaClient } from "@mercoa/javascript"; const client = new MercoaClient({ token: "YOUR_TOKEN" }); await client.entityGroup.user.getToken("entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced", "MY-DB-ID-12345", { expiresIn: "1h" }); ``` **`Default`** ```go Default package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token" payload := strings.NewReader("{\n \"expiresIn\": \"1h\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` **`Default`** ```ruby Default require 'uri' require 'net/http' url = URI("https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"expiresIn\": \"1h\"\n}" response = http.request(request) puts response.read_body ``` **`Default`** ```java Default import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"expiresIn\": \"1h\"\n}") .asString(); ``` **`Default`** ```php Default request('POST', 'https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token', [ 'body' => '{ "expiresIn": "1h" }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` **`Default`** ```csharp Default using RestSharp; var client = new RestClient("https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"expiresIn\": \"1h\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` **`Default`** ```swift Default import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = ["expiresIn": "1h"] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.mercoa.com/entityGroup/entg_a0f6ea94-0761-4a5e-a416-3c453cb7eced/user/MY-DB-ID-12345/token")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` 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: ### Request POST [https://api.mercoa.com/entityGroup](https://api.mercoa.com/entityGroup) **`DocsExample`** ```curl DocsExample curl -X POST https://api.mercoa.com/entityGroup \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "emailToName": "coastalcorp", "entityIds": [ "ent_e8c2af94-61cd-4036-a765-80341209167b", "ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b", "ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be" ], "foreignId": "your-group-id", "name": "Coastal Corporation" }' ``` **`DocsExample`** ```python DocsExample import requests url = "https://api.mercoa.com/entityGroup" payload = { "emailToName": "coastalcorp", "entityIds": ["ent_e8c2af94-61cd-4036-a765-80341209167b", "ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b", "ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be"], "foreignId": "your-group-id", "name": "Coastal Corporation" } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` **`DocsExample`** ```typescript DocsExample import { MercoaClient } from "@mercoa/javascript"; const client = new MercoaClient({ token: "YOUR_TOKEN" }); await client.entityGroup.create({ foreignId: "your-group-id", name: "Coastal Corporation", emailToName: "coastalcorp", entityIds: ["ent_e8c2af94-61cd-4036-a765-80341209167b", "ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b", "ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be"] }); ``` **`DocsExample`** ```go DocsExample package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.mercoa.com/entityGroup" payload := strings.NewReader("{\n \"emailToName\": \"coastalcorp\",\n \"entityIds\": [\n \"ent_e8c2af94-61cd-4036-a765-80341209167b\",\n \"ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b\",\n \"ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be\"\n ],\n \"foreignId\": \"your-group-id\",\n \"name\": \"Coastal Corporation\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` **`DocsExample`** ```ruby DocsExample require 'uri' require 'net/http' url = URI("https://api.mercoa.com/entityGroup") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"emailToName\": \"coastalcorp\",\n \"entityIds\": [\n \"ent_e8c2af94-61cd-4036-a765-80341209167b\",\n \"ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b\",\n \"ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be\"\n ],\n \"foreignId\": \"your-group-id\",\n \"name\": \"Coastal Corporation\"\n}" response = http.request(request) puts response.read_body ``` **`DocsExample`** ```java DocsExample import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.mercoa.com/entityGroup") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"emailToName\": \"coastalcorp\",\n \"entityIds\": [\n \"ent_e8c2af94-61cd-4036-a765-80341209167b\",\n \"ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b\",\n \"ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be\"\n ],\n \"foreignId\": \"your-group-id\",\n \"name\": \"Coastal Corporation\"\n}") .asString(); ``` **`DocsExample`** ```php DocsExample request('POST', 'https://api.mercoa.com/entityGroup', [ 'body' => '{ "emailToName": "coastalcorp", "entityIds": [ "ent_e8c2af94-61cd-4036-a765-80341209167b", "ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b", "ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be" ], "foreignId": "your-group-id", "name": "Coastal Corporation" }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` **`DocsExample`** ```csharp DocsExample using RestSharp; var client = new RestClient("https://api.mercoa.com/entityGroup"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"emailToName\": \"coastalcorp\",\n \"entityIds\": [\n \"ent_e8c2af94-61cd-4036-a765-80341209167b\",\n \"ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b\",\n \"ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be\"\n ],\n \"foreignId\": \"your-group-id\",\n \"name\": \"Coastal Corporation\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` **`DocsExample`** ```swift DocsExample import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "emailToName": "coastalcorp", "entityIds": ["ent_e8c2af94-61cd-4036-a765-80341209167b", "ent_1176dd0c-12e1-41c7-85a5-ae9b4746e64b", "ent_3dbb4ede-2d1d-49be-a996-a5dfad3641be"], "foreignId": "your-group-id", "name": "Coastal Corporation" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.mercoa.com/entityGroup")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ## 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. ### Request POST [https://api.mercoa.com/entityGroup/\{entityGroupId}/user](https://api.mercoa.com/entityGroup/\{entityGroupId}/user) **`Default`** ```curl Default curl -X POST https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": [ "admin", "approver" ], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": [ "viewer" ], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] }' ``` **`Default`** ```python Default import requests url = "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user" payload = { "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": ["admin", "approver"], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": ["viewer"], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` **`Default`** ```typescript Default import { MercoaClient } from "@mercoa/javascript"; const client = new MercoaClient({ token: "YOUR_TOKEN" }); await client.entityGroup.user.create("entg_8545a84e-a45f-41bf-bdf1-33b42a55812c", { foreignId: "MY-DB-ID-12345", email: "john.doe@acme.com", name: "John Doe", entities: [{ roles: ["admin", "approver"], entityId: "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { roles: ["viewer"], entityId: "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" }] }); ``` **`Default`** ```go Default package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user" payload := strings.NewReader("{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` **`Default`** ```ruby Default require 'uri' require 'net/http' url = URI("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` **`Default`** ```java Default import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}") .asString(); ``` **`Default`** ```php Default request('POST', 'https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user', [ 'body' => '{ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": [ "admin", "approver" ], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": [ "viewer" ], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` **`Default`** ```csharp Default using RestSharp; var client = new RestClient("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` **`Default`** ```swift Default import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ [ "roles": ["admin", "approver"], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" ], [ "roles": ["viewer"], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ## 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. ### Request POST [https://api.mercoa.com/entityGroup/\{entityGroupId}/user](https://api.mercoa.com/entityGroup/\{entityGroupId}/user) **`Default`** ```curl Default curl -X POST https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": [ "admin", "approver" ], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": [ "viewer" ], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] }' ``` **`Default`** ```python Default import requests url = "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user" payload = { "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": ["admin", "approver"], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": ["viewer"], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` **`Default`** ```typescript Default import { MercoaClient } from "@mercoa/javascript"; const client = new MercoaClient({ token: "YOUR_TOKEN" }); await client.entityGroup.user.create("entg_8545a84e-a45f-41bf-bdf1-33b42a55812c", { foreignId: "MY-DB-ID-12345", email: "john.doe@acme.com", name: "John Doe", entities: [{ roles: ["admin", "approver"], entityId: "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { roles: ["viewer"], entityId: "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" }] }); ``` **`Default`** ```go Default package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user" payload := strings.NewReader("{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` **`Default`** ```ruby Default require 'uri' require 'net/http' url = URI("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` **`Default`** ```java Default import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}") .asString(); ``` **`Default`** ```php Default request('POST', 'https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user', [ 'body' => '{ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ { "roles": [ "admin", "approver" ], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" }, { "roles": [ "viewer" ], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" } ] }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` **`Default`** ```csharp Default using RestSharp; var client = new RestClient("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"foreignId\": \"MY-DB-ID-12345\",\n \"email\": \"john.doe@acme.com\",\n \"name\": \"John Doe\",\n \"entities\": [\n {\n \"roles\": [\n \"admin\",\n \"approver\"\n ],\n \"entityId\": \"ent_21661ac1-a2a8-4465-a6c0-64474ba8181d\"\n },\n {\n \"roles\": [\n \"viewer\"\n ],\n \"entityId\": \"ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` **`Default`** ```swift Default import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "foreignId": "MY-DB-ID-12345", "email": "john.doe@acme.com", "name": "John Doe", "entities": [ [ "roles": ["admin", "approver"], "entityId": "ent_21661ac1-a2a8-4465-a6c0-64474ba8181d" ], [ "roles": ["viewer"], "entityId": "ent_9e02a20e-7749-47de-8d8a-f8ff2859fa90" ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/user")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ## 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. ### Request POST [https://api.mercoa.com/entityGroup/\{entityGroupId}/sync-users](https://api.mercoa.com/entityGroup/\{entityGroupId}/sync-users) **`Default`** ```curl Default curl -X POST https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "filterRoles": [ "approver", "viewer" ] }' ``` **`Default`** ```python Default import requests url = "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users" payload = { "filterRoles": ["approver", "viewer"] } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` **`Default`** ```typescript Default import { MercoaClient } from "@mercoa/javascript"; const client = new MercoaClient({ token: "YOUR_TOKEN" }); await client.entityGroup.user.sync("entg_8545a84e-a45f-41bf-bdf1-33b42a55812c", { filterRoles: ["approver", "viewer"] }); ``` **`Default`** ```go Default package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users" payload := strings.NewReader("{\n \"filterRoles\": [\n \"approver\",\n \"viewer\"\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` **`Default`** ```ruby Default require 'uri' require 'net/http' url = URI("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"filterRoles\": [\n \"approver\",\n \"viewer\"\n ]\n}" response = http.request(request) puts response.read_body ``` **`Default`** ```java Default import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"filterRoles\": [\n \"approver\",\n \"viewer\"\n ]\n}") .asString(); ``` **`Default`** ```php Default request('POST', 'https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users', [ 'body' => '{ "filterRoles": [ "approver", "viewer" ] }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` **`Default`** ```csharp Default using RestSharp; var client = new RestClient("https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"filterRoles\": [\n \"approver\",\n \"viewer\"\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` **`Default`** ```swift Default import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = ["filterRoles": ["approver", "viewer"]] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.mercoa.com/entityGroup/entg_8545a84e-a45f-41bf-bdf1-33b42a55812c/sync-users")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```