# LinkedIn API post: free checker and publishing example

Resources for the APIWings guide [LinkedIn API post: member profiles vs company pages](https://apiwings.com/blog/linkedin-api-post). Free to use (MIT licence). Rules checked against LinkedIn's documentation on 30 November 2026 (Marketing API version 202611).

## Files

| File | What it is |
|---|---|
| `linkedin-post-check.mjs` | Checker in JavaScript (Node 18+). `node linkedin-post-check.mjs plan.json` |
| `linkedin_post_check.py` | The same checker in Python 3.11+. `python linkedin_post_check.py plan.json` |
| `linkedin-posting-rules.json` | Every rule with its source URL. Both checkers read it from the same folder |
| `example-plan.json` | Worked example: a fictional app (Postwell) with six planned posts and 20 problems |
| `example-plan-fixed.json` | The same plan after the fixes: no errors or warnings |
| `linkedin-test-cases.json` | 1,498 test cases: 130 written by hand from LinkedIn's docs, 1,368 generated |
| `make-test-cases.mjs` | Rebuilds the test cases |
| `make-examples.py` | Rebuilds the two example plans |
| `test-linkedin-check.mjs`, `test_linkedin_check.py` | Run all cases: `1498 of 1498 cases pass` in both languages |
| `linkedin-post-example.mjs` | Publishing example: checks, asks organizationAuthorizations before a page post, uploads media, creates the post, returns the URN |
| `test-post-example.mjs` | Runs the publishing example against a local mock of LinkedIn: `24 of 24 publishing scenarios pass` |
| `linkedin-api-post-cheat-sheet.pdf` | One-page cheat sheet |

## The plan format

```json
{
  "app": { "products": ["share_on_linkedin", "community_management"], "community_management_tier": "development",
           "linkedin_version": "202611", "programmatic_refresh_tokens": false, "review_date": "2026-11-30" },
  "posts": [{
    "id": "launch", "author": { "type": "person", "urn": "urn:li:person:{id}" },
    "granted_scopes": ["w_member_social"], "commentary": "Plain text, the checker escapes it #launch",
    "mentions": [{ "text": "Ana Ruiz", "urn": "urn:li:person:{id}" }], "visibility": "PUBLIC",
    "content": { "type": "image", "images": [{ "format": "jpg", "width": 1200, "height": 800, "alt": "...", "file": "a.jpg" }] },
    "publish_at": "2026-12-01T09:00:00Z", "token_expires_at": "2027-01-29T10:00:00Z",
    "origin": { "generated_by": "person" }
  }]
}
```

- `author.type`: `person` or `organization` (add `role` for pages: the member's page role).
- `content.type`: `none`, `image`, `multi_image`, `video`, `document`, `article`, `poll` or `carousel`.
- Optional: `member_urn` (whose token posts for a page: used for daily call counts and for the organizationAuthorizations check), `targeting.audience_estimate`, `origin.approved_by`, `verify_by_reading`, `lifecycle_state`.
- `commentary_format`: `plain` (default: the checker escapes the text once) or `little` (the text is already escaped: the checker sends it as is and reports reserved characters left unescaped). Plain text that already contains escapes gets a `POSSIBLY_ALREADY_ESCAPED` warning, so nothing is escaped twice by accident.

Each post gets `no_issues_found`, `warnings` or `blocked`, the list of issues with their source, `estimated_requests` (`api_calls` to api.linkedin.com, `file_uploads` to LinkedIn's upload URLs and their sum, `http_requests`) and the `POST /rest/posts` request with the text in LinkedIn's little format. Daily limits are checked against API calls only: LinkedIn does not document whether file uploads count.

## What a clean result means

No documented rule is broken. It is not an approval: the checker cannot see your app's review status, the member's current page role, whether a mention name matches or your real rate limits (Developer Portal, Analytics tab).

## Publishing example

```
LINKEDIN_TOKEN=... node linkedin-post-example.mjs example-plan-fixed.json 1-ana-launch-text --dry-run
```

Remove `--dry-run` to send. Tested only against a local mock written from LinkedIn's documentation, never against LinkedIn: try it on a test profile first. For a page post it first asks `/rest/organizationAuthorizations` for ORGANIC_SHARE_CREATE (needs `rw_organization_admin`); Denied stops the post, a 403 is reported as `page_permission_check: unchecked`. It does not handle videos (multipart upload). It retries 429 (honouring `Retry-After`, up to `LINKEDIN_MAX_WAIT_MS`) and server errors on uploads, but never resends a create call after a server error or timeout, because LinkedIn has no idempotency key and member posts cannot be read back. Image and document paths in `file` are relative to the plan file.

## Sources

The `sources` block of `linkedin-posting-rules.json` lists every LinkedIn page used. Values that are our reading, marked in the guide: the hashtag rule (ASCII letters and digits after `#`), counting the 3,000 characters after escaping as a warning, the DIRECT_SPONSORED_CONTENT_POSTER warning (from LinkedIn's role to permission mapping) and reporting file uploads apart from API calls. Not legal advice.
