{
  "openapi": "3.0.1",
  "info": {
    "title": "UN Comtrade Trade Flow Watch",
    "description": "Bilateral commodity trade flows from UN Comtrade's official free API: annual trade records per reporter, partner, HS code and year, with values, weights and quantities, per-pair aggregates and change vs previous run. Official UN open data, no key needed. Latest published year per reporter.",
    "version": "0.1",
    "x-build-id": "Lzz4AOvvwFVm0WVAK"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/automatic~comtrade-trade-watch/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-automatic-comtrade-trade-watch",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/automatic~comtrade-trade-watch/runs": {
      "post": {
        "operationId": "runs-sync-automatic-comtrade-trade-watch",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/automatic~comtrade-trade-watch/run-sync": {
      "post": {
        "operationId": "run-sync-automatic-comtrade-trade-watch",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "properties": {
          "reporter": {
            "title": "Reporter (single-pair mode)",
            "type": "string",
            "description": "Reporting country for single-pair mode: an ISO numeric code ('604') or a name ('peru', 'china', 'united states'). Resolved against a static UN country list. Ignored when a watchlist is given.",
            "default": "peru"
          },
          "partner": {
            "title": "Partner (single-pair mode)",
            "type": "string",
            "description": "Partner country for single-pair mode: ISO numeric code, name, 'world'/'0' for the World aggregate. Defaults to 'world'. Ignored when a watchlist is given.",
            "default": "world"
          },
          "cmdCode": {
            "title": "HS commodity code (single-pair mode)",
            "type": "string",
            "description": "HS commodity code for single-pair mode ('8517' = phones, '2710' = petroleum oils). Chapter-level codes return aggregated rows; deeper codes return more detailed ones. Ignored when a watchlist is given.",
            "default": "8517"
          },
          "period": {
            "title": "Period (year)",
            "minimum": 2010,
            "maximum": 2100,
            "type": "integer",
            "description": "Reference year. Leave empty for the latest published year: the current calendar year and the two before it are tried per reporter, newest first, and the first with published figures is used. Set a year explicitly for older data."
          },
          "watchlist": {
            "title": "Watchlist of pairs",
            "maxItems": 25,
            "type": "array",
            "description": "Optional list of pairs to watch in one run (overrides reporter/partner/cmdCode/period). Each item: {reporter, partner, cmdCode, period} with the same value rules; 'period' may be omitted to use the default resolution.",
            "items": {
              "type": "object",
              "required": [
                "reporter",
                "cmdCode"
              ],
              "properties": {
                "reporter": {
                  "title": "Reporter",
                  "type": "string",
                  "minLength": 1,
                  "description": "Reporter ISO numeric code or name, e.g. 604 or peru."
                },
                "partner": {
                  "title": "Partner",
                  "type": "string",
                  "description": "Partner ISO numeric code, name, or world/0 for the World aggregate."
                },
                "cmdCode": {
                  "title": "HS commodity code",
                  "type": "string",
                  "minLength": 1,
                  "description": "HS commodity code, e.g. 8517 or 2710."
                },
                "period": {
                  "title": "Period (year)",
                  "type": "integer",
                  "description": "Reference year; omit to use the default resolution."
                }
              },
              "additionalProperties": false
            }
          },
          "requestDelaySecs": {
            "title": "Delay between pair requests",
            "minimum": 1,
            "maximum": 60,
            "type": "number",
            "description": "Pause between pair requests. The source is free but rate-limited, so keep the spacing moderate.",
            "default": 6
          },
          "maxResults": {
            "title": "Max records per pair",
            "minimum": 1,
            "maximum": 500,
            "type": "integer",
            "description": "Cap on records kept per pair after parsing (the endpoint itself caps at 500 rows per response).",
            "default": 500
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}