Примеры запросов¶
Base URL:
https://ocrbot.ru/api/v1/
В каждом примере заменитеВАШ_КЛЮЧ
на актуальный API‑ключ.
Содержание¶
- Отправка задачи в распознавание
- Получение списка задач
- Получение статуса задачи
- Получение распознанных документов
- Получение информации о балансе
- Получение информации о подписке
- Установка вебхука
- Удаление вебхука
Отправка задачи в распознавание POST /tasks
¶
Python¶
import base64, requests
with open("ИЗОБРАЖЕНИЕ", "rb") as f:
img_b64 = base64.b64encode(f.read()).decode()
headers = {"X-Api-Key": "ВАШ API КЛЮЧ"}
payload = {"image": img_b64, "return_type": "json"}
r = requests.post("https://ocrbot.ru/api/v1/tasks", headers=headers, json=payload)
print(r.json())
curl¶
API_KEY="ВАШ API КЛЮЧ"
IMG="/path/to/image"
curl -X POST https://ocrbot.ru/api/v1/tasks \
-H "X-Api-Key: ${API_KEY}" \
-H "Content-Type: application/json" \
--data @<( \
printf '{ "image":"'; \
base64 -w0 "${IMG}"; \
printf '","return_type":"json" }' \
)
JavaScript (Node.js + axios)¶
import axios from "axios";
import fs from "fs";
const imgB64 = fs.readFileSync("test.jpg", { encoding: "base64" });
const res = await axios.post(
"https://ocrbot.ru/api/v1/tasks",
{ image: imgB64, return_type: "json" },
{ headers: { "X-Api-Key": "ВАШ API КЛЮЧ" } }
);
console.log(res.data);
Go¶
package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"bytes"
)
func main() {
img, _ := ioutil.ReadFile("ИЗОБРАЖЕНИЕ")
imgB64 := base64.StdEncoding.EncodeToString(img)
body, _ := json.Marshal(map[string]interface{}{"image": imgB64, "return_type": "json"})
req, _ := http.NewRequest("POST", "https://ocrbot.ru/api/v1/tasks", bytes.NewBuffer(body))
req.Header.Set("X-Api-Key", "ВАШ API КЛЮЧ")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
resBody, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(resBody))
}
2. Получение списка задач — GET /tasks
¶
Python¶
import requests
r = requests.get("https://ocrbot.ru/api/v1/tasks", headers={"X-Api-Key": "ВАШ API КЛЮЧ"})
print(r.json())
curl¶
API_KEY="ВАШ API КЛЮЧ"
curl -X GET https://ocrbot.ru/api/v1/tasks -H "X-Api-Key: $API_KEY"
JavaScript¶
import axios from "axios";
const { data } = await axios.get("https://ocrbot.ru/api/v1/tasks", {
headers: { "X-Api-Key": "ВАШ API КЛЮЧ" }
});
console.log(data);
Go¶
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://ocrbot.ru/api/v1/tasks", nil)
req.Header.Set("X-Api-Key", "ВАШ API КЛЮЧ")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
3. Получение статуса задачи — GET /tasks/{task_id}/status
¶
Python¶
import requests
task_id = 'ID задачи'
url = f"https://ocrbot.ru/api/v1/tasks/{task_id}/status"
r = requests.get(url, headers={"X-Api-Key": "ВАШ API КЛЮЧ"})
print(r.json())
curl¶
API_KEY="ВАШ API КЛЮЧ"
TASK_ID="ID задачи"
curl -X GET https://ocrbot.ru/api/v1/tasks/$TASK_ID/status -H "X-Api-Key: $API_KEY"
JavaScript¶
import axios from "axios";
const taskId = "c4d1c7b6-89e5-48d2-bfae-01b61e2c68da";
const { data } = await axios.get(
`https://ocrbot.ru/api/v1/tasks/${taskId}/status`,
{ headers: { "X-Api-Key": "ВАШ API КЛЮЧ" } }
);
console.log(data);
Go¶
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
taskId := "c4d1c7b6-89e5-48d2-bfae-01b61e2c68da"
url := fmt.Sprintf("https://ocrbot.ru/api/v1/tasks/%s/status", taskId)
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("X-Api-Key", "ВАШ API КЛЮЧ")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
4. Получение распознанных документов — GET /tasks/{task_id}/result
¶
Python¶
import requests
task_id = "ID задачи"
url = f"https://ocrbot.ru/api/v1/tasks/{task_id}/result"
r = requests.get(url, headers={"X-Api-Key": "ВАШ API КЛЮЧ"})
print(r.json())
curl¶
API_KEY="ВАШ API КЛЮЧ"
TASK_ID="ID задачи"
curl -s -X GET "https://ocrbot.ru/api/v1/tasks/${TASK_ID}/result" \
-H "X-Api-Key: ${API_KEY}" |
jq '.recognition_result' > data.dat
JavaScript¶
import axios from "axios";
const taskId = "c4d1c7b6-89e5-48d2-bfae-01b61e2c68da";
const { data } = await axios.get(
`https://ocrbot.ru/api/v1/tasks/${taskId}/result`,
{ headers: { "X-Api-Key": "ВАШ API КЛЮЧ" } }
);
console.log(data);
Go¶
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
taskId := "c4d1c7b6-89e5-48d2-bfae-01b61e2c68da"
url := fmt.Sprintf("https://ocrbot.ru/api/v1/tasks/%s/result", taskId)
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("X-Api-Key", "ВАШ API КЛЮЧ")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
5. Получение информации о балансе — GET /account/balance
¶
Python¶
import requests
r = requests.get("https://ocrbot.ru/api/v1/account/balance",
headers={"X-Api-Key": "ВАШ API КЛЮЧ"})
print(r.json())
curl¶
API_KEY="ВАШ API КЛЮЧ"
curl -X GET https://ocrbot.ru/api/v1/account/balance -H "X-Api-Key: $API_KEY$"
JavaScript¶
import axios from "axios";
const { data } = await axios.get(
"https://ocrbot.ru/api/v1/account/balance",
{ headers: { "X-Api-Key": "ВАШ_КЛЮЧ" } }
);
console.log(data);
Go¶
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://ocrbot.ru/api/v1/account/balance", nil)
req.Header.Set("X-Api-Key", "ВАШ API КЛЮЧ")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
6. Получение информации о подписке — GET /account/subscription
¶
Python¶
import requests
r = requests.get("https://ocrbot.ru/api/v1/account/subscription",
headers={"X-Api-Key": "ВАШ API КЛЮЧ"})
print(r.json())
curl¶
$API_KEY="ВАШ API КЛЮЧ"
curl -X GET https://ocrbot.ru/api/v1/account/subscription -H "X-Api-Key: $API_KEY"
JavaScript¶
import axios from "axios";
const { data } = await axios.get(
"https://ocrbot.ru/api/v1/account/subscription",
{ headers: { "X-Api-Key": "ВАШ API КЛЮЧ" } }
);
console.log(data);
Go¶
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://ocrbot.ru/api/v1/account/subscription", nil)
req.Header.Set("X-Api-Key", "ВАШ API КЛЮЧ")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
7. Установка вебхука — POST /webhook
¶
Python¶
import requests, json
payload = {"webhook_url": "https://your-domain.com/webhook"}
r = requests.post("https://ocrbot.ru/api/v1/webhook",
headers={"X-Api-Key": "ВАШ_КЛЮЧ", "Content-Type": "application/json"},
json=payload)
print(json.dumps(r.json(), indent=2, ensure_ascii=False))
curl¶
curl -X POST https://ocrbot.ru/api/v1/webhook \
-H "X-Api-Key: ВАШ_КЛЮЧ" \
-H "Content-Type: application/json" \
-d '{"webhook_url":"https://your-domain.com/webhook"}'
JavaScript¶
import axios from "axios";
await axios.post(
"https://ocrbot.ru/api/v1/webhook",
{ webhook_url: "https://your-domain.com/webhook" },
{ headers: { "X-Api-Key": "ВАШ_КЛЮЧ" } }
);
Go¶
package main
import (
"encoding/json"
"bytes"
"io/ioutil"
"net/http"
"fmt"
)
func main() {
body, _ := json.Marshal(map[string]string{"webhook_url": "https://your-domain.com/webhook"})
req, _ := http.NewRequest("POST", "https://ocrbot.ru/api/v1/webhook", bytes.NewBuffer(body))
req.Header.Set("X-Api-Key", "ВАШ_КЛЮЧ")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
respBody, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(respBody))
}
8. Удаление вебхука — DELETE /webhook
¶
Python¶
import requests, json
r = requests.delete("https://ocrbot.ru/api/v1/webhook",
headers={"X-Api-Key": "ВАШ_КЛЮЧ"})
print(json.dumps(r.json(), indent=2, ensure_ascii=False))
curl¶
curl -X DELETE https://ocrbot.ru/api/v1/webhook -H "X-Api-Key: ВАШ_КЛЮЧ"
JavaScript¶
import axios from "axios";
await axios.delete("https://ocrbot.ru/api/v1/webhook", {
headers: { "X-Api-Key": "ВАШ_КЛЮЧ" }
});
Go¶
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
req, _ := http.NewRequest("DELETE", "https://ocrbot.ru/api/v1/webhook", nil)
req.Header.Set("X-Api-Key", "ВАШ_КЛЮЧ")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}