{
    "openapi": "3.0.3",
    "info": {
        "title": "Pijon Script API",
        "description": "Application-scoped notification sending and image uploads. Account management requires the authenticated app.",
        "version": "1.0.0"
    },
    "servers": [
        {
            "url": "https://api.pijon.fyi/api/v1"
        }
    ],
    "tags": [
        {
            "name": "Attachments",
            "description": ""
        },
        {
            "name": "Notifications",
            "description": ""
        }
    ],
    "components": {
        "securitySchemes": {
            "default": {
                "type": "http",
                "scheme": "bearer",
                "description": "Application-scoped bearer key. Test/live labels do not select a sandbox."
            }
        },
        "schemas": {
            "Notification": {
                "type": "object",
                "required": [
                    "id",
                    "application_id",
                    "recipient_id",
                    "title",
                    "body",
                    "status",
                    "endpoint_count"
                ],
                "properties": {
                    "id": {
                        "type": "string",
                        "minLength": 26,
                        "maxLength": 26,
                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                    },
                    "application_id": {
                        "type": "string",
                        "minLength": 26,
                        "maxLength": 26,
                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                    },
                    "recipient_id": {
                        "type": "string",
                        "minLength": 26,
                        "maxLength": 26,
                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                    },
                    "source_name": {
                        "type": "string"
                    },
                    "title": {
                        "type": "string"
                    },
                    "body": {
                        "type": "string"
                    },
                    "body_format": {
                        "type": "string",
                        "enum": [
                            "plain",
                            "markdown"
                        ]
                    },
                    "category_id": {
                        "type": "string",
                        "minLength": 26,
                        "maxLength": 26,
                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$",
                        "nullable": true
                    },
                    "category_name": {
                        "type": "string",
                        "description": "Display name snapshot captured on acceptance."
                    },
                    "preview": {
                        "type": "string"
                    },
                    "category": {
                        "type": "string",
                        "maxLength": 64,
                        "pattern": "^[a-z][a-z0-9_]*$",
                        "default": "general",
                        "description": "An active immutable key belonging to this application, approved by the recipient. Unknown/archived keys return 422 invalid_category."
                    },
                    "priority": {
                        "type": "string",
                        "description": "",
                        "enum": [
                            "silent",
                            "low",
                            "normal",
                            "high"
                        ],
                        "default": "normal"
                    },
                    "url": {
                        "type": "string",
                        "nullable": true
                    },
                    "url_title": {
                        "type": "string",
                        "nullable": true
                    },
                    "external_id": {
                        "type": "string",
                        "nullable": true
                    },
                    "attachment_id": {
                        "type": "string",
                        "minLength": 26,
                        "maxLength": 26,
                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$",
                        "nullable": true
                    },
                    "status": {
                        "type": "string",
                        "description": "Aggregate processing outcome, not guaranteed device display."
                    },
                    "endpoint_count": {
                        "type": "integer",
                        "minimum": 0
                    },
                    "created_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "event_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "expires_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "read_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "archived_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "synced_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "deliveries": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/Delivery"
                        }
                    }
                }
            },
            "Delivery": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string",
                        "minLength": 26,
                        "maxLength": 26,
                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                    },
                    "device_id": {
                        "type": "string",
                        "minLength": 26,
                        "maxLength": 26,
                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$",
                        "nullable": true
                    },
                    "endpoint_name": {
                        "type": "string",
                        "nullable": true
                    },
                    "provider": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string"
                    },
                    "attempts": {
                        "type": "integer"
                    },
                    "error_code": {
                        "type": "string",
                        "nullable": true
                    },
                    "provider_accepted_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "synced_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    },
                    "receipt_checked_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    }
                }
            },
            "Attachment": {
                "type": "object",
                "required": [
                    "id",
                    "mime_type",
                    "size",
                    "width",
                    "height",
                    "expires_at"
                ],
                "properties": {
                    "id": {
                        "type": "string",
                        "minLength": 26,
                        "maxLength": 26,
                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                    },
                    "mime_type": {
                        "type": "string",
                        "enum": [
                            "image/jpeg",
                            "image/png",
                            "image/webp"
                        ]
                    },
                    "size": {
                        "type": "integer"
                    },
                    "width": {
                        "type": "integer"
                    },
                    "height": {
                        "type": "integer"
                    },
                    "expires_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                    }
                }
            },
            "Error": {
                "type": "object",
                "required": [
                    "message"
                ],
                "properties": {
                    "message": {
                        "type": "string"
                    },
                    "reason": {
                        "type": "string"
                    },
                    "errors": {
                        "type": "object",
                        "additionalProperties": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    },
    "security": [
        {
            "default": []
        }
    ],
    "paths": {
        "/attachments": {
            "post": {
                "summary": "Upload one private notification image",
                "operationId": "postApiV1Attachments",
                "description": "JPEG/PNG/WebP, at most 5 MiB and 4096 x 4096 pixels. Returns an ID to use in attachment_id. Uploads are not idempotent.",
                "parameters": [],
                "responses": {
                    "201": {
                        "description": "Private image uploaded.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "data"
                                    ],
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Attachment"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Missing, invalid, or revoked credential.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Scope, account, application, or subscription rejection.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Unknown or foreign private resource.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Field validation or domain rejection.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Rate, quota, or queue admission limit.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        },
                        "headers": {
                            "Retry-After": {
                                "schema": {
                                    "type": "string"
                                },
                                "description": "Seconds or HTTP date before retrying."
                            }
                        }
                    },
                    "503": {
                        "description": "Service unavailable.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "tags": [
                    "Attachments"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "application_id": {
                                        "type": "string",
                                        "minLength": 26,
                                        "maxLength": 26,
                                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                                    },
                                    "image": {
                                        "type": "string",
                                        "format": "binary",
                                        "description": "JPEG, PNG, or WebP; maximum 5242880 bytes and 4096 x 4096 pixels."
                                    }
                                },
                                "required": [
                                    "application_id",
                                    "image"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "/notifications": {
            "post": {
                "summary": "Accept one notification for an approved recipient",
                "operationId": "postApiV1Notifications",
                "description": "202 is durable acceptance, not device display. Test/live key labels use the same delivery and quota pipeline.",
                "parameters": [
                    {
                        "in": "header",
                        "name": "Idempotency-Key",
                        "required": false,
                        "description": "Reuse for identical retries within 24 hours.",
                        "schema": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 128,
                            "pattern": "^[!-~]+$"
                        }
                    }
                ],
                "responses": {
                    "202": {
                        "description": "Durably accepted; replayed is false.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "data"
                                    ],
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "required": [
                                                "notification",
                                                "replayed"
                                            ],
                                            "properties": {
                                                "notification": {
                                                    "$ref": "#/components/schemas/Notification"
                                                },
                                                "replayed": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "200": {
                        "description": "Identical replay; original notification ID and replayed is true.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "data"
                                    ],
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "required": [
                                                "notification",
                                                "replayed"
                                            ],
                                            "properties": {
                                                "notification": {
                                                    "$ref": "#/components/schemas/Notification"
                                                },
                                                "replayed": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Missing, invalid, or revoked credential.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Scope, account, application, or subscription rejection.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Unknown or foreign private resource.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Field validation or domain rejection.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Rate, quota, or queue admission limit.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        },
                        "headers": {
                            "Retry-After": {
                                "schema": {
                                    "type": "string"
                                },
                                "description": "Seconds or HTTP date before retrying."
                            }
                        }
                    },
                    "503": {
                        "description": "Service unavailable.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Idempotency or external ID conflicts with another payload.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                },
                "tags": [
                    "Notifications"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "application_id": {
                                        "type": "string",
                                        "minLength": 26,
                                        "maxLength": 26,
                                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                                    },
                                    "recipient_id": {
                                        "type": "string",
                                        "minLength": 26,
                                        "maxLength": 26,
                                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                                    },
                                    "title": {
                                        "type": "string",
                                        "description": "Must not be greater than 120 characters.",
                                        "nullable": true,
                                        "maxLength": 120
                                    },
                                    "body": {
                                        "type": "string",
                                        "description": "Must not be greater than 10000 characters.",
                                        "maxLength": 10000,
                                        "minLength": 1
                                    },
                                    "body_format": {
                                        "type": "string",
                                        "description": "",
                                        "enum": [
                                            "plain",
                                            "markdown"
                                        ],
                                        "default": "plain"
                                    },
                                    "category": {
                                        "type": "string",
                                        "maxLength": 64,
                                        "pattern": "^[a-z][a-z0-9_]*$",
                                        "default": "general",
                                        "description": "An active immutable key belonging to this application, approved by the recipient. Unknown/archived keys return 422 invalid_category."
                                    },
                                    "priority": {
                                        "type": "string",
                                        "description": "",
                                        "enum": [
                                            "silent",
                                            "low",
                                            "normal",
                                            "high"
                                        ],
                                        "default": "normal"
                                    },
                                    "device_ids": {
                                        "type": "array",
                                        "nullable": true,
                                        "minItems": 1,
                                        "maxItems": 100,
                                        "items": {
                                            "type": "string",
                                            "minLength": 26,
                                            "maxLength": 26,
                                            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
                                        },
                                        "description": "Omit/null for all eligible endpoints. Empty array is rejected."
                                    },
                                    "external_id": {
                                        "type": "string",
                                        "description": "Must not be greater than 128 characters.",
                                        "nullable": true,
                                        "maxLength": 128
                                    },
                                    "url": {
                                        "type": "string",
                                        "description": "HTTP/HTTPS only, without embedded credentials.",
                                        "nullable": true,
                                        "maxLength": 2048,
                                        "format": "uri"
                                    },
                                    "url_title": {
                                        "type": "string",
                                        "description": "Must not be greater than 80 characters.",
                                        "nullable": true,
                                        "maxLength": 80
                                    },
                                    "attachment_id": {
                                        "type": "string",
                                        "minLength": 26,
                                        "maxLength": 26,
                                        "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$",
                                        "nullable": true
                                    },
                                    "event_at": {
                                        "type": "string",
                                        "format": "date-time",
                                        "nullable": true
                                    },
                                    "ttl": {
                                        "type": "integer",
                                        "minimum": 1,
                                        "maximum": 604800,
                                        "default": 86400
                                    }
                                },
                                "required": [
                                    "application_id",
                                    "recipient_id",
                                    "body"
                                ]
                            }
                        }
                    }
                }
            }
        }
    }
}
