ยอมรับหรือยกเลิกข้อเสนอ

คุณยอมรับหรือยกเลิกข้อเสนอสำหรับผู้ซื้อได้โดยใช้วิธีการต่อไปนี้ และบัญชี ลูกค้า

ยอมรับข้อเสนอ

คุณสามารถใช้ buyers.proposals.accept เพื่ออนุมัติข้อเสนอและดีลที่เกี่ยวข้อง ณ เวลาที่ระบุ proposalRevision

ผู้ซื้อจะยอมรับข้อเสนอได้หลังจากที่ข้อเสนอได้รับการยอมรับแล้วเท่านั้น จากผู้เผยแพร่โฆษณา หากคุณยอมรับข้อเสนอก่อนผู้เผยแพร่โฆษณา buyers.proposals.accept แสดงผลข้อผิดพลาด

หากทั้ง 2 ฝ่ายยอมรับข้อเสนอ state ของข้อเสนอดังกล่าว FINALIZED และดีลของข้อเสนอจะมีสิทธิ์เริ่มแสดงโดยอิงตาม การกำหนดค่าได้

ตัวอย่างต่อไปนี้จะแสดงให้เห็นวิธีการรับข้อเสนอที่มี accept วิธี

REST

ส่งคำขอ

POST https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/proposals/MP48576074:accept?alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
 "proposalRevision": "4"
}

คำตอบ

{
 "name": "buyers/12345678/proposals/MP49876074",
 "updateTime": "2022-03-26T04:03:19.282Z",
 "proposalRevision": "5",
 "dealType": "PROGRAMMATIC_GUARANTEED",
 "displayName": "Test PG Proposal #0ce643e9-5518-4e8e-b352-0cb45cc2eeb2",
 "state": "FINALIZED",
 "originatorRole": "BUYER",
 "publisherProfile": "buyers/12345678/publisherProfiles/PP111111",
 "buyer": "buyers/12345678",
 "buyerPrivateData": {
   "referenceId": "2f5e9550-8d22-495e-ba38-9b9496347a3b"
 },
 "billedBuyer": "buyers/12345678",
 "sellerContacts": [
   {
     "email": "jeff@hypersonicmedia.com"
   },
   {
     "email": "alex@hypersonicmedia.com"
   },
 ],
 "buyerContacts": [
   {
     "email": "testemail89319783@test.com",
     "displayName": "Joe"
   }
 ],
 "lastUpdaterOrCommentorRole": "BUYER",
 "pausingConsented": true,
 "notes": [
   {
     "createTime": "2022-03-26T04:03:19.548Z",
     "creatorRole": "BUYER",
     "note": "Test programmatic guaranteed deal proposal."
   },
   {
     "createTime": "2022-03-26T05:36:23.406Z",
     "creatorRole": "BUYER",
     "note": "Test note."
   }
 ]
}

C#

/* 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
 *
 *     http://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.
 */

using Google.Apis.AuthorizedBuyersMarketplace.v1;
using Google.Apis.AuthorizedBuyersMarketplace.v1.Data;
using Mono.Options;

using System;
using System.Collections.Generic;

namespace Google.Apis.AuthorizedBuyersMarketplace.Examples.v1.Buyers.Proposals
{
    /// <summary>
    /// Accepts a proposal for the given account and proposal IDs.
    ///
    /// Note that a proposal can only be accepted if it is in the BUYER_ACCEPTANCE_REQUESTED
    /// state. Once both a buyer and seller have accepted a proposal, its state will change to
    /// FINALIZED.
    /// </summary>
    public class AcceptProposals : ExampleBase
    {
        private AuthorizedBuyersMarketplaceService mkService;

        /// <summary>
        /// Constructor.
        /// </summary>
        public AcceptProposals()
        {
            mkService = Utilities.GetAuthorizedBuyersMarketplaceService();
        }

        /// <summary>
        /// Returns a description about the code example.
        /// </summary>
        public override string Description
        {
            get => "This code example accepts a given proposal on behalf of the specified buyer.";
        }

        /// <summary>
        /// Parse specified arguments.
        /// </summary>
        protected override Dictionary<string, object> ParseArguments(List<string> exampleArgs) {
            string[] requiredOptions = new string[] {"account_id", "proposal_id",
                "proposal_revision"};
            bool showHelp = false;

            string accountId = null;
            string proposalId = null;
            long? proposalRevision = null;

            OptionSet options = new OptionSet {
                "Accepts a proposal for the given account and proposal IDs.",
                {
                    "h|help",
                    "Show help message and exit.",
                    h => showHelp = h != null
                },
                {
                    "a|account_id=",
                    ("[Required] The resource ID of the buyers resource under which the " +
                     "proposal exists. This will be used to construct the name used as a path " +
                     "parameter for the proposals.accept request."),
                    a => accountId = a
                },
                {
                    "p|proposal_id=",
                    ("[Required] The resource ID of the buyers.proposals resource that is " +
                     "being accepted. This will be used to construct the name used as a path " +
                     "parameter for the proposals.accept request."),
                    p => proposalId = p
                },
                {
                    "r|proposal_revision=",
                    ("The last known revision number of the proposal. If this is less than the ." +
                     "revision number stored server-side, it means that the proposal revision " +
                     "being worked upon is obsolete, and an error message will be returned."),
                    (long? r) => proposalRevision = r
                },
            };

            List<string> extras = options.Parse(exampleArgs);
            var parsedArgs = new Dictionary<string, object>();

            // Show help message.
            if (showHelp == true)
            {
                options.WriteOptionDescriptions(Console.Out);
                Environment.Exit(0);
            }
            // Set optional arguments.
            parsedArgs["account_id"] = accountId;
            parsedArgs["proposal_id"] = proposalId;
            parsedArgs["proposal_revision"] = proposalRevision;
            // Validate that options were set correctly.
            Utilities.ValidateOptions(options, parsedArgs, requiredOptions, extras);

            return parsedArgs;
        }

        /// <summary>
        /// Run the example.
        /// </summary>
        /// <param name="parsedArgs">Parsed arguments for the example.</param>
        protected override void Run(Dictionary<string, object> parsedArgs)
        {
            string accountId = (string) parsedArgs["account_id"];
            string proposalId = (string) parsedArgs["proposal_id"];
            string name = $"buyers/{accountId}/proposals/{proposalId}";

            AcceptProposalRequest acceptProposalRequest = new AcceptProposalRequest()
            {
                ProposalRevision = (long?) parsedArgs["proposal_revision"]
            };

            BuyersResource.ProposalsResource.AcceptRequest request =
                mkService.Buyers.Proposals.Accept(acceptProposalRequest, name);
            Proposal response = null;

            Console.WriteLine("Accepting a proposal with name: {0}", name);

            try
            {
                response = request.Execute();
            }
            catch (Exception exception)
            {
                throw new ApplicationException(
                    $"Marketplace API returned error response:\n{exception.Message}");
            }

            Utilities.PrintProposal(response);
        }
    }
}

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;

import com.google.api.services.authorizedbuyersmarketplace.v1.AuthorizedBuyersMarketplace;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.AcceptProposalRequest;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.Proposal;
import com.google.api.services.samples.authorizedbuyers.marketplace.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;

/**
 * Accepts a proposal for the given account and proposal IDs.
 *
 * <p>Note that a proposal can only be accepted if it is in the BUYER_ACCEPTANCE_REQUESTED state.
 * Once both a buyer and seller have accepted a proposal, its state will change to FINALIZED.
 */
public class AcceptProposals {

  public static void execute(AuthorizedBuyersMarketplace marketplaceClient, Namespace parsedArgs) {
    Long accountId = parsedArgs.getLong("account_id");
    String proposalId = parsedArgs.getString("proposal_id");
    String name = String.format("buyers/%d/proposals/%s", accountId, proposalId);

    AcceptProposalRequest acceptProposalRequest = new AcceptProposalRequest();
    acceptProposalRequest.setProposalRevision(parsedArgs.getLong("proposal_revision"));

    Proposal proposal = null;

    try {
      proposal =
          marketplaceClient.buyers().proposals().accept(name, acceptProposalRequest).execute();
    } catch (IOException ex) {
      System.out.printf("Marketplace API returned error response:%n%s", ex);
      System.exit(1);
    }

    System.out.printf("Accepting proposal with name \"%s\":%n", name);
    Utils.printProposal(proposal);
  }

  public static void main(String[] args) {
    ArgumentParser parser =
        ArgumentParsers.newFor("AcceptProposals")
            .build()
            .defaultHelp(true)
            .description(("Accepts a proposal for the given account and proposal IDs."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource under which the proposal exists. This will "
                + "be used to construct the name used as a path parameter for the proposals.accept "
                + "request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-p", "--proposal_id")
        .help(
            "The resource ID of the buyers.proposals resource that is being accepted. This "
                + "will be used to construct the name used as a path parameter for the "
                + "proposals.accept request.")
        .required(true);
    parser
        .addArgument("-r", "--proposal_revision")
        .help(
            "The last known revision number of the proposal. If this is less than the "
                + "revision number stored server-side, it means that the proposal revision being "
                + "worked upon is obsolete, and an error message will be returned.")
        .required(true)
        .type(Long.class);

    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);
  }
}

Python

#!/usr/bin/python
#
# Copyright 2021 Google Inc. All Rights Reserved.
#
# 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
#
#      http://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.

"""Accepts proposal for the given account and proposal IDs.

Note that a proposal can only be accepted if it is in the
BUYER_ACCEPTANCE_REQUESTED state. Once both a buyer and seller have accepted a
proposal, its state will change to FINALIZED.

If the revision number specified is lower than the latest stored by the API, an
error message will be returned.
"""


import argparse
import os
import pprint
import sys

sys.path.insert(0, os.path.abspath('../../..'))

from googleapiclient.errors import HttpError

import util


_PROPOSALS_NAME_TEMPLATE = 'buyers/%s/proposals/%s'

DEFAULT_BUYER_RESOURCE_ID = 'ENTER_BUYER_RESOURCE_ID_HERE'
DEFAULT_PROPOSAL_RESOURCE_ID = 'ENTER_PROPOSAL_RESOURCE_ID_HERE'


def main(marketplace, args):
    account_id = args.account_id
    proposal_id = args.proposal_id

    body = {
        'proposalRevision': args.proposal_revision
    }

    print(f'Accepting proposal "{proposal_id}" for account "{account_id}":')
    try:
        # Construct and execute the request.
        response = marketplace.buyers().proposals().accept(
            name=_PROPOSALS_NAME_TEMPLATE % (account_id, proposal_id),
            body=body).execute()
    except HttpError as e:
        print(e)
        sys.exit(1)

    pprint.pprint(response)


if __name__ == '__main__':
    try:
        service = util.get_service(version='v1')
    except IOError as ex:
        print(f'Unable to create marketplace service - {ex}')
        print('Did you specify the key file in util.py?')
        sys.exit(1)

    parser = argparse.ArgumentParser(
        description=('Accept a proposal for the given buyer account ID and '
                     'proposal ID at the specified revision.'))
    # Required fields.
    parser.add_argument(
        '-a', '--account_id', default=DEFAULT_BUYER_RESOURCE_ID,
        help=('The resource ID of the buyers resource under which the '
              'proposal was created. This will be used to construct the '
              'name used as a path parameter for the proposals.accept '
              'request.'))
    parser.add_argument(
        '-p', '--proposal_id', default=DEFAULT_PROPOSAL_RESOURCE_ID,
        help=('The resource ID of the buyers.proposals resource for which the '
              'proposal was created. This will be used to construct the '
              'name used as a path parameter for the proposals.accept '
              'request.'))
    parser.add_argument(
        '-r', '--proposal_revision', required=True,
        help=('The last known client revision number of the proposal. If this '
              'is less than the revision number stored server-side, it means '
              'that the proposal revision being worked upon is obsolete, and '
              'an error message will be returned.'))

    main(service, parser.parse_args())

ยกเลิกการเจรจาต่อรอง

คุณสามารถใช้ buyers.proposals.cancelNegotiation วิธีการยกเลิกการเจรจาต่อรองสำหรับข้อเสนอที่กำหนด

หากคุณยกเลิกข้อเสนอที่ยังไม่ได้มีการสรุปผล ค่า state ของข้อเสนอจะตั้งค่าเป็น TERMINATED และการเจรจากับผู้เผยแพร่โฆษณาจะสิ้นสุดลง สิ่งที่จะเกิดขึ้นหากคุณยกเลิกข้อเสนอ ที่มี proposalRevision ที่สรุปผลไปแล้วก่อนหน้านี้ ข้อเสนอจะเปลี่ยนกลับไปเป็น proposalRevision ที่สรุปผลครั้งล่าสุดแทนที่จะสิ้นสุดการใช้งาน

คุณไม่สามารถยกเลิกดีลการประมูลส่วนตัวด้วย Marketplace API คุณสามารถเก็บถาวร ดีลการประมูลส่วนตัวใน UI มาร์เก็ตเพลสของ Authorized Buyers

ตัวอย่างต่อไปนี้แสดงวิธียกเลิกการเจรจาต่อรองข้อเสนอ ด้วยเมธอด cancelNegotiation

REST

ส่งคำขอ

POST https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/proposals/MP14138120:cancelNegotiation?alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

คำตอบ

{
 "name": "buyers/12345678/proposals/MP14138120",
 "updateTime": "2022-03-20T03:08:36.424Z",
 "proposalRevision": "2",
 "dealType": "PROGRAMMATIC_GUARANTEED",
 "displayName": "Test PG Proposal 3",
 "state": "TERMINATED",
 "originatorRole": "BUYER",
 "publisherProfile": "buyers/12345678/publisherProfiles/PP892146",
 "buyer": "buyers/12345678",
 "billedBuyer": "buyers/12345678",
 "sellerContacts": [
   {
     "email": "cindy@garb.com"
   }
 ],
 "buyerContacts": [
   {
     "email": "testemail2022@gmail.com"
   }
 ],
 "lastUpdaterOrCommentorRole": "BUYER",
 "notes": [
   {
     "createTime": "2022-03-20T03:08:36.424Z",
     "creatorRole": "BUYER",
     "note": "Verified that ad sizes are supported."
   }
 ]
}   

C#

/* 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
 *
 *     http://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.
 */

using Google.Apis.AuthorizedBuyersMarketplace.v1;
using Google.Apis.AuthorizedBuyersMarketplace.v1.Data;
using Mono.Options;

using System;
using System.Collections.Generic;

namespace Google.Apis.AuthorizedBuyersMarketplace.Examples.v1.Buyers.Proposals
{
    /// <summary>
    /// Cancels the ongoing negotiation for the specified proposal.
    ///
    /// This method is not supported for proposals including private auction deals because
    /// negotiation for that deal type can not be canceled. On successful cancelation, the
    /// proposal's state will be set to TERMINATED.
    ///
    /// This does not cancel or end serving for deals that have already been finalized. For
    /// finalized deals that are under renegotiation, calling this method will instead reset the
    /// proposal's state to FINALIZED.
    /// </summary>
    public class CancelNegotiationForProposals : ExampleBase
    {
        private AuthorizedBuyersMarketplaceService mkService;

        /// <summary>
        /// Constructor.
        /// </summary>
        public CancelNegotiationForProposals()
        {
            mkService = Utilities.GetAuthorizedBuyersMarketplaceService();
        }

        /// <summary>
        /// Returns a description about the code example.
        /// </summary>
        public override string Description
        {
            get => "This code example cancels negotiaton for a given proposal.";
        }

        /// <summary>
        /// Parse specified arguments.
        /// </summary>
        protected override Dictionary<string, object> ParseArguments(List<string> exampleArgs) {
            string[] requiredOptions = new string[] {"account_id", "proposal_id"};
            bool showHelp = false;

            string accountId = null;
            string proposalId = null;

            OptionSet options = new OptionSet {
                "Cancels negotiation for a proposal with the given account and proposal IDs.",
                {
                    "h|help",
                    "Show help message and exit.",
                    h => showHelp = h != null
                },
                {
                    "a|account_id=",
                    ("[Required] The resource ID of the buyers resource under which the " +
                     "proposal exists. This will be used to construct the name used as a path " +
                     "parameter for the proposals.cancelNegotiation request."),
                    a => accountId = a
                },
                {
                    "p|proposal_id=",
                    ("[Required] The resource ID of the buyers.proposals resource that is " +
                     "being canceled. This will be used to construct the name used as a path " +
                     "parameter for the proposals.cancelNegotiation request."),
                    p => proposalId = p
                }
            };

            List<string> extras = options.Parse(exampleArgs);
            var parsedArgs = new Dictionary<string, object>();

            // Show help message.
            if (showHelp == true)
            {
                options.WriteOptionDescriptions(Console.Out);
                Environment.Exit(0);
            }
            // Set optional arguments.
            parsedArgs["account_id"] = accountId;
            parsedArgs["proposal_id"] = proposalId;
            // Validate that options were set correctly.
            Utilities.ValidateOptions(options, parsedArgs, requiredOptions, extras);

            return parsedArgs;
        }

        /// <summary>
        /// Run the example.
        /// </summary>
        /// <param name="parsedArgs">Parsed arguments for the example.</param>
        protected override void Run(Dictionary<string, object> parsedArgs)
        {
            string accountId = (string) parsedArgs["account_id"];
            string proposalId = (string) parsedArgs["proposal_id"];
            string name = $"buyers/{accountId}/proposals/{proposalId}";

            BuyersResource.ProposalsResource.CancelNegotiationRequest request =
                mkService.Buyers.Proposals.CancelNegotiation(new CancelNegotiationRequest(), name);
            Proposal response = null;

            Console.WriteLine("Canceling negotiation for a proposal with name: {0}", name);

            try
            {
                response = request.Execute();
            }
            catch (Exception exception)
            {
                throw new ApplicationException(
                    $"Marketplace API returned error response:\n{exception.Message}");
            }

            Utilities.PrintProposal(response);
        }
    }
}

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;

import com.google.api.services.authorizedbuyersmarketplace.v1.AuthorizedBuyersMarketplace;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.CancelNegotiationRequest;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.Proposal;
import com.google.api.services.samples.authorizedbuyers.marketplace.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;

/**
 * Cancels the ongoing negotiation for the specified proposal.
 *
 * <p>This method is not supported for proposals including private auction deals because negotiation
 * for that deal type can not be canceled. On successful cancelation, the proposal's state will be
 * set to TERMINATED.
 *
 * <p>This does not cancel or end serving for deals that have already been finalized. For finalized
 * deals that are under renegotiation, calling this method will instead reset the proposal's state
 * to FINALIZED.
 */
public class CancelNegotiationForProposals {

  public static void execute(AuthorizedBuyersMarketplace marketplaceClient, Namespace parsedArgs) {
    Long accountId = parsedArgs.getLong("account_id");
    String proposalId = parsedArgs.getString("proposal_id");
    String name = String.format("buyers/%d/proposals/%s", accountId, proposalId);

    CancelNegotiationRequest cancelNegotiationRequest = new CancelNegotiationRequest();

    Proposal proposal = null;

    try {
      proposal =
          marketplaceClient
              .buyers()
              .proposals()
              .cancelNegotiation(name, cancelNegotiationRequest)
              .execute();
    } catch (IOException ex) {
      System.out.printf("Marketplace API returned error response:%n%s", ex);
      System.exit(1);
    }

    System.out.printf("Canceling negotiation for a proposal with name \"%s\":%n", name);
    Utils.printProposal(proposal);
  }

  public static void main(String[] args) {
    ArgumentParser parser =
        ArgumentParsers.newFor("CancelNegotiationForProposals")
            .build()
            .defaultHelp(true)
            .description(
                ("Cancels negotiation for a proposal with the given account and proposal "
                    + "IDs."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource under which the proposal exists. This will "
                + "be used to construct the name used as a path parameter for the "
                + "proposals.cancelNegotiaton request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-p", "--proposal_id")
        .help(
            "The resource ID of the buyers.proposals resource that is being canceled. This "
                + "will be used to construct the name used as a path parameter for the "
                + "proposals.cancelNegotiation request.")
        .required(true);

    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);
  }
}

Python

#!/usr/bin/python
#
# Copyright 2021 Google Inc. All Rights Reserved.
#
# 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
#
#      http://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.

"""Cancels the ongoing negotiation for the specified proposal.

This method is not supported for proposals including private auction deals
because negotiation for that deal type can not be canceled. On successful
cancelation, the proposal's state will be set to TERMINATED.

This does not cancel or end serving for deals that have already been finalized.
For finalized deals that are under renegotiation, calling this method will
instead reset the proposal's state to FINALIZED.
"""


import argparse
import os
import pprint
import sys

sys.path.insert(0, os.path.abspath('../../..'))

from googleapiclient.errors import HttpError

import util


_PROPOSALS_NAME_TEMPLATE = 'buyers/%s/proposals/%s'

DEFAULT_BUYER_RESOURCE_ID = 'ENTER_BUYER_RESOURCE_ID_HERE'
DEFAULT_PROPOSAL_RESOURCE_ID = 'ENTER_PROPOSAL_RESOURCE_ID_HERE'


def main(marketplace, args):
    proposal_name = _PROPOSALS_NAME_TEMPLATE % (
        args.account_id, args.proposal_id)

    print(f'Canceling negotiation for proposal with name "{proposal_name}":')
    try:
        # Construct and execute the request.
        response = marketplace.buyers().proposals().cancelNegotiation(
            proposal=proposal_name).execute()
    except HttpError as e:
        print(e)
        sys.exit(1)

    pprint.pprint(response)


if __name__ == '__main__':
    try:
        service = util.get_service(version='v1')
    except IOError as ex:
        print(f'Unable to create marketplace service - {ex}')
        print('Did you specify the key file in util.py?')
        sys.exit(1)

    parser = argparse.ArgumentParser(
        description=('Cancel negotiation for a proposal with the given buyer '
                     'account ID and proposal ID.'))
    # Required fields.
    parser.add_argument(
        '-a', '--account_id', default=DEFAULT_BUYER_RESOURCE_ID,
        help=('The resource ID of the buyers resource under which the proposal '
              'was created. This will be used to construct the name used as a '
              'path parameter for the proposals.cancelNegotiation request.'))
    parser.add_argument(
        '-p', '--proposal_id', default=DEFAULT_PROPOSAL_RESOURCE_ID,
        help=('The resource ID of the buyers.proposals resource for which the '
              'proposal was created. This will be used to construct the name '
              'used as a path parameter for the proposals.cancelNegotiation '
              'request.'))

    main(service, parser.parse_args())