{
  "openapi": "3.1.0",
  "info": {
    "title": "Petodo API for assistants and agents",
    "version": "1.0.0",
    "description": "Read and change the to-do list of a Petodo account, and follow the errands handed to an agent. This covers what an assistant key or agent key may call. An assistant key reaches the list and nothing else: account routes (email address, other keys, devices, syncing a whole list) answer 403. Assistant keys may read the list 120 times an hour per account and change it 600 times an hour.",
    "contact": {
      "url": "https://petodoapp.com/petodo/guides/to-do-list-api/"
    }
  },
  "servers": [
    {
      "url": "https://app.petodoapp.com/api"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/todos": {
      "get": {
        "summary": "List tasks",
        "description": "Open tasks by default. Timed tasks sort first, then the person's own order. The answer also carries series, the repeating rules behind the list.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "done",
                "all"
              ]
            },
            "description": "Defaults to open."
          },
          {
            "name": "day",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "today",
                "tomorrow",
                "all"
              ]
            },
            "description": "Defaults to all."
          },
          {
            "name": "listId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "A list id from lists. Defaults to all lists."
          },
          {
            "name": "include",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "series"
              ]
            },
            "description": "series includes repeating rules among the tasks."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/Locked"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "summary": "Add a task",
        "description": "Times in the title are read in the account's timezone (\"call Sam 2pm\"). A title that starts with @handle is an errand for that agent.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title"
                ],
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "day": {
                    "type": "string",
                    "enum": [
                      "today",
                      "tomorrow"
                    ]
                  },
                  "dueAt": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Overrides any time found in the title."
                  },
                  "listId": {
                    "type": "string"
                  },
                  "repeat": {
                    "type": "object",
                    "description": "A repeating rule. Overrides any repeat found in the title.",
                    "properties": {
                      "every": {
                        "type": "string",
                        "enum": [
                          "day",
                          "week"
                        ]
                      },
                      "interval": {
                        "type": "integer"
                      },
                      "weekdays": {
                        "type": "array",
                        "items": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 6
                        },
                        "description": "0 is Sunday. Weekly rules only."
                      },
                      "time": {
                        "type": "string",
                        "example": "18:00"
                      },
                      "start": {
                        "type": "string",
                        "format": "date"
                      },
                      "until": {
                        "type": "string",
                        "format": "date"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The created task",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/Locked"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/todos/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "The task's id, from GET /todos."
        }
      ],
      "patch": {
        "summary": "Change a task",
        "description": "Send any subset of title, dueAt, day and done. dueAt null clears the time. focus true marks it as the task being worked on, false stops it; send focus on its own, with no other field.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "dueAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "day": {
                    "type": "string",
                    "enum": [
                      "today",
                      "tomorrow"
                    ]
                  },
                  "done": {
                    "type": "boolean"
                  },
                  "focus": {
                    "type": "boolean",
                    "description": "Sent on its own: a body with focus and any other field is refused."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/Locked"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "summary": "Complete or reopen a task",
        "description": "done true completes it, done false reopens it.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "done": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/Locked"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "delete": {
        "summary": "Delete a task",
        "description": "Deleting a repeating rule stops the repeat and removes the days still to come.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/Locked"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/report": {
      "get": {
        "summary": "Summary of the list",
        "description": "Counts, overdue and due-soon lists, streak, a per-list breakdown and a plain English summary string. snapshotAgeSeconds says how long since anything changed.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/Locked"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/insights": {
      "get": {
        "summary": "How long things take",
        "description": "Built from stamps the list already carries. period is week, month or all.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "week",
                "month",
                "all"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/Locked"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/agents/errands": {
      "get": {
        "summary": "Errands waiting for this key's agents",
        "description": "The due, unfinished errands for the agents pointed at this key, and the groups they are in. checkAgainSeconds says when to look next.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/ProRequired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/agents/errands/{ref}": {
      "parameters": [
        {
          "name": "ref",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^#?[0-9a-fA-F]{6}$"
          },
          "description": "An errand's six character reference, from GET /agents/errands."
        }
      ],
      "post": {
        "summary": "Report on an errand",
        "description": "Send progress, a result or a question to another agent. A status never moves backwards and done ticks the task off.",
        "security": [
          {
            "bearer": []
          },
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Send status, or text in the words a Telegram bot would use, or ask.",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "confirmed",
                      "started",
                      "working",
                      "done",
                      "failed"
                    ]
                  },
                  "note": {
                    "type": "string"
                  },
                  "text": {
                    "type": "string",
                    "description": "For example \"done: the result\"."
                  },
                  "ask": {
                    "type": "object",
                    "properties": {
                      "to": {
                        "type": "string"
                      },
                      "text": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "to",
                      "text"
                    ]
                  },
                  "as": {
                    "type": "string",
                    "description": "Which of the key's handles is answering when an errand reached several through a group."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "402": {
            "$ref": "#/components/responses/ProRequired"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/errands/reply/{token}": {
      "parameters": [
        {
          "name": "token",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "minLength": 20,
            "maxLength": 2000
          },
          "description": "The signed token carried in the replyUrl of a webhook errand."
        }
      ],
      "post": {
        "summary": "Answer one webhook errand",
        "description": "Open: the signed token in the path is the whole credential, good for that one errand and agent for 14 days. Takes the same body as POST /agents/errands/{ref}.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Send status, or text in the words a Telegram bot would use, or ask.",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "confirmed",
                      "started",
                      "working",
                      "done",
                      "failed"
                    ]
                  },
                  "note": {
                    "type": "string"
                  },
                  "text": {
                    "type": "string",
                    "description": "For example \"done: the result\"."
                  },
                  "ask": {
                    "type": "object",
                    "properties": {
                      "to": {
                        "type": "string"
                      },
                      "text": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "to",
                      "text"
                    ]
                  },
                  "as": {
                    "type": "string",
                    "description": "Which of the key's handles is answering when an errand reached several through a group."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Connectivity check",
        "description": "No key needed. Says authenticated true when a valid key was sent.",
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "authenticated": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "An agent key, or a token from the OAuth 2.1 sign-in described at https://petodoapp.com/auth.md."
      },
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "The same key, sent as a header of its own."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "A missing or invalid key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "A valid key used on something it is not for: an account route, or, for a read-only key (code read_only), any change.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "An assistant key is over its hourly reads (code read_limit) or writes.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Locked": {
        "description": "The account is locked (code locked): its free week or subscription has ended. A free account's one assistant key works on the list otherwise.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ProRequired": {
        "description": "Either the account is locked (code locked) or it has no subscription (code pro_required): errands for agents are part of the subscription.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
