{
  "openapi": "3.1.0",
  "info": {
    "title": "nudg API",
    "version": "1.0.0",
    "summary": "Read your own nudg data.",
    "description": "Read-only access to your own nudg score, daily signals, monthly spending and insights with a personal access token from the nudg app (You › AI apps › Developer tokens). Part of nudg plus. 500 calls a day per account, shared with connected AI apps.",
    "contact": {
      "email": "hello@trynudg.app",
      "url": "https://trynudg.app/developers"
    },
    "termsOfService": "https://trynudg.app/privacy#developer-api"
  },
  "servers": [
    {
      "url": "https://nudg-api.nudg-api.workers.dev"
    }
  ],
  "security": [
    {
      "token": []
    }
  ],
  "paths": {
    "/v1/today": {
      "get": {
        "operationId": "getToday",
        "summary": "Today's score and signals",
        "responses": {
          "200": {
            "description": "OK",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/Remaining"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "currency": {
                      "type": "string",
                      "example": "GBP"
                    },
                    "generated": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "date": {
                      "type": "string",
                      "format": "date"
                    },
                    "nudg_score": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "score_label": {
                      "type": "string"
                    },
                    "score_sleep": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "score_recovery": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "score_activity": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "score_screen": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "sleep_mins": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "hrv": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "resting_hr": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "steps": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "exercise_mins": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "screen_mins": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "pickups": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "spend": {
                      "type": [
                        "number",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/days": {
      "get": {
        "operationId": "listDays",
        "summary": "One row a day",
        "parameters": [
          {
            "name": "start",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Default 6 days ago (UTC)."
          },
          {
            "name": "end",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Default today (UTC)."
          },
          {
            "name": "fields",
            "in": "query",
            "style": "form",
            "explode": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "nudg_score",
                  "score_sleep",
                  "score_recovery",
                  "score_activity",
                  "score_screen",
                  "sleep_mins",
                  "hrv",
                  "resting_hr",
                  "steps",
                  "exercise_mins",
                  "screen_mins",
                  "pickups",
                  "notifications",
                  "social_mins",
                  "late_night_mins",
                  "spend",
                  "temp_max",
                  "rain_mm",
                  "aqi"
                ]
              }
            },
            "description": "Comma separated; default all."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/Remaining"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "currency": {
                      "type": "string",
                      "example": "GBP"
                    },
                    "generated": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "start": {
                      "type": "string",
                      "format": "date"
                    },
                    "end": {
                      "type": "string",
                      "format": "date"
                    },
                    "days": {
                      "type": "array",
                      "maxItems": 92,
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string",
                            "format": "date"
                          },
                          "nudg_score": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "score_sleep": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "score_recovery": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "score_activity": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "score_screen": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "sleep_mins": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "hrv": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "resting_hr": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "steps": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "exercise_mins": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "screen_mins": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "pickups": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "notifications": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "social_mins": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "late_night_mins": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "spend": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "temp_max": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "rain_mm": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "aqi": {
                            "type": [
                              "number",
                              "null"
                            ]
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/months": {
      "get": {
        "operationId": "listMonths",
        "summary": "Spending by category per month, your share after splits",
        "parameters": [
          {
            "name": "months",
            "in": "query",
            "style": "form",
            "explode": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}$"
              }
            },
            "description": "Default the last 12."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/Remaining"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "currency": {
                      "type": "string",
                      "example": "GBP"
                    },
                    "generated": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "months": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "month": {
                            "type": "string"
                          },
                          "total": {
                            "type": "number"
                          }
                        },
                        "additionalProperties": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/weeks": {
      "get": {
        "operationId": "listWeeks",
        "summary": "Weekly averages, keyed by Monday",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/Remaining"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "currency": {
                      "type": "string",
                      "example": "GBP"
                    },
                    "generated": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "weeks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "week": {
                            "type": "string",
                            "format": "date"
                          }
                        },
                        "additionalProperties": true
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/insights": {
      "get": {
        "operationId": "listInsights",
        "summary": "Your insight cards",
        "responses": {
          "200": {
            "description": "OK",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/Remaining"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "currency": {
                      "type": "string",
                      "example": "GBP"
                    },
                    "generated": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "cards": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "detail": {
                            "type": "string"
                          },
                          "strength": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "token": {
        "type": "http",
        "scheme": "bearer",
        "description": "A personal access token (nudg_pat_…) from the nudg app."
      }
    },
    "headers": {
      "Limit": {
        "schema": {
          "type": "integer"
        },
        "description": "Calls allowed a day."
      },
      "Remaining": {
        "schema": {
          "type": "integer"
        },
        "description": "Calls left today (UTC)."
      }
    },
    "responses": {
      "Error": {
        "description": "An error",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string",
                      "enum": [
                        "bad_range",
                        "bad_field",
                        "bad_month",
                        "unauthorised",
                        "needs_plus",
                        "not_found",
                        "no_data",
                        "method_not_allowed",
                        "daily_limit"
                      ]
                    },
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "code",
                    "message"
                  ]
                }
              }
            }
          }
        }
      }
    }
  }
}
