Guides
Getting started

Authentication

LinkedIn's 3-legged OAuth 2.0, scopes and roles, the code exchange, programmatic refresh tokens, token introspection and the 401 and 403 errors.

The Marketing API only takes member tokens (3-legged OAuth): a LinkedIn member authorizes your app, and the token acts on their behalf, limited by the granted scopes and by the roles they hold on each ad account and organization. There is no client credentials flow for marketing use cases.

1. Register the redirect URL

The sandbox app starts with no redirect URLs. Register your callback in the console or through the control API:

bash
curl --request PUT \
  --url https://api.mimicr.dev/v1/linkedin-ads/app \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "redirect_uris": ["https://crm.example.com/linkedin/callback"] }'

Matching ignores the query string; URLs must be absolute and contain no #.

2. Send the member to the authorization page

text
https://linkedin-ads.mimicr.dev/oauth/v2/authorization?response_type=code&client_id=<client_id>&redirect_uri=https%3A%2F%2Fcrm.example.com%2Flinkedin%2Fcallback&state=csrf1&scope=r_basicprofile%20r_ads%20rw_ads%20r_ads_reporting%20rw_conversions%20r_marketing_leadgen_automation%20r_organization_admin%20w_organization_social

Scopes are space-separated. The page shows the app, the scopes with LinkedIn's descriptions and, in Mimicr, a persona picker. Consent is all-or-nothing: the member can't pick scopes one by one.

Button or personaRedirect
Permitir (Allow){redirect_uri}?code=…&state=csrf1
Cancelar (Cancel)?error=user_cancelled_authorize&error_description=The+user+cancelled+the+authorization&state=…
Persona cancel_login?error=user_cancelled_login&…

The code is valid for 30 minutes, can be used once and is bound to the client_id and the redirect_uri. If the member already granted the same scopes, the page is skipped and the redirect is immediate (silent re-consent); the page's "Esquecer minha autorização" (forget my grant) link, or the grant.forget action, shows the page again.

Errors on the page (HTTP 401, as HTML): "Client_id doesn't match", "Redirect_uri doesn't match" and "Invalid scope" (a scope of a product the app doesn't have).

3. Exchange the code for tokens

bash
curl --request POST \
  --url https://linkedin-ads.mimicr.dev/oauth/v2/accessToken \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=authorization_code' \
  --data-urlencode 'code=AQ…' \
  --data-urlencode 'redirect_uri=https://crm.example.com/linkedin/callback' \
  --data-urlencode 'client_id=<client_id>' \
  --data-urlencode 'client_secret=<client_secret>'
json
{
  "access_token": "AQV…",
  "expires_in": 5184000,
  "refresh_token": "AQX…",
  "refresh_token_expires_in": 31536000,
  "scope": "r_basicprofile r_ads rw_ads r_ads_reporting rw_conversions r_marketing_leadgen_automation r_organization_admin w_organization_social"
}

The access token lasts 60 days and the refresh token 365. Tokens are opaque, about 500 characters long: leave room for 1,000. Use the token like this:

bash
curl https://linkedin-ads.mimicr.dev/v2/me --header 'Authorization: Bearer <token>'

GET /v2/me returns the member (id, name, headline); their URN is urn:li:person:{id}. Then discover the accounts with the member's ad accounts (see Accounts and roles).

Requesting a different set of scopes than the one granted before revokes every earlier token of the member for this app. Always request the same set.

4. Refresh before day 60

bash
curl --request POST \
  --url https://linkedin-ads.mimicr.dev/oauth/v2/accessToken \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=refresh_token' \
  --data-urlencode 'refresh_token=AQX…' \
  --data-urlencode 'client_id=<client_id>' \
  --data-urlencode 'client_secret=<client_secret>'

The response has a new access token and the same refresh token, with refresh_token_expires_in set to its remaining lifetime: refreshing doesn't extend the 365 days. Near the end, send the member through the authorization page again. Programmatic refresh tokens come while the programmaticRefresh toggle is on (default); on LinkedIn they are granted to approved partners.

5. Introspect a token

bash
curl --request POST \
  --url https://linkedin-ads.mimicr.dev/oauth/v2/introspectToken \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'client_id=<client_id>' \
  --data-urlencode 'client_secret=<client_secret>' \
  --data-urlencode 'token=AQV…'
json
{ "active": true, "client_id": "9vem0tlt63qrfg", "authorized_at": 1793949742, "created_at": 1793949742, "status": "active", "expires_at": 1799133742, "scope": "r_basicprofile,r_ads,rw_ads,r_ads_reporting,rw_conversions,r_marketing_leadgen_automation,r_organization_admin,w_organization_social", "auth_type": "3L" }

Here times are epoch seconds and scopes are comma-separated. status is active, expired or revoked. A valid token of another app answers {"active": false}.

Scopes and roles

ScopeApp productGrants
r_adsAdvertisingRead accounts, groups, campaigns, creatives, forms, targeting and pricing
rw_adsAdvertisingAlso create and change all of them and the forms; can't read leads
r_ads_reportingAdvertisingadAnalytics
rw_conversionsConversions/conversions, /campaignConversions, /conversionEvents
r_marketing_leadgen_automationLead SyncRead forms and leads, manage leadNotifications
r_organization_admin, rw_organization_adminAdvertising, Lead SyncorganizationAcls, organizations
w_organization_social, r_organization_socialAdvertisingThe organization's posts and images
w_member_socialAdvertisingThe member's posts and images
r_basicprofile, r_liteprofileAdvertising, Lead Sync, Conversions/v2/me

The scope isn't enough: the member needs the right role on the account. VIEWER only reads, even with rw_ads; CREATIVE_MANAGER creates creatives; CAMPAIGN_MANAGER also groups and campaigns; ACCOUNT_MANAGER also the account and its users; ACCOUNT_BILLING_ADMIN also billing and deletion. Leads also need a role on the account's organization. Details in Accounts and roles.

Errors

CaseResponse
No header or empty token401 {"serviceErrorCode":401,"message":"Empty oauth2_access_token","status":401}
Invalid token401 serviceErrorCode 65600, INVALID_ACCESS_TOKEN
Revoked token (member, scope change, token.revoke)401 65601, REVOKED_ACCESS_TOKEN
Expired token (sandbox clock)401 65602, EXPIRED_ACCESS_TOKEN
Missing scope403 ACCESS_DENIED "Not enough permissions to access: adCampaigns.CREATE.20261001"
Role too low403 NO_PERMISSION_ON_ENTITY "Viewer may not have permission … on entity …"
Account the member has no role on404 (LinkedIn hides the resource)

Errors of /oauth/v2/accessToken use {"error", "error_description"}: invalid_request (missing parameter, or a bad, expired or revoked refresh token), invalid_redirect_uri (code expired, already used, or of another app or redirect_uri) and invalid_client (wrong secret).

Without the browser

For agents and CI, the control API issues the tokens directly, without the page:

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/linkedin-ads/token \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "member": "viewer", "scopes": ["r_basicprofile", "r_ads"] }'

member is the id or the persona (default admin); scopes is the list (default every scope of the app). To exercise your real callback, the oauth.authorize action clicks Allow and returns the code and the redirect URL. To simulate revocation and expiry, use token.revoke, token.expire and refresh.expire (see Sandbox control).