Quickstart
Od zera do opublikowanego posta. Potrzebujesz konta Postia z co najmniej jednym połączonym kanałem.
1. Utwórz klucz
Otwórz konsolę i zaloguj się kontem Postia. Klucze live wymagają włączonego dwuetapowego logowania. Utwórz klucz z potrzebnymi zakresami i skopiuj go: jest pokazywany tylko raz. Klucze testowe zaczynają się od pst_test_, klucze live od pst_live_.
2. Sprawdź klucz
curl -X GET https://pub.postia.app/v1/me \
-H "Authorization: Bearer $POSTIA_API_KEY"const res = await fetch("https://pub.postia.app/v1/me", {
method: "GET",
headers: {
Authorization: `Bearer ${process.env.POSTIA_API_KEY}`,
},
});
const data = await res.json();import os, requests
res = requests.get(
"https://pub.postia.app/v1/me",
headers={
"Authorization": f"Bearer {os.environ['POSTIA_API_KEY']}",
},
)
data = res.json()using System.Net.Http.Headers;
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("POSTIA_API_KEY"));
var req = new HttpRequestMessage(HttpMethod.Get, "https://pub.postia.app/v1/me");
var res = await http.SendAsync(req);
var data = await res.Content.ReadAsStringAsync();import java.net.URI;
import java.net.http.*;
var req = HttpRequest.newBuilder(URI.create("https://pub.postia.app/v1/me"))
.header("Authorization", "Bearer " + System.getenv("POSTIA_API_KEY"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
String data = res.body();<?php
$ch = curl_init('https://pub.postia.app/v1/me');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('POSTIA_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);req, _ := http.NewRequest("GET", "https://pub.postia.app/v1/me", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("POSTIA_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)require 'net/http'
require 'json'
uri = URI('https://pub.postia.app/v1/me')
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{ENV['POSTIA_API_KEY']}"
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
data = JSON.parse(res.body)Odpowiedź podaje konto, zakresy i limit żądań klucza oraz saldo kredytów.
3. Znajdź identyfikator kanału
curl -X GET https://pub.postia.app/v1/channels \
-H "Authorization: Bearer $POSTIA_API_KEY"const res = await fetch("https://pub.postia.app/v1/channels", {
method: "GET",
headers: {
Authorization: `Bearer ${process.env.POSTIA_API_KEY}`,
},
});
const data = await res.json();import os, requests
res = requests.get(
"https://pub.postia.app/v1/channels",
headers={
"Authorization": f"Bearer {os.environ['POSTIA_API_KEY']}",
},
)
data = res.json()using System.Net.Http.Headers;
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("POSTIA_API_KEY"));
var req = new HttpRequestMessage(HttpMethod.Get, "https://pub.postia.app/v1/channels");
var res = await http.SendAsync(req);
var data = await res.Content.ReadAsStringAsync();import java.net.URI;
import java.net.http.*;
var req = HttpRequest.newBuilder(URI.create("https://pub.postia.app/v1/channels"))
.header("Authorization", "Bearer " + System.getenv("POSTIA_API_KEY"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
String data = res.body();<?php
$ch = curl_init('https://pub.postia.app/v1/channels');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('POSTIA_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);req, _ := http.NewRequest("GET", "https://pub.postia.app/v1/channels", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("POSTIA_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)require 'net/http'
require 'json'
uri = URI('https://pub.postia.app/v1/channels')
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{ENV['POSTIA_API_KEY']}"
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
data = JSON.parse(res.body)Wymaga to zakresu channels:read. Kanały łączy się w aplikacji Postia, nie przez API.
4. Opublikuj post
curl -X POST https://pub.postia.app/v1/posts \
-H "Authorization: Bearer $POSTIA_API_KEY" \
-H "Idempotency-Key: first-post-1" \
-H "Content-Type: application/json" \
-d '{"text": "Hello from the API", "channel_ids": ["CHANNEL_ID"], "publish": true}'const res = await fetch("https://pub.postia.app/v1/posts", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.POSTIA_API_KEY}`,
"Idempotency-Key": "first-post-1",
"Content-Type": "application/json",
},
body: JSON.stringify({
"text": "Hello from the API",
"channel_ids": [
"CHANNEL_ID"
],
"publish": true
}),
});
const data = await res.json();import os, requests
res = requests.post(
"https://pub.postia.app/v1/posts",
headers={
"Authorization": f"Bearer {os.environ['POSTIA_API_KEY']}",
"Idempotency-Key": "first-post-1",
},
json={
"text": "Hello from the API",
"channel_ids": [
"CHANNEL_ID"
],
"publish": True
},
)
data = res.json()using System.Net.Http.Headers;
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("POSTIA_API_KEY"));
var req = new HttpRequestMessage(HttpMethod.Post, "https://pub.postia.app/v1/posts");
req.Headers.Add("Idempotency-Key", "first-post-1");
req.Content = new StringContent("{\"text\": \"Hello from the API\", \"channel_ids\": [\"CHANNEL_ID\"], \"publish\": true}", System.Text.Encoding.UTF8, "application/json");
var res = await http.SendAsync(req);
var data = await res.Content.ReadAsStringAsync();import java.net.URI;
import java.net.http.*;
var req = HttpRequest.newBuilder(URI.create("https://pub.postia.app/v1/posts"))
.header("Authorization", "Bearer " + System.getenv("POSTIA_API_KEY"))
.header("Idempotency-Key", "first-post-1")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\"text\": \"Hello from the API\", \"channel_ids\": [\"CHANNEL_ID\"], \"publish\": true}"))
.build();
var res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
String data = res.body();<?php
$ch = curl_init('https://pub.postia.app/v1/posts');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('POSTIA_API_KEY'),
'Idempotency-Key: first-post-1',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => '{"text": "Hello from the API", "channel_ids": ["CHANNEL_ID"], "publish": true}',
]);
$data = json_decode(curl_exec($ch), true);req, _ := http.NewRequest("POST", "https://pub.postia.app/v1/posts", strings.NewReader(`{"text": "Hello from the API", "channel_ids": ["CHANNEL_ID"], "publish": true}`))
req.Header.Set("Authorization", "Bearer "+os.Getenv("POSTIA_API_KEY"))
req.Header.Set("Idempotency-Key", "first-post-1")
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)require 'net/http'
require 'json'
uri = URI('https://pub.postia.app/v1/posts')
req = Net::HTTP::Post.new(uri)
req['Authorization'] = "Bearer #{ENV['POSTIA_API_KEY']}"
req['Idempotency-Key'] = 'first-post-1'
req['Content-Type'] = 'application/json'
req.body = '{"text": "Hello from the API", "channel_ids": ["CHANNEL_ID"], "publish": true}'
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
data = JSON.parse(res.body)Pomiń publish, aby otrzymać wersję roboczą, albo wyślij schedule_at (ISO 8601 z przesunięciem strefy), aby zaplanować post. Idempotency-Key zapewnia bezpieczne ponowienie.
5. Śledź wynik
Dostarczanie jest asynchroniczne. Odczytaj post przez GET /v1/posts/{post_id}, aby zobaczyć wyniki dla poszczególnych kanałów, albo zasubskrybuj webhooki.