0

I try to call this API with the following ad object.

  var ad = DoubleClickCampaigns.Ads.insert(6485800,
    {
      
      "campaignId": parseInt(singlePlacementArray[0]),
      "advertiserId": parseInt(inputSheet.getRange("J9").getValue()),
      
      //"accountId": inputSheet.getRange("H9").getValue(),
      "name": singlePlacementArray[1],
       "active": true,
       "archived": false,
      "type": "AD_SERVING_TRACKING",
      "startDate": Utilities.formatDate(singlePlacementArray[5], ss.getSpreadsheetTimeZone(), "yyyy-MM-dd"),
      "endDate": Utilities.formatDate(singlePlacementArray[6], ss.getSpreadsheetTimeZone(), "yyyy-MM-dd"),
      "placementAssignments": [
        {
          "placementId": parseInt(singlePlacementArray[9]),
          "active": true,
          //"sslRequired": false,
        }
      ]
    });

I get this error, even thought the profile_id is an int.

GoogleJsonResponseException: API call to dfareporting.ads.insert failed with error: Invalid value at 'profile_id' (TYPE_INT64), "endDate,2023-06-30,placementAssignments,[Ljava.lang.Object;@7ad1fc95,campaignId,2.2529571E7,type,AD_SERVING_TRACKING,active,true,startDate,2021-05-29,advertiserId,6334010.0,name,video campaign test parallel tracking_cn+Video,archived,false"
Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

0

It seems that the arguments of the method of DoubleClickCampaigns.Ads.insert is DoubleClickCampaigns.Ads.insert(object, profileId). I thought that the reason of your issue might be due to this. And also, it seems that profileId is string (int64 format). So how about the following modification?

Modified script:

var ad = DoubleClickCampaigns.Ads.insert({
  "campaignId": parseInt(singlePlacementArray[0]),
  "advertiserId": parseInt(inputSheet.getRange("J9").getValue()),
  //"accountId": inputSheet.getRange("H9").getValue(),
  "name": singlePlacementArray[1],
  "active": true,
  "archived": false,
  "type": "AD_SERVING_TRACKING",
  "startDate": Utilities.formatDate(singlePlacementArray[5], ss.getSpreadsheetTimeZone(), "yyyy-MM-dd"),
  "endDate": Utilities.formatDate(singlePlacementArray[6], ss.getSpreadsheetTimeZone(), "yyyy-MM-dd"),
  "placementAssignments": [
    {
      "placementId": parseInt(singlePlacementArray[9]),
      "active": true,
      //"sslRequired": false,
    }
  ]
}, "6485800");

Note:

  • In this modified script, it supposes that your values in the object of the 1st argument and the value of profileId of the 2nd argument are valid values. Please be careful this.
  • From the official document, I'm not sure whether startDate and endDate can be used in this request. Are those startTime and endTime? If an error occurs for this, please check it again.

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Thanks, but how do you know the profileId is the second arg? The doc says:`The request body contains an instance of Ad.` – Elad Benda May 30 '21 at 00:11
  • 1
    @Elad Benda Thank you for replying. About your question of `how do you know the profileId is the second arg?`, in this case, you can see it at the auto-completion of the script editor like `insert(resource: Dfareporting_v3_4.Dfareporting.V3_4.Schema.Ad, profileId: string)`. – Tanaike May 30 '21 at 00:16
  • I changed and I now get an unexplained error: `Unexpected error while getting the method or property insert on object Apiary.dfareporting.ads.` Any idea how to make it clearer? – Elad Benda May 30 '21 at 00:22
  • @Elad Benda Thank you for replying. About your new issue, although I think that it is due to the object of 1st argument, unfortunately, I cannot understand about the detail of it from your error message. I apologize for this. In this case, I would like to propose to post it as new question. Because my answer is for your 1st question. I deeply apologize that I cannot resolve your all questions. This is due to my poor skill. I deeply apologize for this again. – Tanaike May 30 '21 at 00:31