Quickstart
Upload a photo, submit a post, and check its publishing status.
On this page
1. Create a publishing key
In your workspace, open Settings → API keys and create a key with Publishing access. You need a workspace admin or owner to create it. Save the key when it appears.
Set these variables in Bash or Zsh. If you run your own Posthoop instance, use its origin. The prompt reads the key without echoing it.
export POSTHOOP_URL=https://posthoop.com
printf 'Posthoop API key: '
read -rs POSTHOOP_API_KEY
export POSTHOOP_API_KEY
printf '\n'2. Find your account ID
Connect an Instagram account from Dashboard → Accounts and put a JPEG named photo.jpg in your working directory. Use the ID of the Instagram account with status: "active".
curl --fail-with-body -sS "$POSTHOOP_URL/api/v1/accounts" \
-H "Authorization: Bearer $POSTHOOP_API_KEY" | jq -e .accounts
export ACCOUNT_ID=replace-with-your-account-uuid3. Upload and publish with curl
This submits a real post to the selected account. It requests an upload URL, PUTs the photo directly to storage, completes the upload, creates the post, then fetches its current status. Save the commands as post.sh and run bash post.sh. Choose either this example or JavaScript for a single post.
set -eo pipefail
FILE=photo.jpg
upload=$(curl --fail-with-body -sS "$POSTHOOP_URL/api/v1/media/uploads" \
-H "Authorization: Bearer $POSTHOOP_API_KEY" \
-H 'Content-Type: application/json' \
--data "$(jq -n --arg name "$FILE" --argjson size "$(wc -c < "$FILE")" \
'{fileName: $name, mimeType: "image/jpeg", sizeBytes: $size}')")
MEDIA_ID=$(jq -er .id <<< "$upload")
curl --fail-with-body -sS -X PUT "$(jq -er .uploadUrl <<< "$upload")" \
-H "Content-Type: $(jq -er '.headers["Content-Type"]' <<< "$upload")" \
-H "If-None-Match: $(jq -er '.headers["If-None-Match"]' <<< "$upload")" \
--upload-file "$FILE"
curl --fail-with-body -sS -X POST "$POSTHOOP_URL/api/v1/media/$MEDIA_ID/complete" \
-H "Authorization: Bearer $POSTHOOP_API_KEY"
post=$(curl --fail-with-body -sS "$POSTHOOP_URL/api/v1/posts" \
-H "Authorization: Bearer $POSTHOOP_API_KEY" \
-H 'Content-Type: application/json' \
--data "$(jq -n --arg account "$ACCOUNT_ID" --arg media "$MEDIA_ID" \
'{caption: "A photo from Posthoop", mediaIds: [$media], targets: [{accountId: $account}]}')")
POST_ID=$(jq -er .id <<< "$post")
curl --fail-with-body -sS "$POSTHOOP_URL/api/v1/posts/$POST_ID" \
-H "Authorization: Bearer $POSTHOOP_API_KEY" | jq '{id, status, targets}'JavaScript version
Save this as post.mjs and run node post.mjs using Node 22. It uses the same environment variables and local photo.
import { readFile } from "node:fs/promises";
const { POSTHOOP_URL, POSTHOOP_API_KEY, ACCOUNT_ID } = process.env;
if (!POSTHOOP_URL || !POSTHOOP_API_KEY || !ACCOUNT_ID) {
throw new Error("Set POSTHOOP_URL, POSTHOOP_API_KEY, and ACCOUNT_ID.");
}
async function api(path, { method = "GET", json } = {}) {
const response = await fetch(new URL("/api/v1/" + path, POSTHOOP_URL), {
method,
headers: {
Authorization: "Bearer " + POSTHOOP_API_KEY,
...(json && { "Content-Type": "application/json" }),
},
body: json && JSON.stringify(json),
redirect: "error",
});
const body = await response.json();
if (!response.ok) throw new Error(body.error?.message ?? String(response.status));
return body;
}
const file = await readFile("photo.jpg");
const upload = await api("media/uploads", {
method: "POST",
json: { fileName: "photo.jpg", mimeType: "image/jpeg", sizeBytes: file.length },
});
const put = await fetch(upload.uploadUrl, {
method: "PUT", headers: upload.headers, body: file, redirect: "error",
});
if (!put.ok) throw new Error("Upload returned HTTP " + put.status);
await api("media/" + upload.id + "/complete", { method: "POST" });
const post = await api("posts", {
method: "POST",
json: {
caption: "A photo from Posthoop",
mediaIds: [upload.id],
targets: [{ accountId: ACCOUNT_ID }],
},
});
console.log(await api("posts/" + post.id));4. Check each target
The create request returns 201 with status queued for this post. A worker publishes it in the background. Read GET /api/v1/posts/{id} to see each target's current status, externalUrl when available, and lastError.
See dry runs to validate without publishing, or subscribe to webhooks for publish outcomes.