Adding an existing sitelink to CampaignExtensionSetting

69 views
Skip to first unread message

Danny

unread,
Feb 7, 2017, 4:14:18 PM2/7/17
to AdWords API Forum
Hi

I'm trying to figure out an easier way to add an existing sitelink to a campaign (via CampaignExtensionSetting). This question also extends to adding sitelinks to adgroup (AdGroupExtensionSetting) and account level (CustomerExtensionSetting).

From https://developers.google.com/adwords/api/docs/reference/v201609/CampaignExtensionSettingService.ExtensionSetting, it seems like I can add a SitelinkFeedItem to the campaign's extension setting, which is great.

The problem is, it seems like there's no way to fetch an existing sitelink of the same object type (SitelinkFeedItem) as the FeedItemService only returns a FeedItem (https://developers.google.com/adwords/api/docs/reference/v201609/FeedItemService.FeedItem) object. Based on this, it seems a little silly/inefficient to recreate a new SitelinkFeedItem object based on the retrieved FeedItem, and then attach it to the Campaign's extension setting. It's quite cumbersome as you have to potentially recreate the start/end time, device preferences, scheduling and so on.

Is there a better/more elegant way of doing this? I wish there was a service which allows you to simply fetch the existing sitelink of type SitelinkFeedItem, which you can then simply add to the extension settings.

Thanks.

Danny

unread,
Feb 7, 2017, 4:45:34 PM2/7/17
to AdWords API Forum
Btw, I'm just referencing my comment on https://groups.google.com/forum/#!topic/adwords-api/szTBX5B5d8E.

Hi Nadine

Could you please share a sample code of adding an existing sitelink to an existing campaign via CampaignExtensionSettingServices? I'm trying to do something similar, but rather than create a new CampaignExtensionSetting, the CampaignExtensionSetting already exists with existing sitelinks (I'm just trying to add another SitelinkFeedItem to the extension setting).

When adding to the extension setting, do you simply create a new SitelinkFeedItem object and assign the 'FeedItemId' field with the existing ID (without populating anything else - e.g. status, feed type, start/end time) and when making the mutate request, the API will know to add the correct sitelink base on the 'FeedItemId' only?

Shwetha Vastrad (AdWords API Team)

unread,
Feb 7, 2017, 5:14:35 PM2/7/17
to AdWords API Forum
Hi Danny, 

I'm afraid you cannot pass the FeedItem objects returned in the response from the FeedItemService to add existing sitelinks. To add an existing sitelink to a campaign, you need to provide the FeedId and the FeedItemId in the SitelinkFeedItem object. You need not populate the rest of the feed item attributes. You can retrieve the FeedId and FeedItemId using FeedService and FeedItemService respectively. 

Let me know if this works. 

Regards,
Shwetha, AdWords API Team.

Danny

unread,
Feb 8, 2017, 6:13:05 PM2/8/17
to AdWords API Forum
Thanks - I can confirm this works. Below is the code snippet (if interested).

public function buildSitelinkFeedItem(FeedItem $feed_item) {
    $attributes = $feed_item->getAttributeValues();
    $sitelink_feed_item = new SitelinkFeedItem();
    $sitelink_feed_item->setFeedId($feed_item->getFeedId());
    $sitelink_feed_item->setFeedItemId($feed_item->getFeedItemId());
    return $sitelink_feed_item;
}
Reply all
Reply to author
Forward
0 new messages