{
  "openapi": "3.0.3",
  "info": {
    "title": "Index Monitor API",
    "version": "0.6.12",
    "description": "Klucze z Profilu. Punkty pochodzą ze wszystkich aktywnych pul; utworzenie kampanii rezerwuje zgłoszenia i pierwsze sprawdzenia. Program Windows / GSC jest początkowo w przygotowaniu."
  },
  "servers": [
    {
      "url": "https://index.i4a.pl/api",
      "description": "API Index Monitor"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    },
    {
      "apiKeyHeader": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    }
  },
  "paths": {
    "/account.php": {
      "get": {
        "operationId": "account",
        "summary": "Dostępne punkty i konto",
        "responses": {
          "200": {
            "description": "Sukces",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "user_id": {
                          "type": "integer"
                        },
                        "email": {
                          "type": "string",
                          "format": "email"
                        },
                        "credits": {
                          "type": "integer",
                          "minimum": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/campaign_create.php": {
      "post": {
        "operationId": "createCampaign",
        "summary": "Utwórz kampanię i zarezerwuj środki na pierwszą kolejkę",
        "responses": {
          "200": {
            "description": "Sukces",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "campaign_id": {
                          "type": "integer"
                        },
                        "urls": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "duplicates": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "estimated_max_cost": {
                          "type": "integer",
                          "minimum": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 190
                  },
                  "urls": {
                    "type": "string",
                    "description": "Pełne adresy URL, po jednym w linii."
                  },
                  "indexing_enabled": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "monitoring_enabled": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "indexing_mode": {
                    "type": "string",
                    "enum": [
                      "immediate",
                      "dripfeed"
                    ],
                    "default": "immediate"
                  },
                  "indexing_start_at": {
                    "type": "string",
                    "description": "YYYY-MM-DD HH:MM:SS, strefa czasu serwisu."
                  },
                  "indexing_daily_limit": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 100
                  },
                  "monitor_provider": {
                    "type": "string",
                    "enum": [
                      "system",
                      "desktop_gsc"
                    ],
                    "default": "system",
                    "description": "GSC wymaga udostępnionego klienta Windows."
                  },
                  "monitor_mode": {
                    "type": "string",
                    "enum": [
                      "none",
                      "once",
                      "interval",
                      "until_indexed"
                    ]
                  },
                  "monitor_first_delay_days": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 7
                  },
                  "monitor_interval_days": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 7
                  },
                  "monitor_max_checks": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0
                  },
                  "monitor_end_at": {
                    "type": "string",
                    "nullable": true
                  },
                  "stop_monitoring_when_indexed": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "auto_resubmit": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "resubmit_after_failed_checks": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 2
                  },
                  "max_resubmits": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0
                  }
                },
                "required": [
                  "name",
                  "urls"
                ],
                "description": "Włącz co najmniej jeden moduł: indexing_enabled lub monitoring_enabled. Brak środków odrzuca całość. Brak klucza idempotencji: nie powtarzaj automatycznie żądania po timeoutcie."
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 190
                  },
                  "urls": {
                    "type": "string",
                    "description": "Pełne adresy URL, po jednym w linii."
                  },
                  "indexing_enabled": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "monitoring_enabled": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "indexing_mode": {
                    "type": "string",
                    "enum": [
                      "immediate",
                      "dripfeed"
                    ],
                    "default": "immediate"
                  },
                  "indexing_start_at": {
                    "type": "string",
                    "description": "YYYY-MM-DD HH:MM:SS, strefa czasu serwisu."
                  },
                  "indexing_daily_limit": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 100
                  },
                  "monitor_provider": {
                    "type": "string",
                    "enum": [
                      "system",
                      "desktop_gsc"
                    ],
                    "default": "system",
                    "description": "GSC wymaga udostępnionego klienta Windows."
                  },
                  "monitor_mode": {
                    "type": "string",
                    "enum": [
                      "none",
                      "once",
                      "interval",
                      "until_indexed"
                    ]
                  },
                  "monitor_first_delay_days": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 7
                  },
                  "monitor_interval_days": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 7
                  },
                  "monitor_max_checks": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0
                  },
                  "monitor_end_at": {
                    "type": "string",
                    "nullable": true
                  },
                  "stop_monitoring_when_indexed": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "auto_resubmit": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ]
                  },
                  "resubmit_after_failed_checks": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 2
                  },
                  "max_resubmits": {
                    "type": "integer",
                    "minimum": 0,
                    "default": 0
                  }
                },
                "required": [
                  "name",
                  "urls"
                ],
                "description": "Włącz co najmniej jeden moduł: indexing_enabled lub monitoring_enabled. Brak środków odrzuca całość. Brak klucza idempotencji: nie powtarzaj automatycznie żądania po timeoutcie."
              }
            }
          }
        }
      }
    },
    "/campaign_status.php": {
      "get": {
        "operationId": "campaignStatus",
        "summary": "Ustawienia i grupy stanów URL",
        "responses": {
          "200": {
            "description": "Sukces",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "campaign": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "integer"
                            },
                            "name": {
                              "type": "string"
                            },
                            "status": {
                              "type": "string",
                              "description": "active/paused to stan pracy, nie wyliczony status zakończenia."
                            },
                            "archived_at": {
                              "type": "string",
                              "nullable": true
                            }
                          },
                          "additionalProperties": true
                        },
                        "groups": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "submit_status": {
                                "type": "string"
                              },
                              "index_status": {
                                "type": "string"
                              },
                              "monitoring_status": {
                                "type": "string"
                              },
                              "cnt": {
                                "type": "integer"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ]
      }
    },
    "/urls_add.php": {
      "post": {
        "operationId": "addUrls",
        "summary": "Dodaj i sfinansuj nowe URL-e pojedynczo; dopuszczalny wynik częściowy",
        "responses": {
          "200": {
            "description": "Sukces",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "added": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "funding_rejected": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "invalid": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "duplicates_in_input": {
                          "type": "integer",
                          "minimum": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "campaign_id": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "urls": {
                    "type": "string",
                    "description": "Pełne adresy URL, po jednym w linii."
                  }
                },
                "required": [
                  "campaign_id",
                  "urls"
                ]
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "campaign_id": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "urls": {
                    "type": "string",
                    "description": "Pełne adresy URL, po jednym w linii."
                  }
                },
                "required": [
                  "campaign_id",
                  "urls"
                ]
              }
            }
          }
        }
      }
    },
    "/jobs_fetch.php": {
      "get": {
        "operationId": "fetchDesktopJobs",
        "summary": "Przypisz zadania desktopowe do klucza; rezerwuje punkty",
        "responses": {
          "200": {
            "description": "Sukces",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "jobs": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "integer"
                              },
                              "type": {
                                "type": "string",
                                "enum": [
                                  "check",
                                  "submit",
                                  "resubmit"
                                ]
                              },
                              "campaign_id": {
                                "type": "integer"
                              },
                              "campaign_url_id": {
                                "type": "integer"
                              },
                              "scheduled_at": {
                                "type": "string"
                              },
                              "attempt": {
                                "type": "integer"
                              },
                              "claim_token": {
                                "type": "string"
                              },
                              "payload": {
                                "type": "object",
                                "properties": {
                                  "url": {
                                    "type": "string",
                                    "format": "uri"
                                  }
                                },
                                "additionalProperties": true
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 20,
              "maximum": 100
            }
          }
        ]
      }
    },
    "/jobs_result.php": {
      "post": {
        "operationId": "completeDesktopJob",
        "summary": "Wynik zadania odebranego tym samym kluczem i claim_token",
        "responses": {
          "200": {
            "description": "Sukces",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "job_id": {
                          "type": "integer"
                        },
                        "result": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Błąd; opis w error.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "error"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        false
                      ]
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "job_id": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "claim_token": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "indexed",
                      "not_indexed",
                      "submitted",
                      "error"
                    ],
                    "description": "check: indexed/not_indexed/error; submit/resubmit: submitted/error."
                  },
                  "message": {
                    "type": "string"
                  },
                  "error": {
                    "type": "string",
                    "maxLength": 500
                  }
                },
                "required": [
                  "job_id",
                  "claim_token",
                  "status"
                ]
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "job_id": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "claim_token": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "indexed",
                      "not_indexed",
                      "submitted",
                      "error"
                    ],
                    "description": "check: indexed/not_indexed/error; submit/resubmit: submitted/error."
                  },
                  "message": {
                    "type": "string"
                  },
                  "error": {
                    "type": "string",
                    "maxLength": 500
                  }
                },
                "required": [
                  "job_id",
                  "claim_token",
                  "status"
                ]
              }
            }
          }
        }
      }
    }
  }
}
