Quickstart
Von null bis zum veröffentlichten Beitrag. Sie brauchen ein Postia-Konto mit mindestens einem verbundenen Kanal.
1. Key erstellen
Öffnen Sie die Konsole und melden Sie sich mit Ihrem Postia-Konto an. Für Live-Keys muss die Anmeldung in zwei Schritten aktiviert sein. Erstellen Sie einen Key mit den benötigten Scopes und kopieren Sie ihn: Er wird nur einmal angezeigt. Test-Keys beginnen mit pst_test_, Live-Keys mit pst_live_.
2. Key prüfen
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)Die Antwort nennt das Konto, die Scopes und das Limit des Keys sowie Ihr Credit-Guthaben.
3. Kanal-ID finden
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)Dafür ist der Scope channels:read nötig. Kanäle werden in der Postia-App verbunden, nicht über die API.
4. Beitrag veröffentlichen
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)Ohne publish entsteht ein Entwurf; mit schedule_at (ISO 8601 mit Offset) wird der Beitrag geplant. Der Idempotency-Key macht eine Wiederholung sicher.
5. Ergebnis verfolgen
Die Zustellung erfolgt asynchron. Lesen Sie den Beitrag mit GET /v1/posts/{post_id} für die Ergebnisse pro Kanal oder abonnieren Sie Webhooks.