Opteo / google-ads-api

Google Ads API client library for Node.js
https://opteo.com
MIT License
270 stars 90 forks source link

Can't change a Promotion Asset from "Money Amount Off" to "Percent Off". #490

Open jstoeffler opened 7 months ago

jstoeffler commented 7 months ago

Hi,

Thanks for maintaining this super helpful library!

I am facing a new issue: It doesn't seem possible to change a Promotion Asset from "Money Amount Off" to "Percent Off".

I have created a repo with a minimal example to reproduce the problem.

I have tried 3 approaches:

  1. Setting money_amount_off to null
await customer.assets.update([
      {
        resource_name: resourceName,
        promotion_asset: {
          percent_off: toMicros(0.2),
          money_amount_off: null,
        },
      },
    ]);

=> this raises this error:

{
  "errors": [
    {
      "error_code": {
        "asset_error": "PROMOTION_CANNOT_SET_PERCENT_OFF_AND_MONEY_AMOUNT_OFF"
      },
      "message": "Cannot set both percent off and money amount off fields of promotion asset.",
      "location": {
        "field_path_elements": [
          {
            "field_name": "operations",
            "index": 0
          },
          {
            "field_name": "update"
          },
          {
            "field_name": "promotion_asset"
          },
          {
            "field_name": "percent_off"
          }
        ]
      }
    }
  ],
}
  1. Not setting money_amount_off

=> Same error

  1. Setting money_amount_off to {currency_code: "USD",amount_micros:0}
await customer.assets.update([
      {
        resource_name: resourceName,
        promotion_asset: {
          percent_off: toMicros(0.2),
          money_amount_off: { currency_code: "USD", amount_micros: 0 },
        },
      },
    ]);

=> this raises this error:

{
  "errors": [
    {
      "error_code": {
        "range_error": "TOO_LOW"
      },
      "message": "Too low.",
      "trigger": {
        "int64_value": "0"
      },
      "location": {
        "field_path_elements": [
          {
            "field_name": "operations",
            "index": 0
          },
          {
            "field_name": "update"
          },
          {
            "field_name": "promotion_asset"
          },
          {
            "field_name": "money_amount_off"
          },
          {
            "field_name": "amount_micros"
          }
        ]
      }
    }
  ],
}

What makes me think this could be a bug, is that switching from "Percent Off" to "Money Amount Off" is possible by setting the percent_off property to 0 (my sample code does that). It's the opposite that's not possible.