{
  "openapi": "3.0.1",
  "info": {
    "title": "Cost Centers API",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.mercadoe.com"
    }
  ],
  "paths": {
    "/v1/cost-centers/business-organizations": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get the cost center business organizations",
        "description": "Get information about the business organizations for all cost centers.",
        "parameters": [
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllBusinessOrganizationsResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cost-centers/ledger-accounts": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get all cost centers x ledger accounts",
        "description": "Get a list of all cost centers with their related ledger accounts that are available to the connected user.",
        "parameters": [
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllLedgerAccountsResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cost-centers/service-orders": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get all cost centers x service orders",
        "description": "Get a list of all cost centers with their related service orders that are available to the connected user.",
        "parameters": [
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllServiceOrdersResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cost-centers": {
      "post": {
        "tags": [
          "Cost Centers"
        ],
        "summary": "Create a Cost Center",
        "description": "Create a new cost center by providing the cost center code, cost center 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"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Cost Centers"
        ],
        "summary": "Get all cost centers",
        "description": "Get a list of all cost centers that are available to the connected user.",
        "parameters": [
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cost-centers/{clientCostCenterId}": {
      "put": {
        "tags": [
          "Cost Centers"
        ],
        "summary": "Update a Cost Center based on the cost center Id",
        "description": "Change the specified fields of a cost center with the provided values by informing the `clientCostCenterId`.",
        "parameters": [
          {
            "name": "clientCostCenterId",
            "in": "path",
            "description": "The cost center Id in the ERP",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "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"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cost-centers/{clientCostCenterId}/relationships/delete": {
      "post": {
        "tags": [
          "Cost Centers"
        ],
        "summary": "Delete the Cost Center relationships based on the cost center Id",
        "description": "The Cost Center has three relationships: Ledger Accounts, Service Orders, and Business Organizations.\r\nYou can delete one or more relationships of a Cost Center with the provided values by informing the `clientCostCenterId`.",
        "parameters": [
          {
            "name": "clientCostCenterId",
            "in": "path",
            "description": "The cost center Id in the ERP",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "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/DeleteCommand"
              }
            }
          }
        },
        "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"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cost-centers/{clientCostCenterId}/relationships": {
      "put": {
        "tags": [
          "Cost Centers Relationships"
        ],
        "summary": "Update the relationships between ledgers and service orders with cost centers.",
        "description": "Based on the cost center, remove existing relationships and add new ones according to the received payload.",
        "parameters": [
          {
            "name": "clientCostCenterId",
            "in": "path",
            "description": "The cost center Id in the ERP",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "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/UpdateRelationshipCommand"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateRelationshipResponse"
                }
              }
            }
          },
          "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": [
          "Cost Centers Relationships"
        ],
        "summary": "Get all cost objects relationships by cost center Id",
        "description": "Get a list of all cost objects relationships that are available to the connected user.",
        "parameters": [
          {
            "name": "clientCostCenterId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "pageNumber",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAllRelationshipsResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BusinessOrganizationMinimal": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "entityType": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "BusinessOrganizationModel": {
        "required": [
          "code"
        ],
        "type": "object",
        "properties": {
          "code": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string"
          },
          "entityType": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "CreateCommand": {
        "required": [
          "clientCostCenterId",
          "description"
        ],
        "type": "object",
        "properties": {
          "clientCostCenterId": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Cost center code in the ERP"
          },
          "description": {
            "maxLength": 300,
            "minLength": 1,
            "type": "string",
            "description": "Cost center description"
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Flag for the deactivation of the cost center."
          },
          "status": {
            "type": "boolean",
            "description": "Cost center status is blocked?"
          },
          "validSince": {
            "type": "string",
            "description": "Beginning of the cost center's validity.\r\nDD/MM/YYYYYY format",
            "format": "date-time",
            "nullable": true
          },
          "validUntil": {
            "type": "string",
            "description": "End of the cost center's validity.\r\nDD/MM/YYYYYY format",
            "format": "date-time",
            "nullable": true
          },
          "purchasingOrganization": {
            "type": "string",
            "description": "Purchasing organization code in the ERP."
          },
          "company": {
            "type": "string",
            "description": "Company code in the ERP"
          },
          "center": {
            "type": "string",
            "description": "Center code in the ERP"
          },
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllLedgersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all ledgers are included",
            "nullable": true
          },
          "areAllServiceOrdersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all service orders are included",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationModel"
            },
            "description": "Business Organizations is a list consisting of the Company Code and the Entity type.",
            "nullable": true
          },
          "ledgerAccounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LedgerAccountModel"
            },
            "description": "List of ledger accounts (`LedgerCode` field) associated with the cost center.",
            "nullable": true
          },
          "serviceOrders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ServiceOrderModel"
            },
            "description": "List of service orders associated with the cost center.\r\nThis list is composed of the fields `ClientOrderId` and `Category`.",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Cost Center Command"
      },
      "CreateResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "DeleteCommand": {
        "type": "object",
        "properties": {
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllLedgersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all ledgers are included",
            "nullable": true
          },
          "areAllServiceOrdersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all service orders are included",
            "nullable": true
          },
          "ledgerAccounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LedgerAccountModel"
            },
            "description": "List of ledger accounts (`LedgerCode` field) associated with the cost center.",
            "nullable": true
          },
          "serviceOrders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ServiceOrderModel"
            },
            "description": "List of service orders associated with the cost center.\r\nThis list is composed of the fields `ClientOrderId` and `Category`.",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationModel"
            },
            "description": "Business Organizations is a list consisting of the Company Code and the Entity type.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllBusinessOrganizationsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllBusinessOrganizationsResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllBusinessOrganizationsResponseData": {
        "type": "object",
        "properties": {
          "costCenterId": {
            "type": "string",
            "description": "Cost center identifier"
          },
          "businessOrganization": {
            "$ref": "#/components/schemas/BusinessOrganizationMinimal"
          }
        },
        "additionalProperties": false
      },
      "GetAllLedgerAccountsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllLedgerAccountsResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllLedgerAccountsResponseData": {
        "type": "object",
        "properties": {
          "costCenterId": {
            "type": "string",
            "description": "Cost center identifier"
          },
          "ledgerAccount": {
            "$ref": "#/components/schemas/LedgerAccountModel"
          }
        },
        "additionalProperties": false
      },
      "GetAllRelationshipsData": {
        "type": "object",
        "properties": {
          "clientCostCenterId": {
            "type": "string",
            "description": "Cost center identifier"
          },
          "ledgerCode": {
            "type": "string",
            "description": "Ledger account code"
          },
          "clientOrderId": {
            "type": "string",
            "description": "The purchase order ID in the Client's ERP"
          },
          "clientOrderCategory": {
            "type": "string",
            "description": "Order category in the Client's ERP"
          }
        },
        "additionalProperties": false
      },
      "GetAllRelationshipsResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllRelationshipsData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllResponseData": {
        "type": "object",
        "properties": {
          "costCenterId": {
            "type": "string",
            "description": "Cost center identifier"
          },
          "code": {
            "type": "string",
            "description": "Cost center code",
            "nullable": true
          },
          "description": {
            "type": "string",
            "description": "Cost center description",
            "nullable": true
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Is this cost center deactivated? (True/False)",
            "nullable": true
          },
          "isIntegration": {
            "type": "boolean",
            "description": "Was this cost center created via integration? (True/false)",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllServiceOrdersResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllServiceOrdersResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllServiceOrdersResponseData": {
        "type": "object",
        "properties": {
          "costCenterId": {
            "type": "string",
            "description": "Cost center identifier"
          },
          "serviceOrder": {
            "$ref": "#/components/schemas/ServiceOrderMinimal"
          }
        },
        "additionalProperties": false
      },
      "LedgerAccountModel": {
        "required": [
          "ledgerCode"
        ],
        "type": "object",
        "properties": {
          "ledgerCode": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string"
          }
        },
        "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": {}
      },
      "RelationshipModel": {
        "required": [
          "category",
          "clientOrderId",
          "ledgerCode"
        ],
        "type": "object",
        "properties": {
          "ledgerCode": {
            "minLength": 1,
            "type": "string"
          },
          "areAllLedgersIncluded": {
            "type": "boolean"
          },
          "clientOrderId": {
            "minLength": 1,
            "type": "string"
          },
          "category": {
            "minLength": 1,
            "type": "string"
          },
          "areAllServiceOrdersIncluded": {
            "type": "boolean"
          }
        },
        "additionalProperties": false
      },
      "ServiceOrderMinimal": {
        "type": "object",
        "properties": {
          "order": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "ServiceOrderModel": {
        "required": [
          "category",
          "clientOrderId"
        ],
        "type": "object",
        "properties": {
          "clientOrderId": {
            "maxLength": 30,
            "minLength": 1,
            "type": "string"
          },
          "category": {
            "maxLength": 30,
            "minLength": 1,
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "UpdateCommand": {
        "type": "object",
        "properties": {
          "description": {
            "maxLength": 300,
            "type": "string",
            "description": "Cost center description",
            "nullable": true
          },
          "isDeactivated": {
            "type": "boolean",
            "description": "Flag for the deactivation of the cost center.",
            "nullable": true
          },
          "validSince": {
            "type": "string",
            "description": "Beginning of the cost center's validity.\r\nDD/MM/YYYYYY format",
            "format": "date-time",
            "nullable": true
          },
          "validUntil": {
            "type": "string",
            "description": "End of the cost center's validity.\r\nDD/MM/YYYYYY format",
            "format": "date-time",
            "nullable": true
          },
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllLedgersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all ledgers are included",
            "nullable": true
          },
          "areAllServiceOrdersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all service orders are included",
            "nullable": true
          },
          "ledgerAccounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LedgerAccountModel"
            },
            "description": "List of ledger accounts (`LedgerCode` field) associated with the cost center.",
            "nullable": true
          },
          "serviceOrders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ServiceOrderModel"
            },
            "description": "List of service orders associated with the cost center.\r\nThis list is composed of the fields `ClientOrderId` and `Category`.",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationModel"
            },
            "description": "Business Organizations is a list consisting of the Company Code and the Entity type.",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "UpdateRelationshipCommand": {
        "type": "object",
        "properties": {
          "relationships": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RelationshipModel"
            },
            "description": "Relationships with ledgers and service orders",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Cost Center Relationships Command"
      },
      "UpdateRelationshipResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "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": []
    }
  ]
}