Home > Software engineering >  How to pass creativeId into CampaignCreativeAssociations.insert() method using Google CM360 API
How to pass creativeId into CampaignCreativeAssociations.insert() method using Google CM360 API

Time:03-08

I'm using Google Apps Script and using the DoubleClickCampaigns services v3.5, which allows me to use CM360 APIs v3.5

I'm trying to associate a creative to a campaign using campaignCreativeAssociations.insert()

  const profileId = '1234' //fake
  const campaignId = '12345'
  const creativeId = '5551234'
  DoubleClickCampaigns.CampaignCreativeAssociations.insert(profileId,campaignId,creativeId);

The above returns this error

 GoogleJsonResponseException: API call to dfareporting.campaignCreativeAssociations.insert failed with error: 8058 : Creative ID required.

Using the "Try this method" on the side bar of the documentation site has a sample code shows that I should instead pass in an object into the .insert parameter

 {"profileId":###,"campaignId",###,resource:{"creativeId":###}} 

Testing the code by running it on the documentation website (it works on live data) I can confirm that the creative was associated to the campaign.

function execute() {
    return gapi.client.dfareporting.campaignCreativeAssociations.insert({
      "profileId": 123,
      "campaignId": 456,
      "resource": {
        "creativeId": 123,
      }
    })

However when I try to rebuild the same code into my Apps Script environment, I get this error

DoubleClickCampaigns.CampaignCreativeAssociations.insert({
  "profileId": 123,
  "campaignId": 555,
  "resource": {
    "creativeId": 555123,
  }
})



Exception: Invalid number of arguments provided. Expected 3-4 only

Is the issue with the parameter? Following the sample code gives me an error regarding passing the wrong number of parameters. What should my code me so that I can use Apps Script to insert creatives into a CM360 campaign

CodePudding user response:

It seems that the arguments of DoubleClickCampaigns.CampaignCreativeAssociations.insert() are as follows.

insert(resource: Dfareporting_v3_5.Dfareporting.V3_5.Schema.CampaignCreativeAssociation, profileId: string, campaignId: string)

When this is reflected to your script, how about the following modification?

Modified script:

var resource = { "creativeId": 555123 };
var profileId = "123";
var campaignId = "555"
DoubleClickCampaigns.CampaignCreativeAssociations.insert(resource, profileId, campaignId);
  • It seems that the values of profileId and campaignId are the string type.

Reference:

  • Related