googleads / google-ads-ruby

Google Ads API Ruby Client Library
https://developers.google.com/google-ads/api/
Apache License 2.0
69 stars 67 forks source link

Need example on how to link a Merchant Center Account with Ads Account for API v15 #492

Open diegosaul402 opened 3 months ago

diegosaul402 commented 3 months ago

What is your question? Do you have an example for accepting the link invitation for a Merchant Center Account with an Ads account using API v15 and above?

Hello, I'm working on migrating this feature from API v14 to API v15 but only version 14 has a ruby example. Could you provide a guide on how to achieve this on v15 and above? Maybe add it to the examples folder. Thank you!

diegosaul402 commented 2 months ago

I managed to get the first part right, accepting an invitation, here is the snippet if useful for someone else

      query = <<~QUERY
        SELECT product_link_invitation.merchant_center.merchant_center_id,
               product_link_invitation.type
          FROM product_link_invitation
         WHERE product_link_invitation.status = 'APPROVED'
           AND product_link_invitation.type = 'MERCHANT_CENTER'
      QUERY

      result = client.service.google_ads.search(customer_id: customer_id, page_size: 10, query: query)

  client.service
        .product_link_invitation
        .update_product_link_invitation(customer_id: customer_id,
                                        product_link_invitation_status: :ACCEPTED,
                                        resource_name: result.product_link_invitation.resource_name)

But I'm still having issues with the direct linking without invitation This is what I have so fart

      invitation = client.resource.product_link{ |pl| pl.type = :MERCHANT_CENTER }

      client.service.product_link.create_product_link(customer_id: current_channel.ads_id, product_link: invitation)

Documentation says that product_link accepts a merchant_center_id but I get this error trying to set it. Effectively, I can only set type and resource_name for ProductLink, so what I'm doing wrong?

`method_missing': undefined method `merchant_center_id=' for <Google::Ads::GoogleAds::V16::Resources::ProductLink: resource_name: "", type: :MERCHANT_CENTER>:Google::Ads::GoogleAds::V16::Resources::ProductLink (NoMethodError)

@mcloonan sorry to tag you but I really appreciate your help.

mcloonan commented 2 months ago

Checking the docs, the merchant_center_id isn't directly on the product_link, but nested one level deep within a MerchantCenterIdentifier named merchant_center: https://developers.google.com/google-ads/api/reference/rpc/v16/ProductLink

I tried this code out and it seemed to work:

[4] pry(main)> product_link = client.resource.product_link do |pl|
[4] pry(main)*   pl.merchant_center = client.resource.merchant_center_identifier do |mc|
[4] pry(main)*     mc.merchant_center_id = 1234
[4] pry(main)*   end  
[4] pry(main)* end  
=> <Google::Ads::GoogleAds::V16::Resources::ProductLink: resource_name: "", type: :UNSPECIFIED, merchant_center: <Google::Ads::GoogleAds::V16::Resources::MerchantCenterIdentifier: merchant_center_id: 1234>>