Let agents share updates on LinkedIn as you: announce a launch, share an article with a link preview, or post a photo with alt text for accessibility. Agents can also remove a post they published by mistake.
With read access, agents can only see your basic profile: your name, profile picture and email address. Choose write access to let them publish and delete posts. Posts can be public or limited to your connections.
LinkedIn does not let connected apps read your feed, existing posts, connections or messages, so agents cannot browse or reply to LinkedIn content.
Connect with LinkedIn in one click: sign in and allow access. Your authorization stays on Houston's server. See Connect your LinkedIn account.
Setup instructions
Setup instructions
Connect your LinkedIn account
- Choose the level for Access:
- Read to let agents read your basic profile.
- Write to also let agents publish and delete posts as you.
- Select Authorize connection, sign in to LinkedIn and allow access.
Advanced: access, expiry and troubleshooting
Reconnect every 60 days
LinkedIn access expires after 60 days and LinkedIn does not let ordinary apps renew it automatically. When agents report that LinkedIn access expired, edit the connection and connect with LinkedIn again.
Changing the access level
Switching between Read and Write asks LinkedIn for different permissions, so edit the connection and connect with LinkedIn again. LinkedIn then replaces the previous authorization.
Revoking access
To stop Houston posting as you, remove the connection in Houston and revoke Houston in LinkedIn's permitted services.
Files
Files
connector.luau
-- The connected member's LinkedIn profile and posts, through Sign In with LinkedIn -- (OpenID Connect) and Share on LinkedIn. Credentials are injected only by Houston's proxy. type Options = {[string]: any} type Post = {id: string, url: string} local API = "https://api.linkedin.com" -- Versioned REST APIs (YYYYMM) are supported for about a year after release. local VERSION = "202609" local VISIBILITY = table.freeze({PUBLIC = true, CONNECTIONS = true}) local function text(value: any, field: string): string assert(type(value) == "string" and value ~= "", field .. " must be a nonempty string") return value end local function optionalText(value: any, field: string): string? if value == nil then return nil end return text(value, field) end local function fields(value: any, field: string, allowed: {[string]: boolean}): Options assert(type(value) == "table", field .. " must be an options object") for key in value do assert(allowed[key], field .. " received an unknown option " .. tostring(key)) end return value end -- Commentary uses LinkedIn's little text format. Escape its reserved characters so -- text is posted literally; # stays unescaped so hashtags still link. local function commentary(value: string): string return (string.gsub(value, "[\\|{}@%[%]()<>*_~]", "\\%0")) end local function invalid(operation: string, message: string): never return houston.fail({operation = operation, layer = "upstream", retryable = false, message = message}) end local function send(operation: string, request: HttpRequest): HttpResponse local response = await(http.request(request)) if response.statusCode >= 200 and response.statusCode < 300 then return response end -- LinkedIn errors are small JSON objects: keep only their code and message. local ok, body = pcall(json.decode, await(response.body:readPrefix(4096))) local message = "LinkedIn HTTP " .. tostring(response.statusCode) if ok and type(body) == "table" then if type(body.code) == "string" then message ..= " (" .. body.code .. ")" end if type(body.message) == "string" then message ..= ": " .. string.sub(body.message, 1, 600) end end if response.statusCode == 401 then message ..= "; reconnect LinkedIn, its access tokens expire after 60 days" end return houston.fail({operation = operation, layer = "upstream", upstream_status = response.statusCode, retryable = response.statusCode == 429 or response.statusCode >= 500, message = message}) end local function decode(operation: string, response: HttpResponse): Options local ok, value = pcall(json.decode, await(response.body:readAll())) if not ok or type(value) ~= "table" then invalid(operation, "LinkedIn returned an invalid JSON object") end return value end local function rest(operation: string, method: string, path: string, payload: Options?): HttpResponse local headers: HttpHeaders = {["LinkedIn-Version"] = {VERSION}, ["X-Restli-Protocol-Version"] = {"2.0.0"}} if payload then headers["Content-Type"] = {"application/json"} end return send(operation, {method = method, url = API .. path, headers = headers, body = if payload then json.encode(payload) else nil}) end local function profile(operation: string): Options local member = decode(operation, send(operation, {method = "GET", url = API .. "/v2/userinfo"})) if type(member.sub) ~= "string" or member.sub == "" then invalid(operation, "LinkedIn profile has no member ID") end member.urn = "urn:li:person:" .. member.sub return member end -- Register the image, then stream the session file to LinkedIn's signed upload URL. local function uploadImage(owner: string, path: string): string local registered = decode("createPost", rest("createPost", "POST", "/rest/images?action=initializeUpload", {initializeUploadRequest = {owner = owner}})).value if type(registered) ~= "table" or type(registered.uploadUrl) ~= "string" or type(registered.image) ~= "string" then invalid("createPost", "LinkedIn did not return an image upload URL") end send("createPost", {method = "PUT", url = registered.uploadUrl, headers = {["Content-Type"] = {"application/octet-stream"}}, body = fs.open(path, "r")}).body:close() return registered.image end local function createPost(input: Options): Post local options = fields(input, "createPost", {text = true, visibility = true, image = true, article = true}) local visibility = options.visibility or "PUBLIC" assert(VISIBILITY[visibility], "visibility must be PUBLIC or CONNECTIONS") assert(options.image == nil or options.article == nil, "createPost accepts an image or an article, not both") local post: Options = { commentary = commentary(text(options.text, "text")), visibility = visibility, distribution = {feedDistribution = "MAIN_FEED", targetEntities = json.decode("[]"), thirdPartyDistributionChannels = json.decode("[]")}, lifecycleState = "PUBLISHED", isReshareDisabledByAuthor = false, } local image = if options.image == nil then nil else fields(options.image, "image", {path = true, altText = true}) if image then assert(await(fs.stat(text(image.path, "image.path"))).isFile, "image.path must be a session file") optionalText(image.altText, "image.altText") elseif options.article ~= nil then local article = fields(options.article, "article", {url = true, title = true, description = true}) assert(string.match(text(article.url, "article.url"), "^https?://"), "article.url must be an http(s) URL") post.content = {article = {source = article.url, title = text(article.title, "article.title"), description = optionalText(article.description, "article.description")}} end post.author = profile("createPost").urn if image then post.content = {media = {id = uploadImage(post.author, image.path), altText = image.altText}} end local response = rest("createPost", "POST", "/rest/posts", post) response.body:close() local id = response.headers["x-restli-id"] if not id or type(id[1]) ~= "string" or id[1] == "" then invalid("createPost", "LinkedIn did not confirm the post ID; check your recent activity before retrying") end return {id = id[1], url = "https://www.linkedin.com/feed/update/" .. id[1] .. "/"} end local function deletePost(id: string): {id: string} local urn = text(id, "id") assert(string.match(urn, "^urn:li:share:%d+$") or string.match(urn, "^urn:li:ugcPost:%d+$"), "id must be a post URN such as urn:li:share:123") rest("deletePost", "DELETE", "/rest/posts/" .. url.segment(urn, "id")).body:close() return {id = urn} end local exports: {[string]: any} = {getProfile = function(): Options return profile("getProfile") end} if houston.allows("data:write") then exports.createPost = createPost exports.deletePost = deletePost end local operationHelp: {[string]: string} = { getProfile = [[getProfile() -> {sub, urn, name, given_name, family_name, picture?, locale, email?, email_verified?} The connected member's OpenID Connect profile. urn (urn:li:person:<sub>) identifies the member as a post author. LinkedIn omits email when it does not share one.]], createPost = [==[createPost({text, visibility?, image?, article?}) -> {id, url} Publishes a post as the connected member. text is posted literally, up to LinkedIn's 3,000 characters; #hashtags link, mentions are not supported. visibility is "PUBLIC" (default) or "CONNECTIONS". Attach at most one of: - image = {path, altText?}: a JPG, GIF or PNG session file, streamed to LinkedIn. - article = {url, title, description?}: a link card. LinkedIn does not fetch link previews, so supply the title. id is the post URN (urn:li:share:... or urn:li:ugcPost:...); url opens the post. Never retry automatically: after an error or timeout the post may already be live, so check the member's recent activity first. ```lua -- linkedin is this configured connection. local post = linkedin.createPost({ text = "We're hiring engineers! #hiring", image = {path = "photos/team.png", altText = "Our team at the office"}, }) ```]==], deletePost = [[deletePost(id) -> {id} Permanently deletes one of the member's own posts by URN, such as the id returned by createPost. Deleting an already deleted post succeeds.]], } exports.help = function(): string local names: {string} = {} for name in exports do if name ~= "help" then table.insert(names, name) end end table.sort(names) local sections = {"LinkedIn: the connected member's profile and posts. Credentials stay on Houston. Calls return completed values; do not wrap them in await(). Posting requires write access. LinkedIn does not let apps read feeds, existing posts, connections or messages."} for _, name in names do local section = operationHelp[name] assert(section, "missing help for configured function " .. name) table.insert(sections, "## " .. section) end return table.concat(sections, "\n\n") end return exportshouston.json
{ "schema_version": 2, "name": "LinkedIn", "files": [ "connector.luau" ], "icon": "icon.png", "access": [ { "name": "data", "label": "Access", "levels": [ { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" } ], "auth": { "oauth": { "type": "oauth2", "label": "Connect with LinkedIn", "authorize_url": "https://www.linkedin.com/oauth/v2/authorization", "token_url": "https://www.linkedin.com/oauth/v2/accessToken", "client_id": "{{publisher.client_id}}", "client_secret": "{{publisher.client_secret}}", "client_auth": "body", "pkce": "none", "scope_separator": " ", "scopes": [ { "values": [ "openid", "profile", "email" ] }, { "if": "{{ allows access.data \"write\" }}", "values": [ "w_member_social" ] } ], "account": { "url": "https://api.linkedin.com/v2/userinfo", "headers": { "Authorization": { "value": "Bearer {{auth.oauth.access_token}}" } }, "label": "/name" } } }, "publisher": { "client_id": { "label": "LinkedIn OAuth client ID", "order": 1, "required": true, "type": "string" }, "client_secret": { "label": "LinkedIn OAuth client secret", "order": 2, "required": true, "type": "secret" } }, "proxy": [ { "match": { "protocol": "http", "host": [ "api.linkedin.com" ], "method": [ "GET" ], "path": [ "/v2/userinfo" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "api.linkedin.com" ], "method": [ "POST" ], "path": [ "/rest/images", "/rest/posts" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "api.linkedin.com" ], "method": [ "DELETE" ], "path": [ "/rest/posts/{id}" ], "colon_path_parameters": [ "id" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "www.linkedin.com" ], "method": [ "PUT" ], "path": [ "/dms-uploads/*" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token}}" } } } } ] }icon.png

README.md
--- description: Let agents publish LinkedIn posts with images or links on your behalf. --- # LinkedIn Let agents share updates on LinkedIn as you: announce a launch, share an article with a link preview, or post a photo with alt text for accessibility. Agents can also remove a post they published by mistake. With read access, agents can only see your basic profile: your name, profile picture and email address. Choose write access to let them publish and delete posts. Posts can be public or limited to your connections. LinkedIn does not let connected apps read your feed, existing posts, connections or messages, so agents cannot browse or reply to LinkedIn content. Connect with LinkedIn in one click: sign in and allow access. Your authorization stays on Houston's server. See [Connect your LinkedIn account](SETUP.md).SETUP.md
# Connect your LinkedIn account 1. Choose the level for **Access**: - **Read** to let agents read your basic profile. - **Write** to also let agents publish and delete posts as you. 2. Select **Authorize connection**, sign in to LinkedIn and allow access. ## Advanced: access, expiry and troubleshooting ### Reconnect every 60 days LinkedIn access expires after 60 days and LinkedIn does not let ordinary apps renew it automatically. When agents report that LinkedIn access expired, edit the connection and connect with LinkedIn again. ### Changing the access level Switching between **Read** and **Write** asks LinkedIn for different permissions, so edit the connection and connect with LinkedIn again. LinkedIn then replaces the previous authorization. ### Revoking access To stop Houston posting as you, remove the connection in Houston and revoke Houston in LinkedIn's [permitted services](https://www.linkedin.com/psettings/permitted-services).tests
authentication.luau
return { contract = function(m) m.authentication({ { auth = {}, config = {}, endpoint = { "GET", "https://api.linkedin.com/v2/userinfo" }, expected = "Bearer synthetic-oauth-token", header = "Authorization", method = "oauth", oauth = true, publisher = { client_id = "synthetic-public-client", client_secret = "synthetic-client-secret", }, scopes = true, }, }) end, }manifest.luau
return { contract = function(m) -- TestLinkedInPublisherOwnedClient do if not (m.publisherClient(m.raw.auth["oauth"])) then m.fail("LinkedIn OAuth client must belong to the publication") end for _, publisher in { {}, { client_id = "client" }, { client_id = "client", client_secret = "secret" } } do local draft, err = m.draft(publisher, nil, nil, "") assert(not err, tostring(err)) if m.count(draft.ConfigFields) ~= 0 then m.fail("connection form asks for %s", draft.ConfigFields) end local want = (m.count(publisher) == 2) if (m.count(draft.Methods) ~= 1) or (draft.Methods[1].available ~= want) then m.fail("publisher=%s methods=%s; available=%s", publisher, draft.Methods, want) end end local publisher = { client_id = "client", client_secret = "secret" } do local _, err = m.resolve( publisher, { client_id = "own-client", client_secret = "own-secret" }, nil, "oauth" ) if err == nil then m.fail("connection replaced the publication's OAuth client") end end local r, err = m.resolve(publisher, nil, nil, "oauth") assert(not err, tostring(err)) if (r.Access["data"] ~= "read") or (m.count(r.PublicConfig) ~= 0) then m.fail("unexpected access %s or public settings %s", r.Access, r.PublicConfig) end end -- TestLinkedInScopesAndAccessRoutes do local read = { "GET https://api.linkedin.com/v2/userinfo" } local writes = { "POST https://api.linkedin.com/rest/posts", "POST https://api.linkedin.com/rest/images?action=initializeUpload", "DELETE https://api.linkedin.com/rest/posts/urn%3Ali%3Ashare%3A7", "PUT https://www.linkedin.com/dms-uploads/C4E10AQ/uploaded-image/0?ut=signed", } local denied = { "GET https://api.linkedin.com/rest/posts", "GET https://api.linkedin.com/v2/me", "DELETE https://api.linkedin.com/rest/images/urn%3Ali%3Aimage%3A1", "PUT https://api.linkedin.com/dms-uploads/C4E10AQ", "GET https://api.linkedin.com.evil.test/v2/userinfo", } for _, access in { "read", "write" } do local publisher = { client_id = "fixture-client", client_secret = "fixture-secret" } local r, err = m.resolve(publisher, {}, nil, "oauth", { data = access }) assert(not err, tostring(err)) local scopes = { "openid", "profile", "email" } if access == "write" then scopes = m.concat(scopes, { "w_member_social" }) end if not (m.equal(r.Scopes, scopes)) or (m.raw.auth["oauth"].scope_separator ~= " ") then m.fail("access=%s scopes %s", access, r.Scopes) end r.Context.Auth["oauth"].access_token = "fixture-token" local rules = r.Proxy local check = function(route, allowed) local method, url, _ = m.cut(route, " ") local recipe, err = m.recipe(rules, method, url, nil) if (err == nil) ~= allowed then m.fail("access=%s %s allowed=%s: %s", access, route, (err == nil), err) end if err ~= nil then return end local headers, err = m.prepare(recipe, r.Context, { Authorization = { "forged" } }) if (err ~= nil) or (m.header(headers, "Authorization") ~= "Bearer fixture-token") then m.fail("credential injection for %s: %s", route, err) end end for _, route in read do check(route, true) end for _, route in writes do check(route, (access == "write")) end for _, route in denied do check(route, false) end end end end, }posts.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}}, access = {data = "write"}, configure = function() requests, responses = {}, {} fs = fixture.files() http = {request = function(req) table.insert(requests, req) if req.body ~= nil and type(req.body) ~= "string" then req.wire = await(req.body:readAll()) await(req.body:close()) end assert(#responses > 0, "unexpected request: " .. req.url) return fixture.operation(table.remove(responses, 1)) end} function respond(status, body, headers) table.insert(responses, {statusCode = status, headers = headers or {}, body = fixture.reader(body)}) end function created(id) respond(201, "", {["x-restli-id"] = {id}}) end PROFILE = '{"sub":"abc123","name":"Jane Doe"}' end, run = function(c) assert(c.getProfile and c.createPost and c.deletePost) -- Text post: every little-text reserved character except # is escaped, so hashtags still link. respond(200, PROFILE) created("urn:li:share:6844785523593134080") local post = c.createPost({text = "(a) [b] {c} <d> @e #f g_h *i* ~j~ k|l m\\n", visibility = "CONNECTIONS"}) assert(post.id == "urn:li:share:6844785523593134080") assert(post.url == "https://www.linkedin.com/feed/update/urn:li:share:6844785523593134080/") local req = requests[2] assert(req.method == "POST" and req.url == "https://api.linkedin.com/rest/posts") assert(req.headers["LinkedIn-Version"][1] == "202609" and req.headers["X-Restli-Protocol-Version"][1] == "2.0.0") assert(req.headers["Content-Type"][1] == "application/json" and req.headers.Authorization == nil) local body = json.decode(req.body) assert(body.author == "urn:li:person:abc123" and body.visibility == "CONNECTIONS" and body.lifecycleState == "PUBLISHED") assert(body.commentary == "\\(a\\) \\[b\\] \\{c\\} \\<d\\> \\@e #f g\\_h \\*i\\* \\~j\\~ k\\|l m\\\\n") assert(body.distribution.feedDistribution == "MAIN_FEED" and json.encode(body.distribution.targetEntities) == "[]") assert(string.find(req.body, '"thirdPartyDistributionChannels":[]', 1, true)) assert(body.content == nil and body.isReshareDisabledByAuthor == false) -- Article post: LinkedIn does not scrape links, so title is sent explicitly. respond(200, PROFILE) created("urn:li:ugcPost:42") assert(c.createPost({text = "Read this", article = {url = "https://example.com/post", title = "Our launch"}}).id == "urn:li:ugcPost:42") body = json.decode(requests[4].body) assert(body.visibility == "PUBLIC") assert(body.content.article.source == "https://example.com/post" and body.content.article.title == "Our launch") assert(body.content.article.description == nil) -- Image post: register the image, stream the session file, then publish. local bytes = string.char(137, 80, 78, 71, 0, 255) .. "image bytes" local file = fs.open("photos/team.png", "w") file:write(bytes) await(file:close()) local uploadUrl = "https://www.linkedin.com/dms-uploads/C4E10AQ/uploaded-image/0?ca=vector_feedshare&ut=signed" respond(200, PROFILE) respond(200, json.encode({value = {uploadUrlExpiresAt = 1650567510704, uploadUrl = uploadUrl, image = "urn:li:image:C4E10AQ"}})) respond(201, "") created("urn:li:share:7") c.createPost({text = "Team", image = {path = "photos/team.png", altText = "Our team"}}) local init = requests[6] assert(init.method == "POST" and init.url == "https://api.linkedin.com/rest/images?action=initializeUpload") assert(json.decode(init.body).initializeUploadRequest.owner == "urn:li:person:abc123") local upload = requests[7] assert(upload.method == "PUT" and upload.url == uploadUrl and upload.wire == bytes) body = json.decode(requests[8].body) assert(body.content.media.id == "urn:li:image:C4E10AQ" and body.content.media.altText == "Our team") -- A failed upload stops before publishing. respond(200, PROFILE) respond(200, json.encode({value = {uploadUrl = uploadUrl, image = "urn:li:image:C4E10AQ"}})) respond(500, "") assert(not pcall(c.createPost, {text = "Team", image = {path = "photos/team.png"}})) assert(#requests == 11 and #responses == 0) -- Delete encodes the URN as one path segment. respond(204, "") assert(c.deletePost("urn:li:share:7").id == "urn:li:share:7") assert(requests[12].method == "DELETE" and requests[12].url == "https://api.linkedin.com/rest/posts/urn%3Ali%3Ashare%3A7") assert(requests[12].body == nil) -- Invalid input fails before reaching LinkedIn. local before = #requests for _, call in { function() c.createPost() end, function() c.createPost({}) end, function() c.createPost({text = ""}) end, function() c.createPost({text = "x", visibility = "LOGGED_IN"}) end, function() c.createPost({text = "x", title = "unknown option"}) end, function() c.createPost({text = "x", image = {path = "photos/team.png"}, article = {url = "https://e.com", title = "t"}}) end, function() c.createPost({text = "x", image = {path = "missing.png"}}) end, function() c.createPost({text = "x", image = {path = "photos/team.png", alt = "typo"}}) end, function() c.createPost({text = "x", article = {url = "javascript:alert(1)", title = "t"}}) end, function() c.createPost({text = "x", article = {url = "https://e.com"}}) end, function() c.deletePost("123") end, function() c.deletePost({id = "urn:li:share:7"}) end, function() c.deletePost("urn:li:share:7/../1") end, } do assert(not pcall(call), "invalid input accepted") end assert(#requests == before, "invalid input reached LinkedIn") -- Missing confirmations and provider errors are reported, never retried. respond(200, PROFILE) respond(201, "") local ok, err = pcall(c.createPost, {text = "x"}) assert(not ok and string.find(tostring(err), "did not confirm the post ID", 1, true)) respond(200, PROFILE) respond(403, '{"status":403,"serviceErrorCode":100,"code":"ACCESS_DENIED","message":"Not enough permissions to access: partnerApiPostsExternal.CREATE"}') ok, err = pcall(c.createPost, {text = "x"}) assert(not ok and string.find(tostring(err), "LinkedIn HTTP 403 (ACCESS_DENIED): Not enough permissions", 1, true)) assert(#requests == before + 4 and #responses == 0) end, }read_only.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}}, access = {data = "read"}, configure = function() requests, responses = {}, {} http = {request = function(req) table.insert(requests, req) assert(#responses > 0, "unexpected request: " .. req.url) return fixture.operation(table.remove(responses, 1)) end} function respond(status, body) table.insert(responses, {statusCode = status, headers = {}, body = fixture.reader(body)}) end end, run = function(c) local count = 0 for _, fn in c do assert(type(fn) == "function") count += 1 end assert(count == 1 and c.getProfile and #requests == 0, "read-only exposes only getProfile; help is offline") respond(200, '{"sub":"782bbtaQ","name":"John Doe","given_name":"John","family_name":"Doe","locale":"en-US","email":"[email protected]","email_verified":true}') local me = c.getProfile() assert(me.urn == "urn:li:person:782bbtaQ" and me.name == "John Doe" and me.email == "[email protected]") assert(requests[1].method == "GET" and requests[1].url == "https://api.linkedin.com/v2/userinfo") assert(requests[1].headers == nil, "credentials stay in the proxy") respond(200, '{"sub":"x1","name":"No Email"}') assert(c.getProfile().email == nil) for _, raw in {"not json", "[]", '{"name":"No member ID"}'} do respond(200, raw) assert(not pcall(c.getProfile), "invalid profile accepted: " .. raw) end respond(401, '{"status":401,"serviceErrorCode":65601,"code":"REVOKED_ACCESS_TOKEN","message":"The token used in the request has been revoked by the user"}') local ok, err = pcall(c.getProfile) assert(not ok and string.find(tostring(err), "LinkedIn HTTP 401 (REVOKED_ACCESS_TOKEN): The token used", 1, true)) assert(string.find(tostring(err), "reconnect LinkedIn", 1, true)) respond(503, "upstream unavailable") ok, err = pcall(c.getProfile) assert(not ok and string.find(tostring(err), "LinkedIn HTTP 503", 1, true)) assert(#requests == 7 and #responses == 0, "failures must not be retried") end, }