forcedotcom / postman-salesforce-apis

Salesforce API Postman Collection
Creative Commons Zero v1.0 Universal
1.06k stars 638 forks source link

Making CPQ API JSON response pretty / readable #66

Open inspired27 opened 1 year ago

inspired27 commented 1 year ago

Hi,

Thanks for providing this repo and the Salesforce API's. Is there any way to make the Salesforce API JSON response pretty, I have read a quote with MDQ segments etc using Read API and there a lot in the JSON however not matter which viewer I use it does not format it in a pretty readable way it is hard to understand:

Example of the output not matter what viewer I try , ugly:

{"saver": "SBQQ.QuoteAPI.QuoteSaver", "model": "{\"ui_original_record\":{\"cloneRecordIfNoCache\":true,\"cacheName\":\"LineEditor\",\"cacheId\":\"a0q5i000001ChPBAA0\",\"cachedOriginalRecordPath\":[\"quote\",\"ui_original_record\"]},\"record\":{\"attributes\":{\"type\":\"SBQQQuotec\",\"url\":\"/services/data/v57.0/sobjects/SBQQQuotec/a0q5i000001ChPBAA0\"},\"Id\":\"a0q5i000001ChPBAA0\",\"Name\":\"Q-00057\",\"SBQQTypec\":\"Quote\",\"SBQQAccountc\":\"0015i00000dW4DHAA0\",\"SBQQSubscriptionTermc\":12,\"SBQQExpirationDatec\":\"2023-05-24\",\"SBQQStartDatec\":\"2023-05-01\",\"SBQQEndDatec\":\"2025-04-30\",\"SBQQNetAmountc\":0.00,\"SBQQCustomerAmountc\":0.00,\"SBQQPricebookIdc\":\"01s5i00000F5PMcAAN\",\"SBQQContractingMethodc\":\"By Subscription End Date\",\"SBQQUnopenedc\":false,\"SBQQLineItemCountc\":16,\"SBQQPaymentTermsc\":\"Net 30\",\"SBQQWatermarkShownc\":false,\"SBQQStatusc\":\"Draft\",\"SBQQPrimaryc\":false,\"SBQQLineItemsGroupedc\":false,\"SBQQOpportunity2c\":\"0065i00000CtPCuAAN\",\"SBQQAccountr\":{\"attributes\":{\"type\":\"Account\",\"url\":\"/services/data/v57.0/sobjects/Account/0015i00000dW4DHAA0\"},\"Id\":\"0015i00000dW4DHAA0\",\"Name\":\"Energy Customer 1\",\"SBQQRenewalModelc\":\"Contract Based\",\"SBQQRenewalPricingMethodc\":\"Same\"},\"SBQQOpportunity2r\":{\"attributes\":{\"type\":\"Opportunity\",\"url\":\"/services/data/v57.0/sobjects/Opportunity/0065i00000CtPCuAAN\"},\"Id\":\"0065i00000CtPCuAAN\",\"Pricebook2Id\":\"01s5i00000F5PMcAAN\",\"AccountId\":\"0015i00000dW4DHAA0\"},\"SBQQCustomerDiscountc\":null,\"SBQQMarkupRatec\":null,\"SBQQPartnerDiscountc\":null,\"SBQQMasterContractc\":null,\"SBQQMasterEvergreenContractc\":null,\"SBQQQuoteProcessIdc\":null,\"SBQQDistributorDiscountc\":null,\"SBQQFirstSegmentTermEndDatec\":null,\"SBQQGenerateContractedPricec\":null,\"SBQQBillingFrequencyc\":null,\"SBQQRenewalTermc\":null,\"SBQQRenewalUpliftRatec\":null,\"SBQQOrderGroupIDc\":null,\"SBQQTargetCustomerAmountc\":null,\"SBQQOrderByc\":null,\"SBQQProrationDayOfMonthc\":null},\"nextKey\":17,\"netTotal\":0.00,\"netNonSegmentTotal\":0.0,\"lineItems\":[{\"upliftable\":false,\"upgradeSourcesBySourceProductId\":{},\"ui_original_record\":{\"cloneRecordIfNoCache\":false,\"cacheName\":\"LineEditor\",\"cacheId\":\"a0q5i000001ChPBAA0\",\"cachedOriginalRecordPath\":[\"quote\",\"lineItems\",\"0\",\"ui_original_record\"]},\"record\":{\"attributes\":{\"type\":\"SBQQQuoteLinec\",\"url\":\"/services/data/v57.0/sobjects/SBQQQuoteLinec/a0m5i000001CWMIAA4\"},\"Id\":\"a0m5i000001CWMIAA4\",\"SBQQQuotec\":\"a0q5i000001ChPBAA0\",\"SBQQProductc\":\"01t5i000005LoM6AAK\",\"SBQQNumberc\":1,\"SBQQSegmentIndexc\":1,\"SBQQSegmentLabelc\":\"Quarter 1\",\"SBQQSegmentKeyc\":\"1682597119806\",\"SBQQDimensionc\":\"a0C5i000009BWHpEAO\",\"SBQQPricebookEntryIdc\":\"01u5i000004t6OKAAY\",\"SBQQHasConsumptionSchedulec\":false,\"SBQQHiddenc\":false,\"SBQQTaxablec\":false,\"SBQQSubscriptionPricingc\":\"Fixed Price\",\"SBQQDefaultSubscriptionTermc\":3,\"SBQQSubscriptionBasec\":\"List\",\"SBQQSubscriptionScopec\":\"Quote\",\"SBQQProductSubscriptionTypec\":\"Renewable\",\"SBQQSubscriptionTypec\":\"Renewable\",\"SBQQEndDatec\":\"2023-07-31\",\"Name\":\"QL-0000369\",\"SBQQAdditionalDiscountc\":0.00,\"SBQQBundledc\":false,\"SBQQComponentDiscountedByPackagec\":false,\"SBQQCostEditablec\":true,\"SBQQCustomerPricec\":0.00,\"SBQQEffectiveSubscriptionTermc\":12,\"SBQQListPricec\":9.99,\"SBQQOriginalPricec\":0.00,\"SBQQNetPricec\":0.00,\"SBQQNetTotalc\":0.00,\"SBQQNonDiscountablec\":true,\"SBQQNonPartnerDiscountablec\":false,\"SBQQOptionalc\":false,\"SBQQBundlec\":false,\"SBQQPartnerPricec\":0.00,\"SBQQPriceEditablec\":true,\"SBQQProratedListPricec\":0.00,\"SBQQPricingMethodc\":\"List\",\"SBQQPricingMethodEditablec\":true,\"SBQQProrateMultiplierc\":1.0000,\"SBQQQuantityc\":1.00,\"SBQQSpecialPricec\":0.00,\"SBQQStartDatec\":\"2023-05-01\",\"SBQQRenewalc\":false,\"SBQQProratedPricec\":0.00,\"SBQQUpliftc\":0.00,\"SBQQUpliftAmountc\":0.00,\"SBQQComponentUpliftedByPackagec\":false,\"SBQQProductNamec\":\"Energy - Peak - Qtrly\",\"SBQQExistingc\":false,\"SBQQCarryoverLinec\":false,\"SBQQAllowAssetRefundc\":false,\"SBQQRegularPricec\":69.00,\"Original_Price_Formulac\":0.00,\"Special_Price_Formulac\":0.00,\"SBQQMarkupc\":0.00,\"SBQQEffectiveQuantityc\":1.00,\"SBQQDimensionr\":{\"attributes\":{\"type\":\"SBQQDimensionc\",\"url\":\"/services/data/v57.0/sobjects/SBQQDimensionc/a0C5i000009BWHpEAO\"},\"Id\":\"a0C5i000009BWHpEAO\",\"SBQQTypec\":\"Quarter\",\"SBQQQuantityEditablec\":\"Yes\"},\"SBQQProductr\":{\"attributes\":{\"type\":\"Product2\",\"url\":\"/services/data/v57.0/sobjects/Product2/01t5i000005LoM6AAK\"},\"Id\":\"01t5i000005LoM6AAK\",\"Name\":\"Energy - Peak - Qtrly\",\"SBQQSubscriptionPricingc\":\"Fixed Price\",\"SBQQPriceEditablec\":true,\"SBQQDefaultQuantityc\":1.00000,\"SBQQQuantityEditablec\":true,\"SBQQCostEditablec\":true,\"SBQQNonDiscountablec\":true,\"SBQQNonPartnerDiscountablec\":false,\"SBQQSubscriptionTermc\":3,\"SBQQSubscriptionBasec\":\"List\",\"SBQQPricingMethodc\":\"List\",\"SBQQPricingMethodEditablec\":true,\"SBQQOptionSelectionMethodc\":\"Click\",\"SBQQOptionalc\":false,\"SBQQTaxablec\":false,\"SBQQCustomConfigurationRequiredc\":false,\"SBQQHiddenc\":false,\"SBQQReconfigurationDisabledc\":false,\"SBQQExcludeFromOpportunityc\":false,\"SBQQDescriptionLockedc\":false,\"SBQQExcludeFromMaintenancec\":false,\"SBQQIncludeInMaintenancec\":false,\"SBQQNewQuoteGroupc\":false,\"SBQQSubscriptionTypec\":\"Renewable\",\"SBQQAssetConversionc\":\"One per quote line\",\"SBQQBlockPricingFieldc\":\"Quantity\",\"SBQQHasConfigurationAttributesc\":false,\"SBQQHasConsumptionSchedulec\":false,\"SBQQDefaultPricingTablec\":\"Segmented\",\"SBQQExternallyConfigurablec\":false,\"SBQQAssetAmendmentBehaviorc\":\"Default\",\"SBQQDimensionsr\":{\"totalSize\":1,\"done\":true,\"records\":[{\"attributes\":{\"type\":\"SBQQDimensionc\",\"url\":\"/services/data/v57.0/sobjects/SBQQDimensionc/a0C5i000009BWHpEAO\"},\"SBQQProductc\":\"01t5i000005LoM6AAK\",\"Id\":\"a0C5i000009BWHpEAO\",\"OwnerId\":\"0055i000007XncYAAS\",\"IsDeleted\":false,\"Name\":\"Quarterly Pricing\",\"CreatedDate\":\"2023-04-27T01:07:01.000+0000\",

pozil commented 1 year ago

Hi @crazyfrog-github, there's a Postman feature for formatting the JSON output of the response. Have you tried to open the Pretty tab in the response view? Screenshot 2023-04-28 at 10 26 02

inspired27 commented 1 year ago

Hi,

Yes very first thing but it still looks terrible nothing like the pretty JSON you have above:

image

pozil commented 1 year ago

Oh wow, looking at the body of your response I can see that it's not JSON, it's a string that contains JSON (see the first double quote). That's why the Postman parser can't handle it.

What's the Content-Type header value for the response?

For the record, I'm not familiar with CPQ but I'll try to help.

inspired27 commented 1 year ago

G'day Philippe,

Below are the details, requested with response info. What is so special about the quote API that makes it come back ugly, any help to make it pretty and understandable would be great.

Response Headers:

@.***

Response Body:

@.***

From: Philippe Ozil @.> Sent: Friday, 28 April 2023 7:24 PM To: forcedotcom/postman-salesforce-apis @.> Cc: crazyfrog-github @.>; Mention @.> Subject: Re: [forcedotcom/postman-salesforce-apis] Making CPQ API JSON response pretty / readable (Issue #66)

Oh wow, looking at the body of your response I can see that it's not JSON, it's a string that contains JSON (see the first double quote). That's why the Postman parser can't handle it.

What's the Content-Type header value for the response?

For the record, I'm not familiar with CPQ but I'll try to help.

- Reply to this email directly, view it on GitHubhttps://github.com/forcedotcom/postman-salesforce-apis/issues/66#issuecomment-1527258235, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AICL2BMAYX3BCETMA6H6LK3XDOEDNANCNFSM6AAAAAAXO5BMAE. You are receiving this because you were mentioned.Message ID: @.**@.>>

inspired27 commented 1 year ago

Hi,

Sorry not sure what happened but the images of postman headers did not save. Hopefully you can see the Content-Type header now, attached again: image001 image002

pozil commented 1 year ago

It really looks like a bug on the server side to me. Despite the response header saying that this is JSON, you can see that this is a String with escaped JSON (you can see the escaped inner quotes \"). The problem isn't Postman here, it's the response format sent by the server. I believe that the response data was JSON-encoded twice.

You can reproduce a similar pattern with this code

Account a = new Account(Name='test account');
String json = JSON.serialize(a);
String doubleEncoded = JSON.serialize(json);
System.debug(doubleEncoded);

This outputs a string which wouldn't be properly formatted:

"{\"attributes\":{\"type\":\"Account\"},\"Name\":\"test account\"}"
inspired27 commented 1 year ago

Thanks, if you use the read product CPQ API do you get the same response JSON encoded twice?

pozil commented 1 year ago

I don't have access to a CPQ environment but I'll ask around if I can find someone who can chime in.