Skip to content

Instantly share code, notes, and snippets.

@1951FDG
Last active September 6, 2023 10:24
Show Gist options
  • Save 1951FDG/bf589ac915dfa9a3c14cb284c73093cd to your computer and use it in GitHub Desktop.
Save 1951FDG/bf589ac915dfa9a3c14cb284c73093cd to your computer and use it in GitHub Desktop.
Share on LinkedIn via LinkedIn REST API using PostMan

Getting started with LinkedIn v2 API using PostMan

A referral link such as, https://www.gitshowcase.com/invitation/1951fdg, the Fetched URL, is replaced with https://www.gitshowcase.com/, the Canonical URL, as tested with Post Inspector, hence it becomes necessary to post via the LinkedIn REST API

Create an application on LinkedIn

1) Default Application Permissions:

  • r_liteprofile
  • rw_company_admin
  • w_member_social

2) Under OAuth 2.0, Authorized Redirect URLs, add:

3) Copy the Authentication Keys:

  • Client ID
  • Client Secret

Install PostMan

1) Open PostMan and import file:

  • linkedin.postman_collection.json

2) Edit collection LinkedIn:

  • Click Authorization
  • Click Get New Access Token

3) Fill the following:

4) Click on Request Token

5) You will be redirected to LinkedIn page

  • Enter your credentials and allow access

6) Click on Use Token

7) Click on Update

Retrieve Person URN

1) Choose Retrieve author

2) Copy value for key "id"

Create a share

1) Choose Create an Article or URL Share

2) Edit Body

For submitting a fully described share via POST:

{
    "author": "urn:li:person:{{person_id}}",
    "lifecycleState": "PUBLISHED",
    "specificContent": {
        "com.linkedin.ugc.ShareContent": {
            "shareCommentary": {
                "text": ""
            },
            "shareMediaCategory": "ARTICLE",
            "media": [
                {
                    "status": "READY",
                    "description": {
                        "text": ""
                    },
                    "originalUrl": "",
                    "title": {
                        "text": ""
                    }
                }
            ]
        }
    },
    "visibility": {
        "com.linkedin.ugc.MemberNetworkVisibility": "CONNECTIONS"
    }
}

3) Replace {{person_id}} with Person URN (paste previously copied value)

4) com.linkedin.ugc. MemberNetworkVisibility can be:

  • CONNECTIONS - Represents 1st degree network of owner.
  • PUBLIC - Anyone can view this.
  • LOGGED_IN - Viewable by logged in members only.

5) Click on Send

References

  1. Authenticating with OAuth 2.0 | LinkedIn Developer Network

  2. Share on LinkedIn | LinkedIn Developer Network

  3. Manage Company Pages | LinkedIn Developer Network

{
"info": {
"_postman_id": "fb771dfd-9601-417b-a10a-f6f80417a4c8",
"name": "LinkedIn",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Retrieve author",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.linkedin.com/v2/me",
"protocol": "https",
"host": [
"api",
"linkedin",
"com"
],
"path": [
"v2",
"me"
]
}
},
"response": []
},
{
"name": "Create an Article or URL Share",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
},
{
"key": "x-li-format",
"type": "text",
"value": "json"
},
{
"key": "X-Restli-Protocol-Version",
"value": "2.0.0",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"author\": \"urn:li:person:{{person_id}}\",\n \"lifecycleState\": \"PUBLISHED\",\n \"specificContent\": {\n \"com.linkedin.ugc.ShareContent\": {\n \"shareCommentary\": {\n \"text\": \"\"\n },\n \"shareMediaCategory\": \"ARTICLE\",\n \"media\": [\n {\n \"status\": \"READY\",\n \"description\": {\n \"text\": \"\"\n },\n \"originalUrl\": \"\",\n \"title\": {\n \"text\": \"\"\n }\n }\n ]\n }\n },\n \"visibility\": {\n \"com.linkedin.ugc.MemberNetworkVisibility\": \"CONNECTIONS\"\n }\n}"
},
"url": {
"raw": "https://api.linkedin.com/v2/ugcPosts",
"protocol": "https",
"host": [
"api",
"linkedin",
"com"
],
"path": [
"v2",
"ugcPosts"
]
}
},
"response": []
},
{
"name": "Check if sharing is enabled for a company (deprecated)",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "https://api.linkedin.com/v1/companies/{{company_id}}/is-company-share-enabled?format=json",
"protocol": "https",
"host": [
"api",
"linkedin",
"com"
],
"path": [
"v1",
"companies",
"{{company_id}}",
"is-company-share-enabled"
],
"query": [
{
"key": "format",
"value": "json"
}
]
}
},
"response": []
},
{
"name": "Create a company share (deprecated)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "x-li-format",
"value": "json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"visibility\": {\n \"code\": \"\"\n },\n \"comment\": \"\",\n \"content\": {\n \"title\": \"\",\n \"description\": \"\",\n \"submitted-­url\": \"\",\n \"submitted‐image-­url\": \"\"\n }\n}"
},
"url": {
"raw": "https://api.linkedin.com/v1/companies/{{company_id}}/shares?format=json",
"protocol": "https",
"host": [
"api",
"linkedin",
"com"
],
"path": [
"v1",
"companies",
"{{company_id}}",
"shares"
],
"query": [
{
"key": "format",
"value": "json"
}
]
}
},
"response": []
},
{
"name": "Create a personal share (deprecated)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "x-li-format",
"value": "json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"visibility\": {\n \"code\": \"\"\n },\n \"comment\": \"\",\n \"content\": {\n \"title\": \"\",\n \"description\": \"\",\n \"submitted-­url\": \"\",\n \"submitted‐image-­url\": \"\"\n }\n}"
},
"url": {
"raw": "https://api.linkedin.com/v1/people/~/shares?format=json",
"protocol": "https",
"host": [
"api",
"linkedin",
"com"
],
"path": [
"v1",
"people",
"~",
"shares"
],
"query": [
{
"key": "format",
"value": "json"
}
]
}
},
"response": []
}
],
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "addTokenTo",
"value": "header",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"id": "cc251422-53ee-47d7-8dca-785966e4a290",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "5031a27a-6404-4181-a6cc-00b089db0531",
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
@1951FDG
Copy link
Author

1951FDG commented Sep 16, 2019

v1 for post is retired now.

I've updated to v2, thx!

@rohkapPersonal
Copy link

@rajurh - why do we require - linkedin.postman_collection.json? Do we need to use it when we go to apex class? if yes how to use it over there.

@rohkapPersonal
Copy link

Thank you so much. Great post.
Few queries

  1. After clicking Use Token, I am not able to find the Update button/link
  2. How to retrieve author - can you please explain the process.

@bandirom
Copy link

bandirom commented Oct 7, 2020

Thank you)

@bhargav1997
Copy link

how to upload images without curl in v2 LinkedIn API? can you please give an example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment