Chilkat Online Tools

unicodeC / Salesforce Platform APIs / Create or Update Quote

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "pricingPref": "skip",
    //   "graph": {
    //     "graphId": "refQuoteGraph",
    //     "records": [
    //       {
    //         "referenceId": "refQuote",
    //         "record": {
    //           "attributes": {
    //             "type": "Quote",
    //             "method": "POST"
    //           },
    //           "Name": "Quote_{{$randomCompanyName}}",
    //           "Pricebook2Id": "{{standardPricebook}}"
    //         }
    //       },
    //       {
    //         "referenceId": "refQuoteLineItem1",
    //         "record": {
    //           "attributes": {
    //             "type": "QuoteLineItem",
    //             "method": "POST"
    //           },
    //           "QuoteId": "@{refQuote.id}",
    //           "PricebookEntryId": "{{VirtualRouterTermedPBE}}",
    //           "Product2Id": "{{VirtualRouterProduct}}",
    //           "Quantity": 5.0,
    //           "UnitPrice": 35.0,
    //           "PeriodBoundary": "Anniversary",
    //           "BillingFrequency": "Monthly",
    //           "StartDate": "2023-01-01",
    //           "EndDate": "2024-01-01"
    //         }
    //       },
    //       {
    //         "referenceId": "refQuoteLineItem2",
    //         "record": {
    //           "attributes": {
    //             "type": "QuoteLineItem",
    //             "method": "POST"
    //           },
    //           "QuoteId": "@{refQuote.id}",
    //           "PricebookEntryId": "{{SLABronzeEvergrnMonthPBE}}",
    //           "Product2Id": "{{SLA_BronzeProduct}}",
    //           "Quantity": 1.0,
    //           "UnitPrice": 10.0,
    //           "PeriodBoundary": "DayOfPeriod",
    //           "PeriodBoundaryDay": 4,
    //           "BillingFrequency": "Monthly",
    //           "StartDate": "2023-01-01"
    //         }
    //       }
    //     ]
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"pricingPref",L"skip");
    CkJsonObjectW_UpdateString(json,L"graph.graphId",L"refQuoteGraph");
    CkJsonObjectW_UpdateString(json,L"graph.records[0].referenceId",L"refQuote");
    CkJsonObjectW_UpdateString(json,L"graph.records[0].record.attributes.type",L"Quote");
    CkJsonObjectW_UpdateString(json,L"graph.records[0].record.attributes.method",L"POST");
    CkJsonObjectW_UpdateString(json,L"graph.records[0].record.Name",L"Quote_{{$randomCompanyName}}");
    CkJsonObjectW_UpdateString(json,L"graph.records[0].record.Pricebook2Id",L"{{standardPricebook}}");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].referenceId",L"refQuoteLineItem1");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.attributes.type",L"QuoteLineItem");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.attributes.method",L"POST");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.QuoteId",L"@{refQuote.id}");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.PricebookEntryId",L"{{VirtualRouterTermedPBE}}");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.Product2Id",L"{{VirtualRouterProduct}}");
    CkJsonObjectW_UpdateNumber(json,L"graph.records[1].record.Quantity",L"5.0");
    CkJsonObjectW_UpdateNumber(json,L"graph.records[1].record.UnitPrice",L"35.0");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.PeriodBoundary",L"Anniversary");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.BillingFrequency",L"Monthly");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.StartDate",L"2023-01-01");
    CkJsonObjectW_UpdateString(json,L"graph.records[1].record.EndDate",L"2024-01-01");
    CkJsonObjectW_UpdateString(json,L"graph.records[2].referenceId",L"refQuoteLineItem2");
    CkJsonObjectW_UpdateString(json,L"graph.records[2].record.attributes.type",L"QuoteLineItem");
    CkJsonObjectW_UpdateString(json,L"graph.records[2].record.attributes.method",L"POST");
    CkJsonObjectW_UpdateString(json,L"graph.records[2].record.QuoteId",L"@{refQuote.id}");
    CkJsonObjectW_UpdateString(json,L"graph.records[2].record.PricebookEntryId",L"{{SLABronzeEvergrnMonthPBE}}");
    CkJsonObjectW_UpdateString(json,L"graph.records[2].record.Product2Id",L"{{SLA_BronzeProduct}}");
    CkJsonObjectW_UpdateNumber(json,L"graph.records[2].record.Quantity",L"1.0");
    CkJsonObjectW_UpdateNumber(json,L"graph.records[2].record.UnitPrice",L"10.0");
    CkJsonObjectW_UpdateString(json,L"graph.records[2].record.PeriodBoundary",L"DayOfPeriod");
    CkJsonObjectW_UpdateInt(json,L"graph.records[2].record.PeriodBoundaryDay",4);
    CkJsonObjectW_UpdateString(json,L"graph.records[2].record.BillingFrequency",L"Monthly");
    CkJsonObjectW_UpdateString(json,L"graph.records[2].record.StartDate",L"2023-01-01");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");
    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");

    resp = CkHttpW_PostJson3(http,L"https://domain.com/services/data/v{{version}}/commerce/quotes/actions/place",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "pricingPref": "skip",
    "graph": {
        "graphId": "refQuoteGraph",
        "records": [
            {
                "referenceId": "refQuote",
                "record": {
                    "attributes": {
                        "type": "Quote",
                        "method": "POST"
                    },
                    "Name": "Quote_{{$randomCompanyName}}",
                    "Pricebook2Id": "{{standardPricebook}}"                    
                }
            },
            {
                "referenceId": "refQuoteLineItem1",
                "record": {
                    "attributes": {
                        "type": "QuoteLineItem",
                        "method": "POST"
                    },
                    "QuoteId": "@{refQuote.id}",
                    "PricebookEntryId": "{{VirtualRouterTermedPBE}}",
                    "Product2Id": "{{VirtualRouterProduct}}",
                    "Quantity": 5.0,
                    "UnitPrice": 35.0,
                    "PeriodBoundary": "Anniversary",
                    "BillingFrequency": "Monthly",
                    "StartDate": "2023-01-01",
                    "EndDate": "2024-01-01"                    
                }
            },
            {
                "referenceId": "refQuoteLineItem2",
                "record": {
                    "attributes": {
                        "type": "QuoteLineItem",
                        "method": "POST"
                    },
                    "QuoteId": "@{refQuote.id}",
                    "PricebookEntryId": "{{SLABronzeEvergrnMonthPBE}}",
                    "Product2Id": "{{SLA_BronzeProduct}}",
                    "Quantity": 1.0,
                    "UnitPrice": 10.0,
                    "PeriodBoundary": "DayOfPeriod",
                    "PeriodBoundaryDay": 4,
                    "BillingFrequency": "Monthly",
                    "StartDate": "2023-01-01"
                }
            }

        ]
    }
}'
https://domain.com/services/data/v{{version}}/commerce/quotes/actions/place

Postman Collection Item JSON

{
  "name": "Create or Update Quote",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"pricingPref\": \"skip\",\n    \"graph\": {\n        \"graphId\": \"refQuoteGraph\",\n        \"records\": [\n            {\n                \"referenceId\": \"refQuote\",\n                \"record\": {\n                    \"attributes\": {\n                        \"type\": \"Quote\",\n                        \"method\": \"POST\"\n                    },\n                    \"Name\": \"Quote_{{$randomCompanyName}}\",\n                    \"Pricebook2Id\": \"{{standardPricebook}}\"                    \n                }\n            },\n            {\n                \"referenceId\": \"refQuoteLineItem1\",\n                \"record\": {\n                    \"attributes\": {\n                        \"type\": \"QuoteLineItem\",\n                        \"method\": \"POST\"\n                    },\n                    \"QuoteId\": \"@{refQuote.id}\",\n                    \"PricebookEntryId\": \"{{VirtualRouterTermedPBE}}\",\n                    \"Product2Id\": \"{{VirtualRouterProduct}}\",\n                    \"Quantity\": 5.0,\n                    \"UnitPrice\": 35.0,\n                    \"PeriodBoundary\": \"Anniversary\",\n                    \"BillingFrequency\": \"Monthly\",\n                    \"StartDate\": \"2023-01-01\",\n                    \"EndDate\": \"2024-01-01\"                    \n                }\n            },\n            {\n                \"referenceId\": \"refQuoteLineItem2\",\n                \"record\": {\n                    \"attributes\": {\n                        \"type\": \"QuoteLineItem\",\n                        \"method\": \"POST\"\n                    },\n                    \"QuoteId\": \"@{refQuote.id}\",\n                    \"PricebookEntryId\": \"{{SLABronzeEvergrnMonthPBE}}\",\n                    \"Product2Id\": \"{{SLA_BronzeProduct}}\",\n                    \"Quantity\": 1.0,\n                    \"UnitPrice\": 10.0,\n                    \"PeriodBoundary\": \"DayOfPeriod\",\n                    \"PeriodBoundaryDay\": 4,\n                    \"BillingFrequency\": \"Monthly\",\n                    \"StartDate\": \"2023-01-01\"\n                }\n            }\n\n        ]\n    }\n}"
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/commerce/quotes/actions/place",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "commerce",
        "quotes",
        "actions",
        "place"
      ]
    },
    "description": "This example creates a quote for the following products.\n\n- 5 Virtual Routers sold on a 1-year termed subscription at $35/item\n- 1 Bronze Service Level Agreement sold on an evergreen subscription at $10/month\n    \n\nSee [place quote](https://developer.salesforce.com/docs/revenue/subscription-management/references/quotes?meta=Create+or+update+a+quote+with+place+quote)."
  },
  "response": [
  ]
}