API

API реализовано на GraphQL. Содержание этой страницы можно скопироть в
Claude - он поможет сгенерировать код для запросов.

GraphQL API

Схема: https://gist.github.com/alexesDev/a943c16053e29ba10d9e93c0e5d08960. Схему можно скормить клауду и попросить написать запрос — в ней вся необходимая информация.

Endpoint: https://blizzard.trip2g.com/graphql

Ключ апи создать тут: https://blizzard.trip2g.com/admin#!nav=apikeys
(для доступа сначала нужно авторизоваться на главной).

Ключ нужно передавать в заголовке X-API-Key.

Все запросы посылаются на один endpoint. Сам запрос - JSON с полями:

  • query - сам запрос
  • variables - переменные для запроса (необязательно)

Playground

Playground: https://blizzard.trip2g.com/graphql

Удобный инструмент для тестирования запросов. Позволяет:

  • писать и тестировать запросы
  • автодополнение
  • смотреть все методы и типы (навигация через ctrl + click)

Создание и обновление заметок

Запрос для теста в плейграйнде:

mutation {
  pushNotes(input:{updates:[{
    path: "/_index.md",
    content: "Hello world!"
  }]}) {
    ... on ErrorPayload {
      message
    }
    ... on PushNotesPayload {
      notes {
        id
        path

        assets {
          path
          sha256Hash
        }
      }
    }
  }
}

Для запросов из кода удобнее использовать переменные:

mutation PushNotes($input: PushNotesInput!) {
  pushNotes(input: $input) {
    ... on ErrorPayload {
      message
    }
    ... on PushNotesPayload {
      notes {
        id
        path

        assets {
          path
          sha256Hash
        }
      }
    }
  }
}
{
  "query": "...",
  "variables": {
    "input": {
      "updates": [
        {
          "path": "/_index.md",
          "content": "Hello world!"
        }
      ]
    }
  }
}

Получение путей всех заметок

query {
  notePaths(filter: { like: "/blog/%" }) {
    value
    latestNoteView {
      title
      content
      toc { title }
      meta { key, raw }
    }
  }
}

Пример на Go

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

type GraphQLRequest struct {
    Query string `json:"query"`
}

type NotePathsResponse struct {
    Data struct {
        NotePaths []struct {
            Value string `json:"value"`
        } `json:"notePaths"`
    } `json:"data"`
}

func getNotePaths(apiKey string) ([]string, error) {
    query := `query {
        notePaths {
            value
        }
    }`
    
    reqBody := GraphQLRequest{Query: query}
    jsonData, err := json.Marshal(reqBody)
    if err != nil {
        return nil, err
    }
    
    req, err := http.NewRequest("POST", "https://blizzard.trip2g.com/graphql", bytes.NewBuffer(jsonData))
    if err != nil {
        return nil, err
    }
    
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("X-API-Key", apiKey)
    
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()
    
    body, err := io.ReadAll(resp.Body)
    if err != nil {
        return nil, err
    }
    
    var response NotePathsResponse
    if err := json.Unmarshal(body, &response); err != nil {
        return nil, err
    }
    
    var paths []string
    for _, notePath := range response.Data.NotePaths {
        paths = append(paths, notePath.Value)
    }
    
    return paths, nil
}

func main() {
    apiKey := "your-api-key-here"
    paths, err := getNotePaths(apiKey)
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    
    fmt.Println("Note paths:")
    for _, path := range paths {
        fmt.Println(path)
    }
}

Скрытие заметки

mutation HideNotes($input: HideNotesInput!) {
  hideNotes(input: $input) {
    ... on HideNotesPayload {
      success
    }
    ... on ErrorPayload {
      message
    }
  }
}