googleads / google-api-ads-ruby

Ad Manager SOAP API Client Libraries for Ruby
297 stars 229 forks source link

AdsCommon::Errors::UnexpectedParametersError when using multiple CustomCriteriaSet #152

Closed eef closed 6 years ago

eef commented 6 years ago

I am trying to recreate the following custom targeting setup via the API.

screenshot_02_05_2018_00_36_56

I have the following setup when creating my line items custom targeting:

{
  :logical_operator => "OR",
  :xsi_type => "CustomCriteriaSet",
  :children => [
    {
      :xsi_type => "CustomCriteriaSet",
      :logical_operator => "AND",
      :children => [
        {
          :xsi_type => "CustomCriteria",
          :key_id => 11678001,
          :value_ids => [447916251724],
          :operator => "IS"
        },
        {
          :xsi_type => "CustomCriteria",
          :key_id => 11670889,
          :value_ids => [447930750961],
          :operator => "IS"
        }
      ]
    },
    {
      :xsi_type => "CustomCriteriaSet",
      :logical_operator => "AND",
      :children => [
        {
          :xsi_type => "CustomCriteria",
          :key_id => 11692815,
          :value_ids => [447931534554, 447931504101],
          :operator => "IS"
        },
        {
          :xsi_type => "CustomCriteria",
          :key_id => 11678001,
          :value_ids => [447916251724],
          :operator => "IS"
        }
      ]
    }
  ]
}

When I assign this to the Line Item using the custom_targeting field I get the following error:

#<AdsCommon::Errors::UnexpectedParametersError: AdsCommon::Errors::UnexpectedParametersError: [:key_id, :value_ids, :operator]>

I tested a few things and discovered if I setup the targeting with only 1 CustomCriteriaSet, like so, it works:

{
  :logical_operator => "OR",
  :xsi_type => "CustomCriteriaSet",
  :children => [
    {
      :xsi_type => "CustomCriteriaSet",
      :logical_operator => "AND",
      :children => [
        {
          :xsi_type => "CustomCriteria",
          :key_id => 11678001,
          :value_ids => [447916251724],
          :operator => "IS"
        },
        {
          :xsi_type => "CustomCriteria",
          :key_id => 11670889,
          :value_ids => [447930750961],
          :operator => "IS"
        }
      ]
    }
  ]
}

Is it possible to create the custom targeting setup with multiple CustomCriteriaSets? Am I missing anything at all? I followed the examples from https://github.com/googleads/google-api-ads-ruby/blob/master/dfp_api/examples/v201802/line_item_service/target_custom_criteria.rb and also read through the reference https://developers.google.com/doubleclick-publishers/docs/reference/v201802/LineItemService.Targeting#customtargeting

Stumped!

donovanfm commented 6 years ago

I'm happy to look into your issue. Can you tell me which version of the google-dfp-api gem you're using? I am using our latest gem (1.2.1), and I successfully updated a line item on our test account with the exact CustomCriteriaSet structure you're trying to make.

Also, if you could send me an expanded code snippet so that I can see how you're setting the custom_targeting and calling the API, I could further debug this for you. I assume you're setting the targeting like this: line_item[:targeting][:custom_targeting].

eef commented 6 years ago

Hey - Thanks for the reply. I was able to get this working. I was dynamically generating a hash using Ruby and trying to send that. I hardcoded the targeting hash and sent that in the update instead it works. I am going to setup a test this weekend showing exactly what is happening. I had to use the hardcoded hash in the meantime due to project time limit. I will leave this open as I this problem also happens on other end points.

donovanfm commented 6 years ago

Glad to hear you got this working (though not in your preferred manner). From the library's perspective, it shouldn't matter how the hash is generated, as long as the structure is the same. Are you logging the generated hash that you're making? Can you send me that generated hash?

eef commented 6 years ago

When I get access to my laptop this evening I will send across the original version that wouldnt work and then the code that I got working. I will provide a bit of context as well as example data being passed to the methods to generate the hash. The weirdest thing is...when took the generated hash and compared it to the hardcoded hash with generated_hash == hardcoded_hash it would return true! I will update this issue tonight with the examples. I will also provide details of my environment just in case that makes a difference.

donovanfm commented 6 years ago

Hey, I was wondering if you were able to put together any more information on this issue. I made a request using the dynamically constructed hash from the target_custom_criteria.rb example, and it's working as expected. If we're going to keep this issue open, I'd like for it to be actionable on my end. Any help you can provide is much appreciated.

eef commented 6 years ago

Hey. Apologies. I will close this just now. Once I get time I will update it with an example.