Class CampaignDraftServiceClient

  • All Implemented Interfaces:
    com.google.api.gax.core.BackgroundResource, java.lang.AutoCloseable

    @Generated("by gapic-generator-java")
    public class CampaignDraftServiceClient
    extends java.lang.Object
    implements com.google.api.gax.core.BackgroundResource
    Service Description: Service to manage campaign drafts.

    This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

    
     try (CampaignDraftServiceClient campaignDraftServiceClient =
         CampaignDraftServiceClient.create()) {
       String customerId = "customerId-1581184615";
       List<CampaignDraftOperation> operations = new ArrayList<>();
       MutateCampaignDraftsResponse response =
           campaignDraftServiceClient.mutateCampaignDrafts(customerId, operations);
     }
     

    Note: close() needs to be called on the CampaignDraftServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

    The surface of this class includes several types of Java methods for each of the API's methods:

    1. A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
    2. A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
    3. A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

    See the individual methods for example code.

    Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

    This class can be customized by passing in a custom instance of CampaignDraftServiceSettings to create(). For example:

    To customize credentials:

    
     CampaignDraftServiceSettings campaignDraftServiceSettings =
         CampaignDraftServiceSettings.newBuilder()
             .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
             .build();
     CampaignDraftServiceClient campaignDraftServiceClient =
         CampaignDraftServiceClient.create(campaignDraftServiceSettings);
     

    To customize the endpoint:

    
     CampaignDraftServiceSettings campaignDraftServiceSettings =
         CampaignDraftServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
     CampaignDraftServiceClient campaignDraftServiceClient =
         CampaignDraftServiceClient.create(campaignDraftServiceSettings);
     

    Please refer to the GitHub repository's samples for more quickstart code snippets.

    • Constructor Detail

      • CampaignDraftServiceClient

        protected CampaignDraftServiceClient​(CampaignDraftServiceSettings settings)
                                      throws java.io.IOException
        Constructs an instance of CampaignDraftServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
        Throws:
        java.io.IOException
      • CampaignDraftServiceClient

        @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
        protected CampaignDraftServiceClient​(CampaignDraftServiceStub stub)
    • Method Detail

      • create

        public static final CampaignDraftServiceClient create()
                                                       throws java.io.IOException
        Constructs an instance of CampaignDraftServiceClient with default settings.
        Throws:
        java.io.IOException
      • create

        public static final CampaignDraftServiceClient create​(CampaignDraftServiceSettings settings)
                                                       throws java.io.IOException
        Constructs an instance of CampaignDraftServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
        Throws:
        java.io.IOException
      • create

        @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
        public static final CampaignDraftServiceClient create​(CampaignDraftServiceStub stub)
        Constructs an instance of CampaignDraftServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(CampaignDraftServiceSettings).
      • getStub

        @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
        public CampaignDraftServiceStub getStub()
      • getOperationsClient

        public final com.google.longrunning.OperationsClient getOperationsClient()
        Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.
      • mutateCampaignDrafts

        public final MutateCampaignDraftsResponse mutateCampaignDrafts​(java.lang.String customerId,
                                                                       java.util.List<CampaignDraftOperation> operations)
        Creates, updates, or removes campaign drafts. Operation statuses are returned.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CampaignDraftError]() [DatabaseError]() [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           String customerId = "customerId-1581184615";
           List<CampaignDraftOperation> operations = new ArrayList<>();
           MutateCampaignDraftsResponse response =
               campaignDraftServiceClient.mutateCampaignDrafts(customerId, operations);
         }
         
        Parameters:
        customerId - Required. The ID of the customer whose campaign drafts are being modified.
        operations - Required. The list of operations to perform on individual campaign drafts.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • mutateCampaignDrafts

        public final MutateCampaignDraftsResponse mutateCampaignDrafts​(MutateCampaignDraftsRequest request)
        Creates, updates, or removes campaign drafts. Operation statuses are returned.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CampaignDraftError]() [DatabaseError]() [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           MutateCampaignDraftsRequest request =
               MutateCampaignDraftsRequest.newBuilder()
                   .setCustomerId("customerId-1581184615")
                   .addAllOperations(new ArrayList<CampaignDraftOperation>())
                   .setPartialFailure(true)
                   .setValidateOnly(true)
                   .build();
           MutateCampaignDraftsResponse response =
               campaignDraftServiceClient.mutateCampaignDrafts(request);
         }
         
        Parameters:
        request - The request object containing all of the parameters for the API call.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • mutateCampaignDraftsCallable

        public final com.google.api.gax.rpc.UnaryCallable<MutateCampaignDraftsRequest,​MutateCampaignDraftsResponse> mutateCampaignDraftsCallable()
        Creates, updates, or removes campaign drafts. Operation statuses are returned.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CampaignDraftError]() [DatabaseError]() [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           MutateCampaignDraftsRequest request =
               MutateCampaignDraftsRequest.newBuilder()
                   .setCustomerId("customerId-1581184615")
                   .addAllOperations(new ArrayList<CampaignDraftOperation>())
                   .setPartialFailure(true)
                   .setValidateOnly(true)
                   .build();
           ApiFuture<MutateCampaignDraftsResponse> future =
               campaignDraftServiceClient.mutateCampaignDraftsCallable().futureCall(request);
           // Do something.
           MutateCampaignDraftsResponse response = future.get();
         }
         
      • promoteCampaignDraftAsync

        public final com.google.api.gax.longrunning.OperationFuture<com.google.protobuf.Empty,​com.google.protobuf.Empty> promoteCampaignDraftAsync​(CampaignDraftName campaignDraft)
        Promotes the changes in a draft back to the base campaign.

        This method returns a Long Running Operation (LRO) indicating if the Promote is done. Use [Operations.GetOperation] to poll the LRO until it is done. Only a done status is returned in the response. See the status in the Campaign Draft resource to determine if the promotion was successful. If the LRO failed, use [CampaignDraftService.ListCampaignDraftAsyncErrors][google.ads.googleads.v10.services.CampaignDraftService.ListCampaignDraftAsyncErrors] to view the list of error reasons.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CampaignDraftError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           CampaignDraftName campaignDraft =
               CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]");
           campaignDraftServiceClient.promoteCampaignDraftAsync(campaignDraft).get();
         }
         
        Parameters:
        campaignDraft - Required. The resource name of the campaign draft to promote.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • promoteCampaignDraftAsync

        public final com.google.api.gax.longrunning.OperationFuture<com.google.protobuf.Empty,​com.google.protobuf.Empty> promoteCampaignDraftAsync​(java.lang.String campaignDraft)
        Promotes the changes in a draft back to the base campaign.

        This method returns a Long Running Operation (LRO) indicating if the Promote is done. Use [Operations.GetOperation] to poll the LRO until it is done. Only a done status is returned in the response. See the status in the Campaign Draft resource to determine if the promotion was successful. If the LRO failed, use [CampaignDraftService.ListCampaignDraftAsyncErrors][google.ads.googleads.v10.services.CampaignDraftService.ListCampaignDraftAsyncErrors] to view the list of error reasons.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CampaignDraftError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           String campaignDraft =
               CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]").toString();
           campaignDraftServiceClient.promoteCampaignDraftAsync(campaignDraft).get();
         }
         
        Parameters:
        campaignDraft - Required. The resource name of the campaign draft to promote.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • promoteCampaignDraftAsync

        public final com.google.api.gax.longrunning.OperationFuture<com.google.protobuf.Empty,​com.google.protobuf.Empty> promoteCampaignDraftAsync​(PromoteCampaignDraftRequest request)
        Promotes the changes in a draft back to the base campaign.

        This method returns a Long Running Operation (LRO) indicating if the Promote is done. Use [Operations.GetOperation] to poll the LRO until it is done. Only a done status is returned in the response. See the status in the Campaign Draft resource to determine if the promotion was successful. If the LRO failed, use [CampaignDraftService.ListCampaignDraftAsyncErrors][google.ads.googleads.v10.services.CampaignDraftService.ListCampaignDraftAsyncErrors] to view the list of error reasons.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CampaignDraftError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           PromoteCampaignDraftRequest request =
               PromoteCampaignDraftRequest.newBuilder()
                   .setCampaignDraft(
                       CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]")
                           .toString())
                   .setValidateOnly(true)
                   .build();
           campaignDraftServiceClient.promoteCampaignDraftAsync(request).get();
         }
         
        Parameters:
        request - The request object containing all of the parameters for the API call.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • promoteCampaignDraftOperationCallable

        public final com.google.api.gax.rpc.OperationCallable<PromoteCampaignDraftRequest,​com.google.protobuf.Empty,​com.google.protobuf.Empty> promoteCampaignDraftOperationCallable()
        Promotes the changes in a draft back to the base campaign.

        This method returns a Long Running Operation (LRO) indicating if the Promote is done. Use [Operations.GetOperation] to poll the LRO until it is done. Only a done status is returned in the response. See the status in the Campaign Draft resource to determine if the promotion was successful. If the LRO failed, use [CampaignDraftService.ListCampaignDraftAsyncErrors][google.ads.googleads.v10.services.CampaignDraftService.ListCampaignDraftAsyncErrors] to view the list of error reasons.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CampaignDraftError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           PromoteCampaignDraftRequest request =
               PromoteCampaignDraftRequest.newBuilder()
                   .setCampaignDraft(
                       CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]")
                           .toString())
                   .setValidateOnly(true)
                   .build();
           OperationFuture<Empty, Empty> future =
               campaignDraftServiceClient.promoteCampaignDraftOperationCallable().futureCall(request);
           // Do something.
           future.get();
         }
         
      • promoteCampaignDraftCallable

        public final com.google.api.gax.rpc.UnaryCallable<PromoteCampaignDraftRequest,​com.google.longrunning.Operation> promoteCampaignDraftCallable()
        Promotes the changes in a draft back to the base campaign.

        This method returns a Long Running Operation (LRO) indicating if the Promote is done. Use [Operations.GetOperation] to poll the LRO until it is done. Only a done status is returned in the response. See the status in the Campaign Draft resource to determine if the promotion was successful. If the LRO failed, use [CampaignDraftService.ListCampaignDraftAsyncErrors][google.ads.googleads.v10.services.CampaignDraftService.ListCampaignDraftAsyncErrors] to view the list of error reasons.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CampaignDraftError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           PromoteCampaignDraftRequest request =
               PromoteCampaignDraftRequest.newBuilder()
                   .setCampaignDraft(
                       CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]")
                           .toString())
                   .setValidateOnly(true)
                   .build();
           ApiFuture<Operation> future =
               campaignDraftServiceClient.promoteCampaignDraftCallable().futureCall(request);
           // Do something.
           future.get();
         }
         
      • listCampaignDraftAsyncErrors

        public final CampaignDraftServiceClient.ListCampaignDraftAsyncErrorsPagedResponse listCampaignDraftAsyncErrors​(CampaignDraftName resourceName)
        Returns all errors that occurred during CampaignDraft promote. Throws an error if called before campaign draft is promoted. Supports standard list paging.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           CampaignDraftName resourceName =
               CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]");
           for (Status element :
               campaignDraftServiceClient.listCampaignDraftAsyncErrors(resourceName).iterateAll()) {
             // doThingsWith(element);
           }
         }
         
        Parameters:
        resourceName - Required. The name of the campaign draft from which to retrieve the async errors.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • listCampaignDraftAsyncErrors

        public final CampaignDraftServiceClient.ListCampaignDraftAsyncErrorsPagedResponse listCampaignDraftAsyncErrors​(java.lang.String resourceName)
        Returns all errors that occurred during CampaignDraft promote. Throws an error if called before campaign draft is promoted. Supports standard list paging.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           String resourceName =
               CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]").toString();
           for (Status element :
               campaignDraftServiceClient.listCampaignDraftAsyncErrors(resourceName).iterateAll()) {
             // doThingsWith(element);
           }
         }
         
        Parameters:
        resourceName - Required. The name of the campaign draft from which to retrieve the async errors.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • listCampaignDraftAsyncErrors

        public final CampaignDraftServiceClient.ListCampaignDraftAsyncErrorsPagedResponse listCampaignDraftAsyncErrors​(ListCampaignDraftAsyncErrorsRequest request)
        Returns all errors that occurred during CampaignDraft promote. Throws an error if called before campaign draft is promoted. Supports standard list paging.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           ListCampaignDraftAsyncErrorsRequest request =
               ListCampaignDraftAsyncErrorsRequest.newBuilder()
                   .setResourceName(
                       CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]")
                           .toString())
                   .setPageToken("pageToken873572522")
                   .setPageSize(883849137)
                   .build();
           for (Status element :
               campaignDraftServiceClient.listCampaignDraftAsyncErrors(request).iterateAll()) {
             // doThingsWith(element);
           }
         }
         
        Parameters:
        request - The request object containing all of the parameters for the API call.
        Throws:
        com.google.api.gax.rpc.ApiException - if the remote call fails
      • listCampaignDraftAsyncErrorsPagedCallable

        public final com.google.api.gax.rpc.UnaryCallable<ListCampaignDraftAsyncErrorsRequest,​CampaignDraftServiceClient.ListCampaignDraftAsyncErrorsPagedResponse> listCampaignDraftAsyncErrorsPagedCallable()
        Returns all errors that occurred during CampaignDraft promote. Throws an error if called before campaign draft is promoted. Supports standard list paging.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           ListCampaignDraftAsyncErrorsRequest request =
               ListCampaignDraftAsyncErrorsRequest.newBuilder()
                   .setResourceName(
                       CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]")
                           .toString())
                   .setPageToken("pageToken873572522")
                   .setPageSize(883849137)
                   .build();
           ApiFuture<Status> future =
               campaignDraftServiceClient
                   .listCampaignDraftAsyncErrorsPagedCallable()
                   .futureCall(request);
           // Do something.
           for (Status element : future.get().iterateAll()) {
             // doThingsWith(element);
           }
         }
         
      • listCampaignDraftAsyncErrorsCallable

        public final com.google.api.gax.rpc.UnaryCallable<ListCampaignDraftAsyncErrorsRequest,​ListCampaignDraftAsyncErrorsResponse> listCampaignDraftAsyncErrorsCallable()
        Returns all errors that occurred during CampaignDraft promote. Throws an error if called before campaign draft is promoted. Supports standard list paging.

        List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]()

        Sample code:

        
         try (CampaignDraftServiceClient campaignDraftServiceClient =
             CampaignDraftServiceClient.create()) {
           ListCampaignDraftAsyncErrorsRequest request =
               ListCampaignDraftAsyncErrorsRequest.newBuilder()
                   .setResourceName(
                       CampaignDraftName.of("[CUSTOMER_ID]", "[BASE_CAMPAIGN_ID]", "[DRAFT_ID]")
                           .toString())
                   .setPageToken("pageToken873572522")
                   .setPageSize(883849137)
                   .build();
           while (true) {
             ListCampaignDraftAsyncErrorsResponse response =
                 campaignDraftServiceClient.listCampaignDraftAsyncErrorsCallable().call(request);
             for (Status element : response.getResponsesList()) {
               // doThingsWith(element);
             }
             String nextPageToken = response.getNextPageToken();
             if (!Strings.isNullOrEmpty(nextPageToken)) {
               request = request.toBuilder().setPageToken(nextPageToken).build();
             } else {
               break;
             }
           }
         }
         
      • close

        public final void close()
        Specified by:
        close in interface java.lang.AutoCloseable
      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface com.google.api.gax.core.BackgroundResource
      • isShutdown

        public boolean isShutdown()
        Specified by:
        isShutdown in interface com.google.api.gax.core.BackgroundResource
      • isTerminated

        public boolean isTerminated()
        Specified by:
        isTerminated in interface com.google.api.gax.core.BackgroundResource
      • shutdownNow

        public void shutdownNow()
        Specified by:
        shutdownNow in interface com.google.api.gax.core.BackgroundResource
      • awaitTermination

        public boolean awaitTermination​(long duration,
                                        java.util.concurrent.TimeUnit unit)
                                 throws java.lang.InterruptedException
        Specified by:
        awaitTermination in interface com.google.api.gax.core.BackgroundResource
        Throws:
        java.lang.InterruptedException