SetTargetToAdGroup Service Operation

 

Associates the specified target with the specified ad group.

Request | Response

Error Codes

Service: CampaignManagementService.svc v10 | Namespace: https://bingads.microsoft.com/CampaignManagement/v10

Request Body

The SetTargetToAdGroupRequest object defines the elements of the request’s body. The elements must be in the same order as shown in the SOAP Request SOAP.

ElementDescriptionData Type
AdGroupIdThe identifier of the ad group to associate with the target.long
ReplaceAssociationIf the specified AdGroupId is already associated with a target, this element determines whether to replace the existing association between the ad group and target with the specified TargetId.

If set to True the operation will replace the existing association between the ad group and target with the specified TargetId.

The default value is False if not otherwise specified. If the value is False and if an association already exists, the operation will throw error 1427, CampaignServiceTargetAlreadyAssociatedWithEntity.

Note: If the specified ad group is not currently associated with a target, this element has no effect.
boolean
TargetIdThe identifier of the target to associate with the ad group.long

Request Headers

Set the required header elements for each service request. New customers are required to sign up for Bing Ads with a Microsoft Account, and to manage those accounts you must use OAuth. Existing users with legacy Bing Ads credentials may continue to specify the UserName and Password header elements. In future versions of the API, Bing Ads will transition exclusively to Microsoft Account authentication. For more information, see Getting Started With the Bing Ads API.

OAuth Authentication

These request headers are required for Managing User Authentication with OAuth.

ElementDescriptionData Type
AuthenticationTokenThe OAuth access token used to manage Bing Ads accounts linked to a Microsoft Account.string
CustomerAccountIdThe identifier of the account that owns the entities in the request. This header element must have the same value as the AccountId body element when both are required.

Note: Required for service operations related to ad extensions. As a best practice you should always specify this element for operations limited in scope to a single account per service call.
string
CustomerIdThe identifier of the customer that contains and owns the account. If you manage an account of another customer, you should use that customer ID instead of your own customer ID.

Note: Required for service operations related to targeting and editorial. As a best practice you should always specify this element.
string
DeveloperTokenThe client application's developer access token.string

Password Authentication

These request headers are required for legacy username and password authentication.

ElementDescriptionData Type
CustomerAccountIdThe identifier of the account that owns the entities in the request. This header element must have the same value as the AccountId body element when both are required.

Note: Required for service operations related to ad extensions. As a best practice you should always specify this element for operations limited in scope to a single account per service call.
string
CustomerIdThe identifier of the customer that contains and owns the account. If you manage an account of another customer, you should use that customer ID instead of your own customer ID.

Note: Required for service operations related to targeting and editorial. As a best practice you should always specify this element.
string
DeveloperTokenThe client application's developer access token.string
PasswordThe Bing Ads user's sign-in password.string
UserNameThe Bing Ads user's sign-in user name. You may not set this element to a Microsoft account or email address.string

Request SOAP

The following example shows the complete request envelope.

<s:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header xmlns="https://bingads.microsoft.com/CampaignManagement/v10">
    <Action mustUnderstand="1">SetTargetToAdGroup</Action>
    <ApplicationToken i:nil="false"></ApplicationToken>
    <AuthenticationToken i:nil="false"></AuthenticationToken>
    <CustomerAccountId i:nil="false"></CustomerAccountId>
    <CustomerId i:nil="false"></CustomerId>
    <DeveloperToken i:nil="false"></DeveloperToken>
    <Password i:nil="false"></Password>
    <UserName i:nil="false"></UserName>
  </s:Header>
  <s:Body>
    <SetTargetToAdGroupRequest xmlns="https://bingads.microsoft.com/CampaignManagement/v10">
      <AdGroupId></AdGroupId>
      <TargetId></TargetId>
      <ReplaceAssociation></ReplaceAssociation>
    </SetTargetToAdGroupRequest>
  </s:Body>
</s:Envelope>

Response Body

The response does not contain additional body elements.

Response Header

ElementDescriptionData Type
TrackingIdThe identifier of the log entry that contains details about the API call.string

Response SOAP

The following example shows the complete response envelope.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header xmlns="https://bingads.microsoft.com/CampaignManagement/v10">
    <TrackingId p4:nil="false" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance"></TrackingId>
  </s:Header>
  <s:Body>
    <SetTargetToAdGroupResponse xmlns="https://bingads.microsoft.com/CampaignManagement/v10" />
  </s:Body>
</s:Envelope>

If the service operation fails, it throws a FaultException exception, which contains one or more of the Bing Ads API error data objects. For information about the fault detail objects, see Campaign Management Error Data Objects and Handling Service Errors and Exceptions.The following are example error codes that the error objects can include when using this service operation. For all documented error codes, please see Bing Ads Operation Error Codes.

Error Code
InvalidCredentials

AddTargetsToLibraryDeleteTargetFromAdGroupDeleteTargetFromCampaignDeleteTargetsFromLibraryGetTargetsByAdGroupIdsGetTargetsByCampaignIdsGetTargetsByIdsGetTargetsInfoFromLibrarySetTargetToCampaignUpdateTargetsInLibrary

Community Additions

ADD
Show: