Companies (Company) define the legal business entities, holding structures, and corporate tenants within GOAL. Each company maintains its own ERP connectors, currency, tax identifiers (RUC), and operational branches.
/v1/base/master/companies
| Header | Type | Description |
|---|---|---|
Authorization |
string |
Bearer <token> OAuth2 token. |
x-app-stage |
string |
Current tenant stage (dev, staging, prod). |
x-app-uid |
string |
Authenticated user UUID. |
| Parameter | Type | Default | Description |
|---|---|---|---|
companyId |
integer |
Optional | Context company ID. |
view |
string |
A |
A (Active), I (Inactive), D (Trashed), ALL. |
Retrieve active legal companies and subsidiaries.
GET /v1/base/master/companies?view=A
200 OK{
"success": true,
"message": "Proceso realizado correctamente",
"data": [
{
"id": 1,
"name": "CORPORACIÓN BEBIDAS DEL PERÚ S.A.C.",
"trade_name": "CORP BEBIDAS",
"ruc": "20100123456",
"currency": "PEN",
"address": "Av. República de Panamá 3055, San Isidro",
"logo_url": "https://assets.goal.pe/logos/company-1.svg",
"parent_id": null,
"status": "A"
}
]
}
Returns companies nested as parent holding organizations and subordinate branch entities.
GET /v1/base/master/companies/with-children?companyId={contextCompanyId}
| Requirement | V2 model action | Legacy fallback |
|---|---|---|
| Call allowed | Company LIST |
G2_COMPANY_LIST |
| Actor | data shape |
|---|---|
| Default (has LIST, no global scope) | Root holdings and children derived from the user's active company assignments only |
Company authorizer (Company::COMPANY_AUTHORIZER / GOAL_V2_AUTH_COMPANY_COMPANY_COMPANY_AUTHORIZER) in current companyId context |
All root holdings (including global type = G, excluding system/reserved roots), flattened with their base_company_id children |
Legacy company admin (G2_COMPANY_ADMIN) |
Same global scope as authorizer |
Note: Company authorizer expands scope only; it does not replace LIST for these endpoints. See also User company assignments API for the same authorizer on assignable companies.
Returns a flat array for data grids. Each row includes normalized fields from CompanyGridResource: type (string code), parent_company_name, base_company_name, productive_mode, tree_depth.
GET /v1/base/master/companies/grid-list?companyId={contextCompanyId}
Same as §2 Company Hierarchy with Children: LIST (V2) or G2_COMPANY_LIST (legacy).
Same rules as with-children: assignment-scoped rows by default; global flat list when the actor has Company authorizer or G2_COMPANY_ADMIN in the active company context.
Response data: array of company row objects (not nested).
Active companies with type = G for assigning base_company_id on child companies.
GET /v1/base/master/companies/autocomplete/global?companyId={contextCompanyId}&exclude_id={optionalCompanyId}
Query subsidiaries directly under a specific holding company. {id} accepts numeric id or uuid.
GET /v1/base/master/companies/1/companies
GET /v1/base/master/companies/42652e79-9c3a-4cb9-9696-435c1cb20b9f/companies?companyId=8
GET, PUT, DELETE, properties, uploads, and child-list routes resolve the company with:
companies.idcompanies.uuidExample:
GET /v1/base/master/companies/42652e79-9c3a-4cb9-9696-435c1cb20b9f?companyId=8
PUT /v1/base/master/companies/42652e79-9c3a-4cb9-9696-435c1cb20b9f?companyId=8
Used for invoice printing, electronic documents, and web portal branding.
POST /v1/base/master/companies/1/upload-logo
Content-Type: multipart/form-data
| Field | Type | Description |
|---|---|---|
logo |
file |
Image binary (png, svg, jpg, max 2MB). |
POST /v1/base/master/companies/1/upload-image
Content-Type: multipart/form-data
POST /v1/base/master/companies?companyId={contextCompanyId}
Content-Type: application/json
{
"name": "DISTRIBUIDORA ORIENTE S.A.C.",
"trade_name": "DISTRIBUIDORA ORIENTE",
"ruc": "20601928374",
"currency": "PEN",
"address": "Jr. Próspero 412, Iquitos",
"parent_id": 1
}
productive_mode & UAT| Layer | Behavior |
|---|---|
Column companies.productive_mode |
Y (default) = empresa productiva; N = pruebas/UAT. Solo filas con productive_mode = 'Y' participan en unicidad de RUC. |
| DB index (PostgreSQL) | uq_companies_ruc_productive_mode — UNIQUE (ruc) WHERE productive_mode = 'Y' AND deleted_at IS NULL. |
| DB index (PostgreSQL) | uq_companies_email_productive_mode — UNIQUE (email) WHERE productive_mode = 'Y' AND deleted_at IS NULL. |
| API validation | Duplicado de RUC y email solo se valida entre empresas con productive_mode = Y (o se omite en UAT / no productivo). |
properties.uat_mode (CouchDB) |
Flag adicional en goal-company-config-{id}.properties; también relaja validación legacy cuando aplica al contexto. |
Migrations (orden):
2026_10_19_180000_drop_unique_ruc_on_companies_table — elimina UNIQUE global en ruc (core).2026_10_19_190000_add_productive_mode_to_companies_table — columna productive_mode + índice parcial RUC.2026_10_19_200000_drop_unique_email_on_companies_table — quita UNIQUE global en email + índice parcial email (core).2026_10_19_210000_align_companies_uniqueness_on_goal_data_db — goal-data-db (DB_DATA): elimina companies_email_unique / companies_ruc_unique, añade productive_mode si falta, crea índices parciales RUC/email.replicateToGoalDatabase)Tras crear o actualizar una empresa, el backend sincroniza la fila en goal-data-db (Goal::db()) por el mismo id:
| Caso | Comportamiento |
|---|---|
| Fila existe en réplica | UPDATE con payload normalizado (flags, type, productive_mode). |
No existe y productive_mode = N |
No inserta (UAT duplicado solo en core). |
No existe y productive_mode = Y |
INSERT; requiere migración 210000 si comparte email/RUC con otra fila UAT en réplica. |
Create (POST) y update (PUT) replican de inmediato. Como red de seguridad, el comando programado goal:companies:sync-to-goal-database (incremental, cada 5 minutos en nodos con etiqueta scheduler) corrige desvíos. Ver CLI: goal:companies:sync-to-goal-database.
| Campo | Descripción |
|---|---|
base_company_id |
ID de matriz global (type = G). |
base_company |
Objeto autocomplete del frontend; el backend lo convierte a base_company_id y no se valida como entero. |
type |
Código de CompanyTypesEnum (G = global matriz). |
productive_mode |
Y / N (puede forzarse a N cuando aplica UAT). |
GET /v1/base/master/companies/properties-form-schema
GET /v1/base/master/companies/{id}/properties?companyId={context}
PUT /v1/base/master/companies/{id}/properties?companyId={context}
Body (PUT):
{
"properties": {
"uat_mode": "Y"
}
}
PUT /v1/base/master/companies/2
DELETE /v1/base/master/companies/2
PUT /v1/base/master/companies/2/restore
Company-wide recargo financiero tier matrix for credit purchases. Used to seed new online store distribution centers and as fallback when resolving rates. Stored on goal-data-db (company_credit_charge_defaults); typically maintained for transactional companies (type = T).
GET /v1/base/master/companies/8/credit-charge-defaults?companyId=8
PUT /v1/base/master/companies/8/credit-charge-defaults?companyId=8
Authorization: Bearer <token>
x-app-stage: <stage>
x-app-uid: <uid>
Content-Type: application/json
GET response (data):
{
"company_id": 8,
"credit_charge_enabled": "Y",
"charges": {
"charges": [
{ "days": 7, "value": 0.5 },
{ "days": 14, "value": 1.0 },
{ "days": 21, "value": 1.5 },
{ "days": 28, "value": 2.0 }
]
}
}
PUT body: same shape as credit_charge_enabled + charges object above.
| HTTP | When |
|---|---|
200 |
Success |
400 / 422 |
Invalid tiers or validation |
401 / 403 |
Auth / permission |
Integration detail: online-store-credit-charges.md.
Provision the three APPLICATION templates (COMPANY_ADMIN, COMPANY_ROLE_MANAGER, COMPANY_ROLE_VIEWER) into company_roles for the target company ({id} may be numeric id or uuid). Safe to call multiple times: existing roles are kept and permissions are merged from global templates.
GET /v1/base/master/companies/{id}/bootstrap-default-roles/status?companyId={context}
POST /v1/base/master/companies/{id}/bootstrap-default-roles?companyId={context}
Authorization: Bearer <token>
x-app-stage: <stage>
x-app-uid: <uid>
| HTTP | Permission (permissions.code) |
|---|---|
GET status |
GOAL_V2_AUTH_COMPANYROLE_COMPANY_ROLE_LIST |
POST bootstrap |
GOAL_V2_AUTH_COMPANYROLE_COMPANY_ROLE_PROVISION_FROM_TEMPLATE |
GET data (example):
{
"target_company_id": 8,
"eligible": true,
"company_type": "T",
"complete": false,
"missing_codes": ["COMPANY_ROLE_VIEWER"],
"templates": [
{ "code": "COMPANY_ADMIN", "name": "Administrador de compañía", "present": true },
{ "code": "COMPANY_ROLE_MANAGER", "name": "Gestor de roles de compañía", "present": true },
{ "code": "COMPANY_ROLE_VIEWER", "name": "Consulta de roles de compañía", "present": false }
]
}
POST 200: Same payload shape as POST /auth/company-roles/provision-from-global (created, skipped, summary with permissions_assigned). Non-transactional companies return 200 with skipped: true, reason: company_type.
CLI equivalent: company-role-bootstrap.md.