Guide · posts:write
Post with media
Upload a photo, publish a post that uses it, then edit or delete it. Publishing is a two-step flow: first the media, then the post.
Scopes: posts:write (and stories:write for stories, posts:read to read posts back).
1. Upload the media#
Send the file as multipart/form-data in a field named file. The response contains a mediaId to use in the next step.
curl https://api.linework.app/open/v1/media \
-H "Authorization: Bearer $LINEWORK_API_KEY" \
-F "file=@sunset.jpg"
import { readFile } from "node:fs/promises";
const form = new FormData();
form.append("file", new Blob([await readFile("sunset.jpg")], { type: "image/jpeg" }), "sunset.jpg");
const res = await fetch("https://api.linework.app/open/v1/media", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.LINEWORK_API_KEY}` },
body: form, // do not set Content-Type: fetch adds the multipart boundary
});
const { mediaId } = await res.json();
import os, requests
API = "https://api.linework.app/open/v1"
s = requests.Session()
s.headers["Authorization"] = f"Bearer {os.environ['LINEWORK_API_KEY']}"
with open("sunset.jpg", "rb") as f:
r = s.post(API + "/media", files={"file": ("sunset.jpg", f, "image/jpeg")}, timeout=120)
r.raise_for_status()
media_id = r.json()["mediaId"]
{ "mediaId": "m_8f2c1a" }
Media limits
| Type | Formats | Max size |
|---|---|---|
| Images | JPEG, PNG, WebP, GIF | 50 MB |
| Videos | MP4, MOV (QuickTime), WebM | 500 MB |
Larger files fail with 413 PAYLOAD_TOO_LARGE; other formats with 400 VALIDATION_ERROR. Uploaded media that is never used in a post may be deleted after some time.
2. Publish the post#
curl https://api.linework.app/open/v1/posts \
-H "Authorization: Bearer $LINEWORK_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "text": "Golden hour on the lake 🌅", "mediaIds": ["m_8f2c1a"] }'
const res = await fetch("https://api.linework.app/open/v1/posts", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LINEWORK_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ text: "Golden hour on the lake 🌅", mediaIds: [mediaId] }),
});
const post = await res.json();
console.log(post.id);
r = s.post(API + "/posts", json={"text": "Golden hour on the lake 🌅", "mediaIds": [media_id]}, timeout=30)
r.raise_for_status()
post = r.json()
print(post["id"])
A post can have text only, media only, or both. Each post counts toward the daily quota of 50 posts per account (quotas).
3. Edit or delete#
# change the text
curl -X PATCH https://api.linework.app/open/v1/posts/1043 \
-H "Authorization: Bearer $LINEWORK_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "text": "Golden hour on Lake Como 🌅" }'
# delete the post
curl -X DELETE https://api.linework.app/open/v1/posts/1043 \
-H "Authorization: Bearer $LINEWORK_API_KEY"
You can edit and delete only your own posts. Read them back with GET /posts/{id} or list them with GET /me/posts (posts:read).
Publish a story#
Stories use the same upload flow: upload with POST /media, then create the story with the mediaId. Scope stories:write, daily quota 20 stories.
curl https://api.linework.app/open/v1/stories \
-H "Authorization: Bearer $LINEWORK_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "mediaId": "m_8f2c1a" }'
Good practices#
- Post content people want to see. Repetitive or automated filler is spam under the API Terms.
- If
POST /poststimes out, checkGET /me/postsbefore retrying, to avoid duplicates. - Only publish media you have the rights to.