Bạn có thể sử dụng các phương thức sau để cập nhật giao dịch từng giao dịch hoặc theo lô. Bạn có thể cập nhật giao dịch trong quá trình thương lượng, hoặc bắt đầu thương lượng lại một đề xuấtđã được chấp nhận trước đó.
Sửa đổi giao dịch
Bạn có thể sử dụng phương thức
buyers.proposals.deals.patch
để cập nhật một giao dịch nhất định được liên kết với một
đề xuất
cho tài khoản người mua của bạn hoặc một trong các
khách hàngcủa bạn.
Bạn có thể sử dụng patch để thay đổi một giao dịch được đề xuất trong quá trình thương lượng ban đầu và bắt đầu thương lượng lại một giao dịch đã hoàn tất.
Mẫu sau đây minh hoạ cách bạn có thể cập nhật một giao dịch bằng phương thức patch.
REST
Yêu cầu
PATCH https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/proposals/MP21673270/deals/52404updateMask=flightStartTime%2CflightEndTime%2CprogrammaticGuaranteedTerms.fixedPrice.amount.units%2CprogrammaticGuaranteedTerms.fixedPrice.amount.nanos&alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json
{
"proposalRevision": "4",
"flightStartTime": "2037-04-02T20:15:59.584739+00:00",
"flightEndTime": "2037-04-03T20:15:59.584739+00:00",
"programmaticGuaranteedTerms": {
"fixedPrice": {
"amount": {
"units": 1,
"nanos": 500000000
}
}
}
}Phản hồi
{
"name": "buyers/12345678/proposals/MP21673270/deals/52404",
"createTime": "2036-12-27T04:02:39.731Z",
"updateTime": "2037-03-31T20:12:40.875Z",
"proposalRevision": "5",
"displayName": "test_deal_7435251",
"buyer": "buyers/12345678",
"publisherProfile": "buyers/12345678/publisherProfiles/PP54321",
"flightStartTime": "2037-04-02T20:12:39.038Z",
"flightEndTime": "2037-04-03T20:12:39.038Z",
"targeting": {
"inventorySizeTargeting": {
"targetedInventorySizes": [
{
"width": "1024",
"height": "768",
"type": "PIXEL"
}
]
}
},
"creativeRequirements": {
"creativePreApprovalPolicy": "SELLER_PRE_APPROVAL_NOT_REQUIRED",
"creativeSafeFrameCompatibility": "COMPATIBLE",
"programmaticCreativeSource": "ADVERTISER",
"creativeFormat": "DISPLAY"
},
"deliveryControl": {
"deliveryRateType": "EVENLY"
},
"billedBuyer": "buyers/12345678",
"dealType": "PROGRAMMATIC_GUARANTEED",
"programmaticGuaranteedTerms": {
"guaranteedLooks": "100",
"fixedPrice": {
"type": "CPM",
"amount": {
"currencyCode": "CNY",
"units": "1",
"nanos": 500000000
}
},
"reservationType": "STANDARD"
},
"sellerTimeZone": {
"id": "Asia/Shanghai"
}
}Java
/* * Copyright 2022 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.api.services.samples.authorizedbuyers.marketplace.v1.buyers.proposals.deals; import com.google.api.services.authorizedbuyersmarketplace.v1.AuthorizedBuyersMarketplace; import com.google.api.services.authorizedbuyersmarketplace.v1.model.Deal; import com.google.api.services.authorizedbuyersmarketplace.v1.model.Money; import com.google.api.services.authorizedbuyersmarketplace.v1.model.Price; import com.google.api.services.authorizedbuyersmarketplace.v1.model.ProgrammaticGuaranteedTerms; import com.google.api.services.samples.authorizedbuyers.marketplace.v1.Utils; import java.io.IOException; import java.security.GeneralSecurityException; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; import org.joda.time.DateTime; import org.joda.time.format.ISODateTimeFormat; /** * Patches a programmatic guaranteed deal at the given revision number. * * <p>This will modify the deal's flightStartTime, flightEndTime, and programmaticGuaranteedTerms. * * <p>Note: If the revision number is lower than what is stored for the deal server-side, the * operation will be deemed obsolete and an error will be returned. */ public class PatchProgrammaticGuaranteedDeals { public static void execute(AuthorizedBuyersMarketplace marketplaceClient, Namespace parsedArgs) { Long accountId = parsedArgs.getLong("account_id"); String proposalId = parsedArgs.getString("proposal_id"); Long dealId = parsedArgs.getLong("deal_id"); String name = String.format("buyers/%d/proposals/%s/deals/%d", accountId, proposalId, dealId); Long proposalRevision = parsedArgs.getLong("proposal_revision"); Deal patchedProgrammaticGuaranteedDeal = new Deal(); patchedProgrammaticGuaranteedDeal.setProposalRevision(proposalRevision); // Patch new start and end flight times in RFC3339 UTC "Zulu" format. DateTime startTime = DateTime.now().plusDays(1); DateTime endTime = startTime.plusDays(1); patchedProgrammaticGuaranteedDeal.setFlightStartTime( startTime.toString(ISODateTimeFormat.dateTime())); patchedProgrammaticGuaranteedDeal.setFlightEndTime( endTime.toString(ISODateTimeFormat.dateTime())); Money fixedPriceAmount = new Money(); fixedPriceAmount.setUnits(parsedArgs.getLong("fixed_price_units")); fixedPriceAmount.setNanos(parsedArgs.getInt("fixed_price_nanos")); Price fixedPrice = new Price(); fixedPrice.setAmount(fixedPriceAmount); ProgrammaticGuaranteedTerms programmaticGuaranteedTerms = new ProgrammaticGuaranteedTerms(); programmaticGuaranteedTerms.setFixedPrice(fixedPrice); patchedProgrammaticGuaranteedDeal.setProgrammaticGuaranteedTerms(programmaticGuaranteedTerms); String updateMask = "flightStartTime,flightEndTime," + "programmaticGuaranteedTerms.fixedPrice.amount.units," + "programmaticGuaranteedTerms.fixedPrice.amount.nanos"; Deal deal = null; try { deal = marketplaceClient .buyers() .proposals() .deals() .patch(name, patchedProgrammaticGuaranteedDeal) .setUpdateMask(updateMask) .execute(); } catch (IOException ex) { System.out.printf("Marketplace API returned error response:%n%s", ex); System.exit(1); } System.out.printf("Patching deal with name \"%s\":%n", name); Utils.printDeal(deal); } public static void main(String[] args) { ArgumentParser parser = ArgumentParsers.newFor("PatchProgrammaticGuaranteedDeals") .build() .defaultHelp(true) .description(("Patches a programmatic guaranteed deal at the given revision number.")); parser .addArgument("-a", "--account_id") .help( "The resource ID of the buyers resource under which the deal is being patched. " + "This will be used to construct the name used as a path parameter for the " + "deals.patch request.") .required(true) .type(Long.class); parser .addArgument("-d", "--deal_id") .help( "The resource ID of the buyers.proposals.deals resource that is being patched. " + "This will be used to construct the name used as a path parameter for the " + "deals.patch request.") .required(true) .type(Long.class); parser .addArgument("-p", "--proposal_id") .help( "The resource ID of the buyers.proposals resource under which the deal is being" + " patched. This will be used to construct the name used as a path parameter for" + " the deals.patch request.") .required(true) .type(String.class); parser .addArgument("-r", "--proposal_revision") .help( "The revision number for the proposal being modified. Each update to the proposal " + "or its deals causes the number to increment. The revision number specified must " + "match the value stored server-side in order for the operation to be performed.") .required(true) .type(Long.class); parser .addArgument("-u", "--fixed_price_units") .help("Whole units of the currency specified for the programmatic guaranteed deal.") .type(Long.class) .setDefault(1L); parser .addArgument("-n", "--fixed_price_nanos") .help( "Number of nano units of the currency specified for the programmatic guaranteed " + "deal.") .type(Integer.class) .setDefault(500000000); Namespace parsedArgs = null; try { parsedArgs = parser.parseArgs(args); } catch (ArgumentParserException ex) { parser.handleError(ex); System.exit(1); } AuthorizedBuyersMarketplace client = null; try { client = Utils.getMarketplaceClient(); } catch (IOException ex) { System.out.printf("Unable to create Marketplace API service:%n%s", ex); System.out.println("Did you specify a valid path to a service account key file?"); System.exit(1); } catch (GeneralSecurityException ex) { System.out.printf("Unable to establish secure HttpTransport:%n%s", ex); System.exit(1); } execute(client, parsedArgs); } }
Cập nhật giao dịch theo lô
Bạn có thể sử dụng
buyers.proposals.deals.batchUpdate
phương thức để cập nhật một hoặc nhiều giao dịch được liên kết với một đề xuất cho tài khoản người mua
của bạn hoặc một trong các khách hàng của bạn.
Ví dụ: bạn có thể bắt đầu thương lượng lại bằng cách cập nhật nhiều giao dịch có trong một đề xuất trong một lệnh gọi API.
Các giao dịch có trong nội dung của phương thức batchUpdate phải có cùng một đề xuất mẹ.
Mẫu sau đây minh hoạ cách bạn có thể cập nhật một hoặc nhiều giao dịch của một đề xuất bằng phương thức batchUpdate.
REST
Yêu cầu
POST https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/proposals/MP21673270/deals:batchUpdate?alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json
{
"requests": [
{
"deal": {
"name": "buyers/12345678/proposals/MP21673270/deals/52404",
"proposalRevision": "6",
"targeting": {
"userListTargeting": {
"targetedCriteriaIds": [
"111111"
]
}
}
},
"updateMask": "targeting.userListTargeting.targetedCriteriaIds"
}
]
}Phản hồi
{
"deals": [
{
"name": "buyers/12345678/proposals/MP21673270/deals/52404",
"createTime": "2036-12-27T04:02:39.731Z",
"updateTime": "2037-03-31T20:33:04.773Z",
"proposalRevision": "7",
"displayName": "test_deal_7435251",
"buyer": "buyers/12345678",
"publisherProfile": "buyers/12345678/publisherProfiles/PP54321",
"flightStartTime": "2037-04-02T20:12:39.038Z",
"flightEndTime": "2037-04-03T20:12:39.038Z",
"targeting": {
"inventorySizeTargeting": {
"targetedInventorySizes": [
{
"width": "1024",
"height": "768",
"type": "PIXEL"
}
]
},
"userListTargeting": {
"targetedCriteriaIds": [
"111111"
]
}
},
"creativeRequirements": {
"creativePreApprovalPolicy": "SELLER_PRE_APPROVAL_NOT_REQUIRED",
"creativeSafeFrameCompatibility": "COMPATIBLE",
"programmaticCreativeSource": "ADVERTISER",
"creativeFormat": "DISPLAY"
},
"deliveryControl": {
"deliveryRateType": "EVENLY"
},
"billedBuyer": "buyers/12345678",
"dealType": "PROGRAMMATIC_GUARANTEED",
"programmaticGuaranteedTerms": {
"guaranteedLooks": "100",
"fixedPrice": {
"type": "CPM",
"amount": {
"currencyCode": "CNY",
"units": "1",
"nanos": 500000000
}
},
"reservationType": "STANDARD"
},
"sellerTimeZone": {
"id": "Asia/Shanghai"
}
}
]
}Java
/* * Copyright 2022 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.api.services.samples.authorizedbuyers.marketplace.v1.buyers.proposals.deals; import com.google.api.services.authorizedbuyersmarketplace.v1.AuthorizedBuyersMarketplace; import com.google.api.services.authorizedbuyersmarketplace.v1.model.BatchUpdateDealsRequest; import com.google.api.services.authorizedbuyersmarketplace.v1.model.BatchUpdateDealsResponse; import com.google.api.services.authorizedbuyersmarketplace.v1.model.CriteriaTargeting; import com.google.api.services.authorizedbuyersmarketplace.v1.model.Deal; import com.google.api.services.authorizedbuyersmarketplace.v1.model.MarketplaceTargeting; import com.google.api.services.authorizedbuyersmarketplace.v1.model.UpdateDealRequest; import com.google.api.services.samples.authorizedbuyers.marketplace.v1.Utils; import java.io.IOException; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.List; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; /** * Patches the user list targeting of one or more deals for the given buyer's proposal. * * <p>This operation requires that the deals all exist under the same proposal. * * <p>The user list targeting of the given deals will be modified to target the specified user * lists. User lists can be retrieved via the Real-time Bidding API's buyers.userLists resource. You * can learn more about buyers.userLists in the reference documentation: * https://developers.google.com/authorized-buyers/apis/realtimebidding/reference/rest/v1/buyers.userLists * * <p>Note: Only preferred and programmatic guaranteed deals can be modified by the buyer; * attempting to modify a private auction deal will result in an error response. */ public class BatchUpdateDeals { public static void execute(AuthorizedBuyersMarketplace marketplaceClient, Namespace parsedArgs) { Long accountId = parsedArgs.getLong("account_id"); List<Long> dealIds = parsedArgs.getList("deal_ids"); String proposalId = parsedArgs.getString("proposal_id"); String parent = String.format("buyers/%d/proposals/%s", accountId, proposalId); Long proposalRevision = parsedArgs.getLong("proposal_revision"); List<Long> userListIds = parsedArgs.getList("user_list_ids"); List<UpdateDealRequest> updateDealRequests = new ArrayList<>(); // Populate the request body based on the deals specified. for (Long dealId : dealIds) { Deal deal = new Deal(); deal.setName(String.format("buyers/%d/proposals/%s/deals/%d", accountId, proposalId, dealId)); deal.setProposalRevision(proposalRevision); CriteriaTargeting userListTargeting = new CriteriaTargeting(); userListTargeting.setTargetedCriteriaIds(userListIds); MarketplaceTargeting marketplaceTargeting = new MarketplaceTargeting(); marketplaceTargeting.setUserListTargeting(userListTargeting); deal.setTargeting(marketplaceTargeting); UpdateDealRequest updateDealRequest = new UpdateDealRequest(); updateDealRequest.setDeal(deal); updateDealRequest.setUpdateMask("targeting.userListTargeting.targetedCriteriaIds"); updateDealRequests.add(updateDealRequest); } BatchUpdateDealsRequest batchUpdateDealsRequest = new BatchUpdateDealsRequest(); batchUpdateDealsRequest.setRequests(updateDealRequests); BatchUpdateDealsResponse response = null; try { response = marketplaceClient .buyers() .proposals() .deals() .batchUpdate(parent, batchUpdateDealsRequest) .execute(); } catch (IOException ex) { System.out.printf("Marketplace API returned error response:%n%s", ex); System.exit(1); } System.out.printf("Batch updating deals for proposal with name \"%s\":%n", parent); for (Deal deal : response.getDeals()) { Utils.printDeal(deal); } } public static void main(String[] args) { ArgumentParser parser = ArgumentParsers.newFor("BatchUpdateDeals") .build() .defaultHelp(true) .description( ("Patches the user list targeting of one or more deals for the given " + "buyer's proposal.")); parser .addArgument("-a", "--account_id") .help( "The resource ID of the buyers resource under which one or more deals are being" + " patched. This will be used to construct the proposal name used as a path" + " parameter for the deals.batchUpdate request, and each deal name included in the" + " request body.") .required(true) .type(Long.class); parser .addArgument("-d", "--deal_ids") .help( "The resource ID of one or more buyers.proposals.deals resources that will be patched" + " in a batch update operation. These will be used to construct the deal names" + " included in the request body. Specify each client ID separated by a space.") .required(true) .type(Long.class) .nargs("+"); parser .addArgument("-p", "--proposal_id") .help( "The resource ID of the buyers.proposals resource under which one or more deals is" + " being patched. This will be used to construct the name used as a path parameter" + " for the deals.batchUpdate request, and each deal name included in the request" + " body") .required(true); parser .addArgument("-r", "--proposal_revision") .help( "The revision number for the corresponding proposal of the deals being modified. Each" + " update to the proposal or its deals causes the number to increment. The" + " revision number specified must match the value stored server-side in order for" + " the operation to be performed.") .required(true) .type(Long.class); parser .addArgument("-u", "--user_list_ids") .help( "The resource ID of one or more buyers.userLists resources that are to be targeted " + "by the given deals. Specify each client ID separated by a space.") .required(true) .type(Long.class) .nargs("+"); Namespace parsedArgs = null; try { parsedArgs = parser.parseArgs(args); } catch (ArgumentParserException ex) { parser.handleError(ex); System.exit(1); } AuthorizedBuyersMarketplace client = null; try { client = Utils.getMarketplaceClient(); } catch (IOException ex) { System.out.printf("Unable to create Marketplace API service:%n%s", ex); System.out.println("Did you specify a valid path to a service account key file?"); System.exit(1); } catch (GeneralSecurityException ex) { System.out.printf("Unable to establish secure HttpTransport:%n%s", ex); System.exit(1); } execute(client, parsedArgs); } }