Lab - Postman Quote Workflow
Introduction
In this lab, you’ll explore the common storefront tasks involved with managing and submitting quotes. This will also give you an opportunity to observe the impact that different user roles have on GraphQL results.
Prerequisites
- A BigCommerce sandbox store or trial store, or a full production store
- B2B Edition enabled in your store
- Postman or a similar API client
- An existing Postman environment, collection, and headers preset as configured in previous labs
- Minimal quote/payment settings as described below
In this lab, you will:
- Create API requests to handle quote submission, management, and conversion
- Implement Postman scripts to automate values used in API requests
- Practice sending quote-related requests from the perspective of users with different roles/permissions
Required Quote/Payment Settings
The lab will involve logging into your storefront as a company user to place an order from a quote. The following minimal settings are required in the B2B Edition section of your control panel:
- In Settings > General, “Quotes” must be checked under “Feature Management.”
- In Settings > Quotes, “Allow Quote Request for” should have “Company user” checked, and “Enable add to quote button” should be checked.
- In Settings > Checkout, the “Purchase Order Payment Method” should be enabled.
- The Payments settings for the company you will use for the storefront must not have been customized to exclude “PO” as an available payment option.
Postman Recap
As a reminder, in previous labs you should have set up these collection variables:
admin_emailadmin_passwordjunior_emailjunior_password
Make sure these variables are set with valid credentials values. You’ll need the “Admin Login” and “Junior Login” requests that you previously created.
Step 1: Fetch Currency Details
- Create a new HTTP request and save it to your collection with the name “Get Currencies.”
- Set the same configuration that was used for the previous requests, including the HTTP method, URL, Auth Type, Headers (using your previously created “GraphQL” preset), and Body type.
- Enter the following query.
- Enter the following in the GraphQL Variables panel.
- In the Scripts tab, enter the following “Post-response” code.
These tests verify not only that currency information was returned in the proper format, but also that the currency identified as the channel’s default is specifically present.
- Enter the following code immediately after the previous Post-response code.
There are quite a lot of values being captured in Postman collection variables here, but all will be needed when submitting a quote. This script ensures that the values matching the storefront’s default currency are automatically captured.
- Send the request and verify that all tests succeed.
- Verify that collection variables have been set for all currency details.
Step 2: Fetch Product Details
In order to submit a quote request for specific products from your storefront, you’ll need catalog details like product and variant IDs, as well as product prices. In this section, you’ll utilize the productsSearch query to capture these details. Automation utilizing Postman scripts will assist in translating the appropriate values from the product data into the eventual quote request.
You’ll perform this and subsequent requests from the context of your Junior Buyer user, as this role has permission to submit quotes.
- Re-run the “Junior Buyer Login” request to regenerate your GraphQL authentication token and other details.
- Verify that the
b2b_logged_in_emailvariable on your environment reflects the Junior Buyer email address. - If the
b2b_logged_in_company_idvariable is not set in your environment, or the company ID doesn’t match your Junior Buyer user, re-run the “User Company” request.
Now that you’ve authenticated as a Junior Buyer, let’s set up the request to fetch product details. For the workflow you’ll be setting up, you’ll choose two products from your store catalog to be part of the quote.
- Log in to your BigCommerce control panel and navigate to Products.
- Record the IDs of your two chosen products. The IDs can be found in the URL path of an individual product edit page, which is in the format
/manage/products/edit/{product-id}.
If possible, include a product with variants as one of your IDs, as you’ll be able to observe the effects of the quote process with such a product.
- Create a new HTTP request and save it to your collection with the name “Search Products.”
- Set the same configuration that was used for the previous requests, including the HTTP method, URL, Auth Type, Headers (using your previously created “GraphQL” preset), and Body type.
- Enter the following query.
- Enter the following in the GraphQL Variables panel.
- Replace
<Product 1 ID>and<Product 2 ID>with the IDs of your chosen products. For example,[13, 27]. - In the Scripts tab, enter the following “Post-response” code.
Observe in the script that the numberOfProducts variable controls the test that verifies the proper number of products were returned (2). The productQty variable will also be used as a multiplier for product prices; we’ll eventually be including 10 of each product in the quote request.
The request submitting the quote will be specifically configured for two products and a quantity of 10 for each, but if you choose to change the details of that request, you can easily update the above variables to make sure productsSearch captures the right info.
The script tests that the values you intend to capture are present on each product and compiles that data into a new array. Notice that some values are captured from the product record, while others are captured from the product’s first available variant.
- Enter the following code immediately after the previous Post-response code.
The final portion of the post-response script captures the required values for each product in collection variables - for example, product1_id, product1_price, etc. The full expected price of the initial quote request (based on a quantity of 10 of each product) is also captured.
- Send the request and verify that all tests succeed.
- Verify that collection variables have been set for the product ID, SKU, price, variant ID, image URL, and name of each of your products.
The product details you’ve captured can now be fed directly into the request to submit the quote.
Step 3: Submit the Quote Request
- Create a new HTTP request and save it to your collection with the name “Create Quote.”
- Set the same configuration that was used for the previous requests, including the HTTP method, URL, Auth Type, Headers (using your previously created “GraphQL” preset), and Body type.
- Enter the following query.
- Enter the following in the GraphQL Variables panel.
Note that the collection variables you’ve captured with your previous requests are being used to populate the appropriate GraphQL variables related to currency, product details and pricing.
In this request, we’re providing a value for channelId, which is not required if your store does not support multiple storefronts. If multiple storefronts are supported, however, this field is necessary even if one storefront is designated as default.
- In the Scripts tab, enter the following “Post-response” code.
The ID of the newly created quote, as well as its “created at” timestamp, are captured in collection variables to automatically tie subsequent requests to the most recently created quote.
- Send the request, verify that all tests succeed, and verify that the
quote_idandquote_created_atvariables are set on your collection.
You should also be able to see your new quote in the B2B Edition admin, or in the storefront while logged in as one of the company’s users.
At this step, you may choose to edit the quote in the B2B Edition admin - for example, to set a discount on one or more items in the quote. (Be sure to “Preview” and then “Submit” the quote.) A typical workflow would involve a sales rep making such edits before the next steps in the quote process.
While editing the quote, also try including a message for the buyer.
Step 4: Get Quotes
Now you’ll make a storefront request to fetch all the quotes belonging to your company.
- Create a new HTTP request and save it to your collection with the name “Get Quotes.”
- Set the same configuration that was used for the previous requests, including the HTTP method, URL, Auth Type, Headers (using your previously created “GraphQL” preset), and Body type.
- Enter the following query.
- Enter the following in the GraphQL Variables panel.
Like in previous requests, the arguments and variables here are designed to easily facilitate pagination once the company has multiple quotes. The “-createdAt” value being passed in for orderBy ensures the quotes will be sorted in descending order by the creation date.
- In the Scripts tab, enter the following “Post-response” code.
- Send the request and verify that all tests succeed.
As you’re sorting by creation date, the quote you previously created should be first in the results.
If you edited the quote from the perspective of a sales rep, observe the effects in the trackingHistory field and the various price fields that reflect any new discounts.
Step 5: Export a Quote PDF
- Create a new HTTP request and save it to your collection with the name “Export Quote PDF.”
- Set the same configuration that was used for the previous requests, including the HTTP method, URL, Auth Type, Headers (using your previously created “GraphQL” preset), and Body type.
- Enter the following query.
- Enter the following in the GraphQL Variables panel.
Note that you’re passing in the collection variables that previously captured the quote ID and “created at” timestamp, meaning you’ll automatically be exporting a PDF for the most recently created quote. Feel free to manually change these values in the collection.
- In the Scripts tab, enter the following “Post-response” code.
- Send the request and verify that all tests succeed.
- Copy the URL value from the response and enter it in a browser to verify that the URL results in downloading a PDF with the details of the quote.
Step 6: Submit a Quote Message
- Create a new HTTP request and save it to your collection with the name “Add Message to Quote.”
- Set the same configuration that was used for the previous requests, including the HTTP method, URL, Auth Type, Headers (using your previously created “GraphQL” preset), and Body type.
- Enter the following query.
- Enter the following in the GraphQL Variables panel.
- In the Scripts tab, enter the following “Post-response” code.
- Send the request and verify that all tests succeed.
Step 7: Check Out from a Quote
The most critical step of the quoting process from the storefront perspective is actually placing an order from the quote details. Let’s practice generating the appropriate URL that will allow a storefront user to complete this process in the BigCommerce checkout.
- Create a new HTTP request and save it to your collection with the name “Get Quote Checkout.”
- Set the same configuration that was used for the previous requests, including the HTTP method, URL, Auth Type, Headers (using your previously created “GraphQL” preset), and Body type.
- Enter the following query.
- Enter the following in the GraphQL Variables panel.
- In the Scripts tab, enter the following “Post-response” code.
Your request is fully configured. However, recall that you most recently used the “Junior Buyer Login” request to generate the GraphQL credentials you’ve been using in the quote creation process, and users with the Junior Buyer role do not have permission to place an order from a quote. Presuming your user’s role hasn’t been changed, you should be able to observe that the “Get Quote Checkout” requests fails with your current authentication.
- Send the request and verify that you receive a “Permission denied” error in the response.
Generating the checkout URL successfully should be as easy as re-authenticating as a user with sufficient permissions.
- Re-run the “Admin Login” request.
- Re-run the “Get Quote Checkout” request and verify that all tests succeed this time.
- Log in to your storefront as a Senior Buyer or Admin user with the company associated with the quote.
- Copy the
checkoutUrlfrom the response and enter it in a browser to verify that the checkout is initiated. - Complete the checkout and place an order from the quote, using the Purchase Order payment method.
The invoice workflow you’ll examine in the next lab is usually relevant for orders that have been paid with credit, so using the Purchase Order payment method will make sure you have an order that makes sense for that workflow.
Taking It Further
Try out implementing a “Get Quote” request to fetch the details of a single quote using the quote GraphQL query. Configure the request to utilize your quote_id and quote_created_at collection variables to automatically fetch the most recently created quote.