Panduan memulai
Dari nol sampai postingan terbit. Anda memerlukan akun Postia dengan setidaknya satu kanal terhubung.
1. Buat kunci
Buka konsol dan masuk dengan akun Postia Anda. Kunci live memerlukan verifikasi dua langkah yang aktif. Buat kunci dengan scope yang Anda perlukan lalu salin: kunci hanya ditampilkan sekali. Kunci uji diawali pst_test_, kunci live diawali pst_live_.
2. Periksa kunci
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)Jawabannya menyebut akun, scope dan laju kunci, serta saldo kredit Anda.
3. Cari id kanal
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)Ini memerlukan scope channels:read. Kanal dihubungkan di aplikasi Postia, bukan lewat API.
4. Publikasikan postingan
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)Hilangkan publish untuk mendapat draf, atau kirim schedule_at (ISO 8601 dengan offset) untuk menjadwalkannya. Idempotency-Key membuat pengulangan permintaan aman.
5. Pantau hasilnya
Pengiriman bersifat asinkron. Baca postingan dengan GET /v1/posts/{post_id} untuk hasil per kanal, atau berlangganan webhook.