use of com.google.api.ads.admanager.axis.v202205.LineItemServiceInterface in project googleads-java-lib by googleads.
the class UpdateLineItems method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param lineItemId the ID of the line item to update.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long lineItemId) throws RemoteException {
// Get the LineItemService.
LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
// Create a statement to only select a single line item by ID.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", lineItemId);
// Get the line item.
LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
LineItem lineItem = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
// Update the line item's priority to High if possible.
if (lineItem.getLineItemType().equals(LineItemType.STANDARD)) {
lineItem.setPriority(6);
// Update the line item on the server.
LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });
for (LineItem updatedLineItem : lineItems) {
System.out.printf("Line item with ID %d and name '%s' was updated.%n", updatedLineItem.getId(), updatedLineItem.getName());
}
} else {
System.out.println("No line items were updated.");
}
}
Aggregations