Chỉnh sửa đề xuất

Bạn có thể sử dụng các phương thức sau để chỉnh sửa đề xuất hiện có cho tài khoản người mua và bất kỳ khách hàng nào của bạn.

Bản vá

Bạn có thể sử dụng phương thức buyers.proposals.patch để cập nhật một đề xuất nhất định.

Bạn có thể sử dụng phương thức này để thay đổi đề xuất trong quá trình thương lượng hoặc bắt đầu thương lượng lại một đề xuất đã hoàn tất.

Bạn không thể thay đổi trạng thái của đề xuất bằng patch.

Hãy xem những cách khác để sửa đổi đề xuất:

Mẫu sau đây minh hoạ cách bạn có thể cập nhật một đề xuất bằng phương thức patch.

REST

Yêu cầu

PATCH https://authorizedbuyersmarketplace.googleapis.com/v1/buyers/12345678/proposals/MP49876074?updateMask=buyerPrivateData.referenceId&alt=json
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
 "proposalRevision": "1",
 "buyerPrivateData": {
   "referenceId": "2f5e9550-8d22-495e-ba38-9b9496347a3b"
 }
}

Phản hồi

{
 "name": "buyers/12345678/proposals/MP49876074",
 "updateTime": "2022-03-26T04:03:19.282Z",
 "proposalRevision": "2",
 "dealType": "PROGRAMMATIC_GUARANTEED",
 "displayName": "Test PG Proposal #0ce643e9-5518-4e8e-b352-0cb45cc2eeb2",
 "state": "SELLER_REVIEW_REQUESTED",
 "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",
 "notes": [
   {
     "createTime": "2022-03-26T04:03:19.548Z",
     "creatorRole": "BUYER",
     "note": "Test programmatic guaranteed deal proposal."
   }
 ]
}

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.PrivateData;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.Proposal;
import com.google.api.services.samples.authorizedbuyers.marketplace.v1.Utils;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.UUID;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;

/**
 * Patches a specified proposal at the given revision number.
 *
 * <p>Fields that can be patched for this resource can be found in the reference documentation:
 * https://developers.google.com/authorized-buyers/apis/marketplace/reference/rest/v1/buyers.proposals
 *
 * <p>Note: If the revision number is lower than what is stored for the proposal server-side, the
 * operation will be deemed obsolete and an error will be returned.
 *
 * <p>Only proposals for preferred and programmatic guaranteed deals can be modified by buyers.
 */
public class PatchProposals {

  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);
    Long proposalRevision = parsedArgs.getLong("proposal_revision");

    PrivateData buyerPrivateData = new PrivateData();
    buyerPrivateData.setReferenceId(
        String.format("Marketplace-Java-Sample-Reference-%s", UUID.randomUUID()));

    Proposal patchedProposal = new Proposal();
    patchedProposal.setProposalRevision(proposalRevision);
    patchedProposal.setBuyerPrivateData(buyerPrivateData);

    String updateMask = "buyerPrivateData.referenceId";

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

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

  public static void main(String[] args) {
    ArgumentParser parser =
        ArgumentParsers.newFor("PatchProposals")
            .build()
            .defaultHelp(true)
            .description(("Patches a proposal at the given revision number."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource for which the RFP is being patched. This "
                + "will be used to construct the name used as a path parameter for the "
                + "proposals.patch request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-p", "--proposal_id")
        .help(
            "The resource ID of the proposals resource that is being patched. This will be used to"
                + " construct the name used as a path parameter for the proposals.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);

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

Thêm ghi chú

Bạn có thể dùng buyers.proposals.addNote để thêm ghi chú vào đề xuất.

Khi bạn thêm ghi chú vào một đề xuất, ghi chú đó sẽ được lưu trữ trong trường notes của đề xuất. Nhà xuất bản có thể xem được ghi chú. Bạn nên sử dụng trường notes để liên hệ với nhà xuất bản trong quá trình thương lượng.

Mẫu sau đây minh hoạ cách bạn có thể thêm ghi chú vào một đề xuất bằng phương thức addNote.

REST

Yêu cầu

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

{
 "note": {
   "note": "Test note."
 }
}

Phản hồi

{
 "name": "buyers/12345678/proposals/MP49876074",
 "updateTime": "2022-03-26T04:03:19.282Z",
 "proposalRevision": "2",
 "dealType": "PROGRAMMATIC_GUARANTEED",
 "displayName": "Test PG Proposal #0ce643e9-5518-4e8e-b352-0cb45cc2eeb2",
 "state": "SELLER_REVIEW_REQUESTED",
 "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",
 "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."
   }
 ]
}

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.AddNoteRequest;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.Note;
import com.google.api.services.authorizedbuyersmarketplace.v1.model.Proposal;
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;

/** Adds a note to a given proposal. */
public class AddNoteToProposals {

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

    Note note = new Note();
    note.setNote(noteValue);

    AddNoteRequest addNoteRequest = new AddNoteRequest();
    addNoteRequest.setNote(note);

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

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

  public static void main(String[] args) {
    ArgumentParser parser =
        ArgumentParsers.newFor("AddNoteToProposals")
            .build()
            .defaultHelp(true)
            .description(("Adds a note to a given proposal."));
    parser
        .addArgument("-a", "--account_id")
        .help(
            "The resource ID of the buyers resource under which the proposal is being "
                + "accessed. This will be used to construct the proposal name used as a path "
                + "parameter for the proposals.addNote request.")
        .required(true)
        .type(Long.class);
    parser
        .addArgument("-p", "--proposal_id")
        .help(
            "The resource ID of the proposals resource that a note is being added to. This "
                + "will be used to construct the name used as a path parameter for the "
                + "proposals.addNote request.")
        .required(true)
        .type(String.class);
    parser
        .addArgument("-n", "--note")
        .help("The note to be added to the proposal.")
        .type(String.class)
        .setDefault("Created note from Java sample.");

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