Thanks to help from Vishal, I got this working by doing nearly what I had 
originally, but changing the second (and all subsequent) 
CampaignExtensionSettingOperations to SET, with the previously used 
Temporary ID. Like this:

campaign_extension1 = {
  campaign_id: -2,
  extension_type: 'SITELINK',
  extension_setting: {
    xsi_type: 'ExtensionSetting',
    extensions: [
      feed_item_id: -5,                 # Temporary ID established here
      xsi_type: 'SitelinkFeedItem',
      sitelink_text: 'Store Hours',
      sitelink_final_urls: {
        urls: ['http://www.example.com/']
      }
    ]
  }
}
campaign_extension1_op = {
  xsi_type: 'CampaignExtensionSettingOperation',
  operator: 'ADD',                     # ADD operator for first one, to 
make the sitelink
  operand: campaign_extension1
}


campaign_extension2 = {
  campaign_id: -4,
  extension_type: 'SITELINK',
  extension_setting: {
    xsi_type: 'ExtensionSetting',
    extensions: [
      feed_item_id: -5,                # Temporary ID re-used here
      xsi_type: 'SitelinkFeedItem'
    ]
  }
}
campaign_extension2_op = {
  xsi_type: 'CampaignExtensionSettingOperation',
  operator: 'SET',                     # SET operator, instead of ADD
  operand: campaign_extension2
}
ops = ops << campaign_extension1_op << campaign_extension2_op

This results in the same feed item (based on feed item id) being used:

  {
    "result": {
      "campaign_extension_setting": {
        "extension_type": "SITELINK",
        "extension_setting": {
          "extensions": {
            "feed_id": "20505208",
            "feed_item_id": "11299267966",
            "status": "ENABLED",
            "feed_type": "SITELINK",
            "extension_feed_item_type": "SitelinkFeedItem",
            "sitelink_text": "Store Hours",
            "sitelink_final_urls": {
              "urls": "http://www.example.com/";
            }
          },
          "platform_restrictions": "NONE"
        }
      }
    },
    "index": "12"
  },
  {
    "result": {
      "campaign_extension_setting": {
        "extension_type": "SITELINK",
        "extension_setting": {
          "extensions": {
            "feed_id": "20505208",
            "feed_item_id": "11299267966",
            "status": "ENABLED",
            "feed_type": "SITELINK",
            "extension_feed_item_type": "SitelinkFeedItem",
            "sitelink_text": "Store Hours",
            "sitelink_final_urls": {
              "urls": "http://www.example.com/";
            }
          },
          "platform_restrictions": "NONE"
        }
      }
    },
    "index": "13"
  }

Confirmed that this was the same sitelink in the UI as well, it checks out.

Thanks again for the help Vishal.
- Alex


On Monday, February 27, 2017 at 2:56:39 PM UTC-6, Alexander Cavalli wrote:
>
> Hi there,
>
> This is somewhat related to an earlier discussion I had with Nadine 
> Sundquist here:
>
> https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/adwords-api/szTBX5B5d8E/jkRkPuOMDgAJ
>
> I would like to generate sitelinks that are shared between multiple 
> campaigns using the Batch Service, preferably with a single batch job. 
> Assuming this is possible, what sort of operations will I need to use to 
> achieve this? In my particular case, all of the campaigns will already have 
> been created, and I have their ids, but the sitelinks may or may not exist 
> yet. 
>
> In the case where the sitelinks are new, I have tried something like this 
> (I'm using Ruby, and in this case I made the campaigns earlier in the Batch 
> Job and used pseudo ids, but that probably shouldn't matter):
>
> extension_setting = {
>   xsi_type: 'ExtensionSetting',
>   extensions: [
>     feed_item_id: -5,
>     xsi_type: 'SitelinkFeedItem',
>     sitelink_text: 'Store Hours',
>     sitelink_final_urls: {
>       urls: ['http://www.example.com/']
>     }
>   ]
> }
>
> campaign_extension1 = {
>   campaign_id: -2,
>   extension_type: 'SITELINK',
>   extension_setting: extension_setting
> }
> campaign_extension1_op = {
>   xsi_type: 'CampaignExtensionSettingOperation',
>   operator: 'ADD',
>   operand: campaign_extension1
> }
> campaign_extension2 = {
>   campaign_id: -4,
>   extension_type: 'SITELINK',
>   extension_setting: extension_setting
> }
> campaign_extension2_op = {
>   xsi_type: 'CampaignExtensionSettingOperation',
>   operator: 'ADD',
>   operand: campaign_extension2
> }
>
> # ops here contains operations to generate campaigns with ids -2 and -4 as 
> well
> ops = ops << campaign_extension1_op << campaign_extension2_op
>
> But the response contained a DUPLICATE_ELEMENT error on the 
> campaign_extension_2_op operation.
>
>   {
>     "result": {
>       "campaign_extension_setting": {
>         "extension_type": "SITELINK",
>         "extension_setting": {
>           "extensions": {
>             "feed_id": "20505208",
>             "feed_item_id": "11262219902",
>             "status": "ENABLED",
>             "feed_type": "SITELINK",
>             "extension_feed_item_type": "SitelinkFeedItem",
>             "sitelink_text": "Store Hours",
>             "sitelink_final_urls": {
>               "urls": "http://www.example.com/";
>             }
>           },
>           "platform_restrictions": "NONE"
>         }
>       }
>     },
>     "index": "12"
>   },
>   {
>     "error_list": {
>       "errors": {
>         "field_path": 
> "operations[13].operand.extensionSetting.extensions[0].feedItemId",
>         "trigger": "TempFeedItemId{id=5}",
>         "error_string": "DistinctError.DUPLICATE_ELEMENT",
>         "api_error_type": "DistinctError",
>         "reason": "DUPLICATE_ELEMENT"
>       }
>     },
>     "index": "13"
>   }
>
> There are many other operation permutations that conceivably could work 
> (including some combination of FeedItemOperations and 
> CampaignExtensionSettingOperations, for instance), so I thought I would 
> reach out before I attempted to test all of them. For both the case of new 
> sitelinks and existing sitelinks (where I have a feed item id), what 
> operations should I use to attach these sitelinks to multiple campaigns 
> within a Batch Job?
>
> Thanks,
> - Alex
>
>
>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/7be60350-b687-4aa1-8e55-c765eb53727b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • How to share s... Alexander Cavalli
    • Re: How t... 'Vishal Vinayak (Adwords API Team)' via AdWords API Forum
      • Re: H... Alexander Cavalli
        • R... Alexander Cavalli
          • ... 'Vishal Vinayak (Adwords API Team)' via AdWords API Forum
            • ... Alexander Cavalli
    • Re: How t... Alexander Cavalli
      • Re: H... 'Vishal Vinayak (Adwords API Team)' via AdWords API Forum
        • R... Alexander Cavalli
          • ... 'Vishal Vinayak (Adwords API Team)' via AdWords API Forum
            • ... Alexander Cavalli
              • ... 'Vishal Vinayak (Adwords API Team)' via AdWords API Forum
                • ... 'Nadine Sundquist (AdWords API Team)' via AdWords API Forum
                • ... Alexander Cavalli
                • ... 'Nadine Sundquist (AdWords API Team)' via AdWords API Forum
                • ... Alexander Cavalli
                • ... 'Nadine Sundquist (AdWords API Team)' via AdWords API Forum

Reply via email to