linkedin API cannot create campaign

Viewed 269

We have got rw_ads permissions for an app. Through that app We have taken access_token with all given permissions.

As mentioned in the documentation, we have rw_ads permission, but If we try to create/update campaign we are getting the below error.

{ "serviceErrorCode": 100, "message": "Not enough permissions to access: POST /adCampaignsV2/sdafnk", "status": 403 }

var request = require("request");

var options = { method: 'POST',
  url: 'https://api.linkedin.com/v2/adCampaignsV2/sdafnk',
  headers: 
   { 'Authorization': 'Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
     'Content-Type': 'application/json' },
  body: 
   { patch: 
      { '$set': 
         { runSchedule: { end: 1548405000000, start: 1547713800000 },
           status: 'ACTIVE' } } },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

Code for creation of campaign is mentioned below

var request = require("request");

var options = { 
  method: 'POST',
  url: 'https://api.linkedin.com/v2/adCampaignsV2',
  headers: { 
    'Authorization': 'Bearer <accessToken>',
    'Content-Type': 'application/json' 
  },
  body: { 
    account: 'urn:li:sponsoredAccount:<accountId>',
    audienceExpansionEnabled: false,
    costType: 'CPM',
    creativeSelection: 'OPTIMIZED',
    dailyBudget: { amount: '200', currencyCode: 'INR' },
    locale: { country: 'IN', language: 'en' },
    name: 'Campaign text ad test',
    objectiveType: 'WEBSITE_TRAFFIC',
    offsiteDeliveryEnabled: false,
    runSchedule: { end: 1547708400000, start: 1547967600000 },
    type: 'TEXT_AD',
    unitCost: { amount: '10', currencyCode: 'INR' },
    status: 'PAUSED' 
  },
  json: true 
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
1 Answers

When you perform a partial update, the header X-RestLi-Method must be included in the request and set to PARTIAL_UPDATE.

Also if you use implicit grant-type, check if you have defined the scope correctly at the start. if you use client-credentials grant-type check if the account has the right permissions.

Direct Sponsored Content can be created by:

Ad Account Users with a role higher than VIEWER. Organization users with DIRECT_SPONSORED_CONTENT_POSTER or ADMINISTRATOR roles.

also the code you added in this question is for Reactivating a campaign. not for updating/creating one.

Related