@openpromo/linkedin
v0.2.1
Published
Type-safe TypeScript SDK for LinkedIn organic publishing and OAuth
Maintainers
Readme
@openpromo/linkedin
Type-safe TypeScript SDK for LinkedIn organic publishing and OAuth.
LinkedIn does not currently publish a public OpenAPI/Swagger spec or public per-endpoint Rest.li restspec for the Marketing API surfaces this package wraps. This SDK is hand-authored against the official Microsoft Learn endpoint docs and LinkedIn's Rest.li protocol documentation.
Install
bun add @openpromo/linkedin
# or
npm install @openpromo/linkedinUse
import { LinkedIn } from "@openpromo/linkedin";
const linkedin = LinkedIn.createClient({
accessToken: process.env.LINKEDIN_ACCESS_TOKEN!,
});
const result = await linkedin.posts.createText({
authorUrn: "urn:li:organization:123456",
commentary: "New launch is live.",
});
console.log(result.postUrn);Publish Media
const imageUrn = await linkedin.assets.uploadImageFromUrl(
"urn:li:organization:123456",
"https://cdn.example.com/photo.jpg",
);
await linkedin.posts.createImage({
authorUrn: "urn:li:organization:123456",
commentary: "Behind the scenes.",
imageUrn,
options: { altText: "A team photo" },
});OAuth
const oauth = LinkedIn.OAuth.create({
clientId: process.env.LINKEDIN_CLIENT_ID!,
clientSecret: process.env.LINKEDIN_CLIENT_SECRET!,
redirectUri: "https://app.example.com/oauth/linkedin/callback",
});
const url = oauth.getAuthorizationUrl({ state: "opaque-state" });Official References
- LinkedIn API Clients - official protocol-level client guidance; LinkedIn notes these clients do not model specific APIs.
- Rest.li Protocol - source for Rest.li 2.0 headers, URL encoding, list notation, and resource methods.
- Marketing API Versioning - source for
/restbase path andLinkedIn-Version. - Posts API - source for text, image, video, partial update, delete, and
x-restli-idbehavior. - Images API - source for
initializeUploadand image URNs. - Videos API - source for multipart upload instructions, ETags, and finalization.
- Comments API - source for comment creation,
x-restli-id, and comment URNs. - Organization Lookup API - source for organization lookup endpoints.
- Organization Access Control by Role - source for administered organization discovery.
- LinkedIn 3-Legged OAuth Flow - source for authorization and token exchange.
- Programmatic Refresh Tokens - source for refresh token exchange behavior.
- Sign In with LinkedIn using OpenID Connect - source for
/v2/userinfo.
