{
  "openapi": "3.0.1",
  "info": {
    "title": "Business Organization API",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.mercadoe.com"
    }
  ],
  "paths": {
    "/v1/business-organizations": {
      "post": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Create a business organization",
        "description": "Create a new business organization by providing the business organization entity type, business organization description, and other details.",
        "parameters": [
          {
            "name": "X-ME-CORRELATION-ID",
            "in": "header",
            "description": "Internal client code to be identified in the webhook. It can be, for example, a product code in your ERP, an order number, etc.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/business-organizations/{businessOrganizationId}": {
      "put": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Update a business organization and its associated processes",
        "description": "Update a business organization and its associated processes specified by its Id.",
        "parameters": [
          {
            "name": "businessOrganizationId",
            "in": "path",
            "description": "the business organization id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "X-ME-CORRELATION-ID",
            "in": "header",
            "description": "Internal client code to be identified in the webhook. It can be, for example, a product code in your ERP, an order number, etc.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Get a business organization by Id",
        "description": "Retrieves information about a specific business organization with the given businessOrganizationId.",
        "parameters": [
          {
            "name": "businessOrganizationId",
            "in": "path",
            "description": "the business organization id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetByIdResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "500": {
            "description": "Server Error"
          }
        }
      }
    },
    "/v1/business-organizations/{businessOrganizationId}/business-organization-parents": {
      "put": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Delete a business organization from an associated parent entity",
        "description": "Delete a business organization from an associated parent entity specified by its Id.",
        "parameters": [
          {
            "name": "businessOrganizationId",
            "in": "path",
            "description": "the business organization id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "X-ME-CORRELATION-ID",
            "in": "header",
            "description": "Internal client code to be identified in the webhook. It can be, for example, a product code in your ERP, an order number, etc.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeleteBusinessOrganizationParentsRelationshipsCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteBusinessOrganizationParentsRelationshipsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Get a list of parent-entities by business organization Id.",
        "description": "Get a list of all parent-entities of a specific business organization with the given businessOrganizationId.",
        "parameters": [
          {
            "name": "businessOrganizationId",
            "in": "path",
            "description": "the business organization id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "pageNumber",
            "in": "query",
            "description": "the page number must be an integer greater than or equal to 1",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "description": "the page size must be an integer greater than or equal to 1",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetBusinessOrganizationParentsResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/business-organizations/{businessOrganizationId}/cost-centers": {
      "put": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Delete a business organization from an associated cost center",
        "description": "Delete a business organization from an associated cost center specified by its Id.",
        "parameters": [
          {
            "name": "businessOrganizationId",
            "in": "path",
            "description": "the business organization id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "X-ME-CORRELATION-ID",
            "in": "header",
            "description": "Internal client code to be identified in the webhook. It can be, for example, a product code in your ERP, an order number, etc.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeleteCostCentersRelationshipsCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteCostCentersRelationshipsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Get a list of cost centers for the business organization based on the business organization Id.",
        "description": "Get a list of all cost centers of a specific business organization with the given businessOrganizationId.",
        "parameters": [
          {
            "name": "businessOrganizationId",
            "in": "path",
            "description": "the business organization id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "pageNumber",
            "in": "query",
            "description": "the page number must be an integer greater than or equal to 1",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "description": "the page size must be an integer greater than or equal to 1",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetBusinessOrganizationCostCentersResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/business-organizations/{businessOrganizationId}/business-organization-children": {
      "get": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Get a list of child-entities by business organization Id.",
        "description": "Get a list of all child-entities of a specific business organization with the given businessOrganizationId.",
        "parameters": [
          {
            "name": "businessOrganizationId",
            "in": "path",
            "description": "the business organization id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "pageNumber",
            "in": "query",
            "description": "the page number must be an integer greater than or equal to 1",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "description": "the page size must be an integer greater than or equal to 1",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetBusinessOrganizationChildrenResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/business-organizations/{businessOrganizationId}/groups": {
      "get": {
        "tags": [
          "Business Organizations"
        ],
        "summary": "Get a list of product groups for the business organization based on the business organization Id.",
        "description": "Get a list of all product groups of a specific business organization with the given businessOrganizationId.",
        "parameters": [
          {
            "name": "businessOrganizationId",
            "in": "path",
            "description": "the business organization id",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "pageNumber",
            "in": "query",
            "description": "the page number must be an integer greater than or equal to 1",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "description": "the page size must be an integer greater than or equal to 1",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetBusinessOrganizationGroupsResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BusinessOrganizationParentDto": {
        "required": [
          "clientBusinessOrganizationId",
          "entityType"
        ],
        "type": "object",
        "properties": {
          "clientBusinessOrganizationId": {
            "minLength": 1,
            "type": "string",
            "description": "Code of the parent-entity for the business organization in the client's ERP"
          },
          "entityType": {
            "minLength": 1,
            "type": "string",
            "description": "Type of parent-entity for the organizational structure. Example: Company, branch."
          }
        },
        "additionalProperties": false
      },
      "CostCenterDto": {
        "required": [
          "clientCostCenterId",
          "description"
        ],
        "type": "object",
        "properties": {
          "clientCostCenterId": {
            "minLength": 1,
            "type": "string",
            "description": "Code of the cost center in the client's ERP\r\nREQUIRED if `Description` = Null"
          },
          "description": {
            "minLength": 1,
            "type": "string",
            "description": "Cost center description\r\nREQUIRED if `ClientCostCenterId` = Null"
          }
        },
        "additionalProperties": false
      },
      "CreateCommand": {
        "required": [
          "clientBusinessOrganizationId",
          "description",
          "entityType"
        ],
        "type": "object",
        "properties": {
          "entityType": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Type of organizational structure. Example: Company, branch, department."
          },
          "description": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Description of the business organization"
          },
          "clientBusinessOrganizationId": {
            "maxLength": 20,
            "minLength": 1,
            "type": "string",
            "description": "Business organization code in the client's ERP"
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Flag to identify if the business organization is blocked (True/False)",
            "nullable": true
          },
          "groups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GroupDto"
            },
            "description": "List with the product groups. This list contains the `ClientGroupId`, `Description`, and `AssociateAll` fields."
          },
          "costCenters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterDto"
            },
            "description": "List with the cost centers associated with the business organization. This list contains the `ClientCostCenterId` and `Description` fields."
          },
          "businessOrganizationParents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationParentDto"
            },
            "description": "List with the business organizations parents. This list contains the `ClientParentCode` and `ParentEntityType` fields."
          }
        },
        "additionalProperties": false
      },
      "CreateResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "DeleteBusinessOrganizationParentsRelationshipsCommand": {
        "required": [
          "businessOrganizationParents"
        ],
        "type": "object",
        "properties": {
          "businessOrganizationParents": {
            "minItems": 1,
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationParentDto"
            },
            "description": "List with the business organizations parents. This list contains the `ClientParentCode` and `ParentEntityType` fields."
          }
        },
        "additionalProperties": false
      },
      "DeleteBusinessOrganizationParentsRelationshipsResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "DeleteCostCentersRelationshipsCommand": {
        "required": [
          "costCenters"
        ],
        "type": "object",
        "properties": {
          "costCenters": {
            "minItems": 1,
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterDto"
            },
            "description": "List with the cost centers associated with the business organization. This list contains the `ClientCostCenterId` and `Description` fields."
          }
        },
        "additionalProperties": false
      },
      "DeleteCostCentersRelationshipsResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "GetBusinessOrganizationChildrenResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetBusinessOrganizationChildrenResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetBusinessOrganizationChildrenResponseData": {
        "type": "object",
        "properties": {
          "businessOrganizationId": {
            "type": "integer",
            "description": "ME business organization id",
            "format": "int32"
          },
          "clientBusinessOrganizationId": {
            "type": "string",
            "description": "Code of the child-entities for the business organization in the client's ERP"
          },
          "entityType": {
            "type": "string",
            "description": "Type of child-entities for the organizational structure. Example: Company, branch."
          }
        },
        "additionalProperties": false
      },
      "GetBusinessOrganizationCostCentersResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetBusinessOrganizationCostCentersResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetBusinessOrganizationCostCentersResponseData": {
        "type": "object",
        "properties": {
          "clientCostCenterId": {
            "type": "string",
            "description": "Code of the cost center in the client's ERP\r\nREQUIRED if `Description` = Null"
          },
          "description": {
            "type": "string",
            "description": "Cost center description\r\nREQUIRED if `ClientCostCenterId` = Null"
          }
        },
        "additionalProperties": false
      },
      "GetBusinessOrganizationGroupsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetBusinessOrganizationGroupsResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetBusinessOrganizationGroupsResponseData": {
        "type": "object",
        "properties": {
          "groupId": {
            "type": "integer",
            "description": "ME group id",
            "format": "int32"
          },
          "clientGroupId": {
            "type": "string",
            "description": "Code of the product group in the client's ERP"
          },
          "description": {
            "type": "string",
            "description": "Product group description"
          }
        },
        "additionalProperties": false
      },
      "GetBusinessOrganizationParentsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetBusinessOrganizationParentsResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetBusinessOrganizationParentsResponseData": {
        "type": "object",
        "properties": {
          "businessOrganizationId": {
            "type": "integer",
            "description": "ME business organization id",
            "format": "int32"
          },
          "clientBusinessOrganizationId": {
            "type": "string",
            "description": "Code of the parent-entity for the business organization in the client's ERP"
          },
          "entityType": {
            "type": "string",
            "description": "Type of parent-entity for the organizational structure. Example: Company, branch."
          }
        },
        "additionalProperties": false
      },
      "GetByIdResponse": {
        "type": "object",
        "properties": {
          "entityType": {
            "type": "string",
            "description": "Type of organizational structure. Example: Company, branch, department."
          },
          "description": {
            "type": "string",
            "description": "Description of the business organization"
          },
          "clientBusinessOrganizationId": {
            "type": "string",
            "description": "Business organization code in the client's ERP"
          },
          "businessOrganizationId": {
            "type": "integer",
            "description": "ME business organization id",
            "format": "int32"
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Flag to identify if the business organization is blocked (True/False)",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GroupDto": {
        "required": [
          "clientGroupId",
          "description"
        ],
        "type": "object",
        "properties": {
          "clientGroupId": {
            "minLength": 1,
            "type": "string",
            "description": "Code of the product group in the client's ERP"
          },
          "description": {
            "minLength": 1,
            "type": "string",
            "description": "Product group description"
          },
          "associateAll": {
            "type": "boolean",
            "description": "Flag to associate all product groups with the business organization.\r\n- If `AssociateAll` = \"True\", then `Description` and `ClientGroupId` are REQUIRED.\r\n- If `AssociateAll` = \"False\", then:\r\n- `Description` and `ClientGroupId` can both be filled in.\r\nor\r\n- `ClientGroupId` is REQUIRED if `Description` = Null.\r\n- `Description` is REQUIRED if `ClientGroupId` = Null.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "ProblemDetails": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "instance": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": {}
      },
      "UpdateCommand": {
        "required": [
          "description",
          "entityType"
        ],
        "type": "object",
        "properties": {
          "entityType": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Type of organizational structure. Example: Company, branch, department."
          },
          "description": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Description of the business organization"
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Flag to identify if the business organization is blocked (True/False)",
            "nullable": true
          },
          "groups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GroupDto"
            },
            "description": "List with the product groups. This list contains the `ClientGroupId`, `Description`, and `AssociateAll` fields."
          },
          "costCenters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterDto"
            },
            "description": "List with the cost centers associated with the business organization. This list contains the `ClientCostCenterId` and `Description` fields."
          },
          "businessOrganizationParents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationParentDto"
            },
            "description": "List with the business organizations parents. This list contains the `ClientParentCode` and `ParentEntityType` fields."
          }
        },
        "additionalProperties": false
      },
      "UpdateResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "Bearer": {
        "type": "apiKey",
        "description": "Please enter the word 'Bearer' followed by a space and then your JWT.",
        "name": "Authorization",
        "in": "header"
      }
    }
  },
  "security": [
    {
      "Bearer": []
    }
  ]
}