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"
1

There are 1 best solutions below

4
On BEST ANSWER

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: