google-apps-scriptdouble-click-advertisinggoogle-apps-script-api

GoogleJsonResponseException: API call to dfareporting.ads.insert failed with error: Invalid value at 'profile_id' (TYPE_INT64)


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"

Solution

  • 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:

    References: