{
  "openapi": "3.0.1",
  "info": {
    "title": "Service Orders Api",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.mercadoe.com"
    }
  ],
  "paths": {
    "/v1/service-orders/business-organizations": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get all service orders x business organizations",
        "description": "Get a list of all service orders with their related business organizations 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/GetAllBusinessOrganizationsResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/service-orders/cost-centers": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get all service orders x cost centers",
        "description": "Get a list of all service orders with their related 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/GetAllCostCentersResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/service-orders/ledger-accounts": {
      "get": {
        "tags": [
          "Associated Processes"
        ],
        "summary": "Get all service orders x ledger accounts",
        "description": "Get a list of all service orders 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/GetAllLedgersResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/service-orders": {
      "post": {
        "tags": [
          "Service Orders"
        ],
        "summary": "Create a service order",
        "description": "Create a new service order by providing the code, description, category and other details, if applicable.",
        "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": [
          "Service Orders"
        ],
        "summary": "Get all service orders",
        "description": "Get a list of all 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/GetAllResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/v1/service-orders/{order}": {
      "put": {
        "tags": [
          "Service Orders"
        ],
        "summary": "Update a service order by Id",
        "description": "Change the specified fields of a service order with the provided values by informing the service order code (`order` field).",
        "parameters": [
          {
            "name": "order",
            "in": "path",
            "description": "Service order code",
            "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/service-orders/{order}/relationships/delete": {
      "post": {
        "tags": [
          "Service Orders"
        ],
        "summary": "Delete the Service Order relationships based on the Service order code",
        "description": "The Service Order has three relationships: Ledger Accounts, Cost Centers, and Business Organizations.\r\nYou can delete one or more relationships of a Service Order with the provided values by informing the service order code (`order` field).",
        "parameters": [
          {
            "name": "order",
            "in": "path",
            "description": "Service order code",
            "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": {
          "204": {
            "description": "No Content",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "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": {
        "type": "object",
        "properties": {
          "code": {
            "maxLength": 50,
            "type": "string"
          },
          "entityType": {
            "maxLength": 50,
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "CostCenterModel": {
        "type": "object",
        "properties": {
          "costCenter": {
            "maxLength": 20,
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "CreateCommand": {
        "required": [
          "clientCategoryId",
          "description",
          "order"
        ],
        "type": "object",
        "properties": {
          "order": {
            "maxLength": 30,
            "minLength": 1,
            "type": "string",
            "description": "Service order code"
          },
          "description": {
            "maxLength": 50,
            "minLength": 1,
            "type": "string",
            "description": "Service order description"
          },
          "clientCategoryId": {
            "maxLength": 30,
            "minLength": 1,
            "type": "string",
            "description": "Client category code"
          },
          "clientOrderId": {
            "maxLength": 39,
            "type": "string",
            "description": "Client service order code"
          },
          "status": {
            "maxLength": 1,
            "type": "string",
            "description": "Service order status"
          },
          "validateDate": {
            "type": "string",
            "description": "Validate date",
            "format": "date-time",
            "nullable": true
          },
          "tolerance": {
            "type": "number",
            "description": "Service order spending tolerance",
            "format": "double",
            "nullable": true
          },
          "originalValue": {
            "type": "number",
            "description": "Service order original value",
            "format": "double",
            "nullable": true
          },
          "balance": {
            "type": "number",
            "description": "Service order balance",
            "format": "double",
            "nullable": true
          },
          "effort": {
            "type": "number",
            "description": "Reserved value within the service order.",
            "format": "double",
            "nullable": true
          },
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllCostCentersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all cost centers are included",
            "nullable": true
          },
          "areAllLedgersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all ledgers are included",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationModel"
            },
            "description": "Business Organizations is a list consisting of the `Code` (company code) and the `EntityType` fields."
          },
          "costCenters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterModel"
            },
            "description": "Cost centers is a list consisting of the `costCenter` field which is associated with that service order."
          },
          "ledgers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LedgerModel"
            },
            "description": "Ledgers is a list consisting of the ledger account code which is associated with that service order."
          }
        },
        "additionalProperties": false
      },
      "CreateResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "DeleteCommand": {
        "required": [
          "clientCategoryId"
        ],
        "type": "object",
        "properties": {
          "clientCategoryId": {
            "maxLength": 30,
            "minLength": 1,
            "type": "string",
            "description": "Client category code"
          },
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllCostCentersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all cost centers are included",
            "nullable": true
          },
          "areAllLedgersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all ledgers are included",
            "nullable": true
          },
          "costCenters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterModel"
            },
            "description": "Cost centers is a list consisting of the `costCenter` field which is associated with that service order.",
            "nullable": true
          },
          "ledgers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LedgerModel"
            },
            "description": "Ledgers is a list consisting of the ledger account code which is associated with that service order.",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationModel"
            },
            "description": "Business Organizations is a list consisting of the `Code` (company code) and the `EntityType` fields."
          }
        },
        "additionalProperties": false
      },
      "DeleteResponse": {
        "type": "object",
        "properties": {
          "correlationId": {
            "type": "string"
          }
        },
        "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": {
          "order": {
            "type": "string",
            "description": "Service order code"
          },
          "clientOrderId": {
            "type": "string",
            "description": "Service order ID in the Client's ERP"
          },
          "businessOrganization": {
            "$ref": "#/components/schemas/BusinessOrganizationMinimal"
          }
        },
        "additionalProperties": false
      },
      "GetAllCostCentersResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllCostCentersResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllCostCentersResponseData": {
        "type": "object",
        "properties": {
          "order": {
            "type": "string",
            "description": "Service order code"
          },
          "costCenter": {
            "$ref": "#/components/schemas/CostCenterModel"
          }
        },
        "additionalProperties": false
      },
      "GetAllLedgersResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GetAllLedgersResponseData"
            }
          },
          "hits": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "GetAllLedgersResponseData": {
        "type": "object",
        "properties": {
          "order": {
            "type": "string",
            "description": "Service order code"
          },
          "category": {
            "type": "string",
            "description": "Service order category"
          },
          "ledgerAccount": {
            "$ref": "#/components/schemas/LedgerModel"
          }
        },
        "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": {
          "order": {
            "type": "string",
            "description": "Service order code"
          },
          "clientOrderId": {
            "type": "string",
            "description": "Service order ID in the Client's ERP"
          },
          "description": {
            "type": "string",
            "description": "Service order description"
          },
          "category": {
            "type": "string",
            "description": "Service order category"
          },
          "status": {
            "type": "string",
            "description": "Service order status"
          }
        },
        "additionalProperties": false
      },
      "LedgerModel": {
        "type": "object",
        "properties": {
          "ledger": {
            "maxLength": 50,
            "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": {}
      },
      "UpdateCommand": {
        "type": "object",
        "properties": {
          "description": {
            "maxLength": 50,
            "type": "string",
            "description": "Service order description",
            "nullable": true
          },
          "clientCategoryId": {
            "type": "string",
            "description": "Client category code",
            "nullable": true
          },
          "status": {
            "maxLength": 1,
            "type": "string",
            "description": "Service order status",
            "nullable": true
          },
          "validateDate": {
            "type": "string",
            "description": "Validate date",
            "format": "date-time",
            "nullable": true
          },
          "tolerance": {
            "type": "number",
            "description": "Service order spending tolerance",
            "format": "double",
            "nullable": true
          },
          "originalValue": {
            "type": "number",
            "description": "Service order original value",
            "format": "double",
            "nullable": true
          },
          "balance": {
            "type": "number",
            "description": "Service order balance",
            "format": "double",
            "nullable": true
          },
          "effort": {
            "type": "number",
            "description": "Reserved value within the service order.",
            "format": "double",
            "nullable": true
          },
          "areAllBusinessOrganizationsIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all business organizations are included",
            "nullable": true
          },
          "areAllCostCentersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all cost centers are included",
            "nullable": true
          },
          "areAllLedgersIncluded": {
            "type": "boolean",
            "description": "Flag to identify if all ledgers are included",
            "nullable": true
          },
          "costCenters": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CostCenterModel"
            },
            "description": "Cost centers is a list consisting of the `costCenter` field which is associated with that service order.",
            "nullable": true
          },
          "ledgers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LedgerModel"
            },
            "description": "Ledgers is a list consisting of the ledger account code which is associated with that service order.",
            "nullable": true
          },
          "businessOrganizations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BusinessOrganizationModel"
            },
            "description": "Business Organizations is a list consisting of the `Code` (company code) and the `EntityType` 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": []
    }
  ]
}