LinkedIn API v2: Post Content, Fetch Analytics, and Manage Leads

This workflow automates LinkedIn API v2 tasks, replacing manual content posting, analytics retrieval, and lead management via the LinkedIn Developer Portal, which is time-consuming and prone to errors due to token management complexities. It handles OAuth2 authentication, token refresh (60-day access tokens), posting content, fetching analytics, retrieving profiles, and managing leads. Key nodes include Manual Trigger for testing, Set for input validation (client_id, client_secret, refresh_token, person_id, organization_id), IF for credential and token checks, HTTP Request for token refresh and API operations (post_content, get_analytics, get_profile, get_leads), and Set for success/error responses. Ideal for marketing teams or professionals managing 5+ posts or campaigns, it streamlines content automation, engagement tracking, and CRM integration, reducing manual effort and ensuring API uptime. Business Value Time Savings: Saves 4-8 hours weekly automating 5+ posts, analytics reports, or lead syncs, cutting downtime by 85%. Target Audience: Suits small to medium marketing teams, recruiters, or B2B businesses. Scalability: Handles up to 250 posts/day and 500 analytics calls/day, constrained by LinkedIn’s API rate limits. Cost: Requires LinkedIn Developer App (free) and n8n cloud ($20/month) or self-hosted (free). Setup Instructions Install n8n: Download from n8n.io or use cloud.n8n.io ($20/month unlimited). Create LinkedIn App: Set up at LinkedIn Developer Portal, obtain client_id, client_secret, and refresh_token via OAuth2 flow (see LinkedIn OAuth Docs). Environment Variables: Configure in n8n: LINKEDIN_CLIENT_ID: App client ID LINKEDIN_CLIENT_SECRET: App client secret LINKEDIN_REFRESH_TOKEN: Long-lived refresh token LINKEDIN_ACCESS_TOKEN: Current access token (optional, auto-refreshed) LINKEDIN_TOKEN_EXPIRES_AT: Token expiration (ISO format) LINKEDIN_PERSON_ID: User’s LinkedIn person ID (for posts) LINKEDIN_ORGANIZATION_ID: Company page ID (for analytics/leads) Webhook (Optional): Add Webhook node, set path to linkedin, use URL (e.g., https://your-n8n/webhook/linkedin123). HTTP Request Configuration: Token refresh: POST https://www.linkedin.com/oauth/v2/accessToken API operations: Use endpoints for posting (ugcPosts), analytics (organizationalEntityShareStatistics), profiles (people), and leads (adCampaignGroupsV2). Testing Manual Test: Run with operation='post_content', post_text='Test post from DevHubConnect', and valid person_id. Verify post on LinkedIn. For analytics, set operation='get_analytics' and organization_id, check response in Operation Success node. Common Errors: Invalid refresh_token: Re-authenticate via OAuth. Missing person_id/organization_id: Verify IDs in LinkedIn Developer Portal. Rate limits: Add Wait node (1s delay) for 250 posts/day or 500 analytics calls/day. Scope issues: Ensure w_member_social, r_organization_social, r_basicprofile, r_ads scopes are granted. Deployment & Maintenance Deploy: Activate workflow in n8n; monitor logs for errors. Maintenance: Store tokens in a database, schedule token checks every 24 hours (1-day buffer), adjust query parameters (e.g., timeIntervals) for large-scale analytics or lead retrieval. Limitations Rate Limits: 250 posts/day, 500 analytics/profile calls/day. Media Support: Current workflow supports text-only posts; extend jsonBody in LinkedIn Post node for images/videos. Lead Management: Limited to campaign group data; additional nodes needed for detailed lead forms. Use Case Automates LinkedIn content posting, engagement analytics, profile retrieval, and lead generation for professional networking and B2B marketing. Setup Time 20-30 minutes Difficulty Intermediate Requirements LinkedIn Developer App (free, with OAuth credentials) Valid refresh token, person ID, and organization ID n8n cloud ($20/month) or self-hosted (free)

$5.49

Workflow steps: 20

Integrated apps: manualTrigger, set, if

LinkedIn API v2: Post Content, Fetch Analytics, and Manage Leads preview