Postia API
TR
Konsol

Hızlı başlangıç

Sıfırdan yayınlanmış bir gönderiye. En az bir kanalı bağlı bir Postia hesabına ihtiyacınız var.

1. Anahtar oluşturun

Konsolu açın ve Postia hesabınızla giriş yapın. Canlı anahtarlar için iki adımlı girişin açık olması gerekir. İhtiyacınız olan kapsamlarla bir anahtar oluşturun ve kopyalayın: yalnızca bir kez gösterilir. Test anahtarları pst_test_ ile, canlı anahtarlar pst_live_ ile başlar.

2. Anahtarı kontrol edin

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)

Yanıt hesabı, anahtarın kapsamlarını ve istek sınırını, ayrıca kredi bakiyenizi gösterir.

3. Kanal kimliğini bulun

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)

Bunun için channels:read kapsamı gerekir. Kanallar API üzerinden değil, Postia uygulamasında bağlanır.

4. Gönderi yayınlayın

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)

Taslak almak için publish alanını çıkarın; zamanlamak için schedule_at (ISO 8601, saat farkıyla) gönderin. Idempotency-Key, yeniden denemeyi güvenli kılar.

5. Sonucu izleyin

Teslimat asenkron çalışır. Kanal bazında sonuçlar için gönderiyi GET /v1/posts/{post_id} ile okuyun ya da webhook'lara abone olun.