Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making CPQ API JSON response pretty / readable #66

Open
inspired27 opened this issue Apr 28, 2023 · 8 comments
Open

Making CPQ API JSON response pretty / readable #66

inspired27 opened this issue Apr 28, 2023 · 8 comments

Comments

@inspired27
Copy link

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":"SBQQ__Quote__c","url":"/services/data/v57.0/sobjects/SBQQ__Quote__c/a0q5i000001ChPBAA0"},"Id":"a0q5i000001ChPBAA0","Name":"Q-00057","SBQQ__Type__c":"Quote","SBQQ__Account__c":"0015i00000dW4DHAA0","SBQQ__SubscriptionTerm__c":12,"SBQQ__ExpirationDate__c":"2023-05-24","SBQQ__StartDate__c":"2023-05-01","SBQQ__EndDate__c":"2025-04-30","SBQQ__NetAmount__c":0.00,"SBQQ__CustomerAmount__c":0.00,"SBQQ__PricebookId__c":"01s5i00000F5PMcAAN","SBQQ__ContractingMethod__c":"By Subscription End Date","SBQQ__Unopened__c":false,"SBQQ__LineItemCount__c":16,"SBQQ__PaymentTerms__c":"Net 30","SBQQ__WatermarkShown__c":false,"SBQQ__Status__c":"Draft","SBQQ__Primary__c":false,"SBQQ__LineItemsGrouped__c":false,"SBQQ__Opportunity2__c":"0065i00000CtPCuAAN","SBQQ__Account__r":{"attributes":{"type":"Account","url":"/services/data/v57.0/sobjects/Account/0015i00000dW4DHAA0"},"Id":"0015i00000dW4DHAA0","Name":"Energy Customer 1","SBQQ__RenewalModel__c":"Contract Based","SBQQ__RenewalPricingMethod__c":"Same"},"SBQQ__Opportunity2__r":{"attributes":{"type":"Opportunity","url":"/services/data/v57.0/sobjects/Opportunity/0065i00000CtPCuAAN"},"Id":"0065i00000CtPCuAAN","Pricebook2Id":"01s5i00000F5PMcAAN","AccountId":"0015i00000dW4DHAA0"},"SBQQ__CustomerDiscount__c":null,"SBQQ__MarkupRate__c":null,"SBQQ__PartnerDiscount__c":null,"SBQQ__MasterContract__c":null,"SBQQ__MasterEvergreenContract__c":null,"SBQQ__QuoteProcessId__c":null,"SBQQ__DistributorDiscount__c":null,"SBQQ__FirstSegmentTermEndDate__c":null,"SBQQ__GenerateContractedPrice__c":null,"SBQQ__BillingFrequency__c":null,"SBQQ__RenewalTerm__c":null,"SBQQ__RenewalUpliftRate__c":null,"SBQQ__OrderGroupID__c":null,"SBQQ__TargetCustomerAmount__c":null,"SBQQ__OrderBy__c":null,"SBQQ__ProrationDayOfMonth__c":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":"SBQQ__QuoteLine__c","url":"/services/data/v57.0/sobjects/SBQQ__QuoteLine__c/a0m5i000001CWMIAA4"},"Id":"a0m5i000001CWMIAA4","SBQQ__Quote__c":"a0q5i000001ChPBAA0","SBQQ__Product__c":"01t5i000005LoM6AAK","SBQQ__Number__c":1,"SBQQ__SegmentIndex__c":1,"SBQQ__SegmentLabel__c":"Quarter 1","SBQQ__SegmentKey__c":"1682597119806","SBQQ__Dimension__c":"a0C5i000009BWHpEAO","SBQQ__PricebookEntryId__c":"01u5i000004t6OKAAY","SBQQ__HasConsumptionSchedule__c":false,"SBQQ__Hidden__c":false,"SBQQ__Taxable__c":false,"SBQQ__SubscriptionPricing__c":"Fixed Price","SBQQ__DefaultSubscriptionTerm__c":3,"SBQQ__SubscriptionBase__c":"List","SBQQ__SubscriptionScope__c":"Quote","SBQQ__ProductSubscriptionType__c":"Renewable","SBQQ__SubscriptionType__c":"Renewable","SBQQ__EndDate__c":"2023-07-31","Name":"QL-0000369","SBQQ__AdditionalDiscount__c":0.00,"SBQQ__Bundled__c":false,"SBQQ__ComponentDiscountedByPackage__c":false,"SBQQ__CostEditable__c":true,"SBQQ__CustomerPrice__c":0.00,"SBQQ__EffectiveSubscriptionTerm__c":12,"SBQQ__ListPrice__c":9.99,"SBQQ__OriginalPrice__c":0.00,"SBQQ__NetPrice__c":0.00,"SBQQ__NetTotal__c":0.00,"SBQQ__NonDiscountable__c":true,"SBQQ__NonPartnerDiscountable__c":false,"SBQQ__Optional__c":false,"SBQQ__Bundle__c":false,"SBQQ__PartnerPrice__c":0.00,"SBQQ__PriceEditable__c":true,"SBQQ__ProratedListPrice__c":0.00,"SBQQ__PricingMethod__c":"List","SBQQ__PricingMethodEditable__c":true,"SBQQ__ProrateMultiplier__c":1.0000,"SBQQ__Quantity__c":1.00,"SBQQ__SpecialPrice__c":0.00,"SBQQ__StartDate__c":"2023-05-01","SBQQ__Renewal__c":false,"SBQQ__ProratedPrice__c":0.00,"SBQQ__Uplift__c":0.00,"SBQQ__UpliftAmount__c":0.00,"SBQQ__ComponentUpliftedByPackage__c":false,"SBQQ__ProductName__c":"Energy - Peak - Qtrly","SBQQ__Existing__c":false,"SBQQ__CarryoverLine__c":false,"SBQQ__AllowAssetRefund__c":false,"SBQQ__RegularPrice__c":69.00,"Original_Price_Formula__c":0.00,"Special_Price_Formula__c":0.00,"SBQQ__Markup__c":0.00,"SBQQ__EffectiveQuantity__c":1.00,"SBQQ__Dimension__r":{"attributes":{"type":"SBQQ__Dimension__c","url":"/services/data/v57.0/sobjects/SBQQ__Dimension__c/a0C5i000009BWHpEAO"},"Id":"a0C5i000009BWHpEAO","SBQQ__Type__c":"Quarter","SBQQ__QuantityEditable__c":"Yes"},"SBQQ__Product__r":{"attributes":{"type":"Product2","url":"/services/data/v57.0/sobjects/Product2/01t5i000005LoM6AAK"},"Id":"01t5i000005LoM6AAK","Name":"Energy - Peak - Qtrly","SBQQ__SubscriptionPricing__c":"Fixed Price","SBQQ__PriceEditable__c":true,"SBQQ__DefaultQuantity__c":1.00000,"SBQQ__QuantityEditable__c":true,"SBQQ__CostEditable__c":true,"SBQQ__NonDiscountable__c":true,"SBQQ__NonPartnerDiscountable__c":false,"SBQQ__SubscriptionTerm__c":3,"SBQQ__SubscriptionBase__c":"List","SBQQ__PricingMethod__c":"List","SBQQ__PricingMethodEditable__c":true,"SBQQ__OptionSelectionMethod__c":"Click","SBQQ__Optional__c":false,"SBQQ__Taxable__c":false,"SBQQ__CustomConfigurationRequired__c":false,"SBQQ__Hidden__c":false,"SBQQ__ReconfigurationDisabled__c":false,"SBQQ__ExcludeFromOpportunity__c":false,"SBQQ__DescriptionLocked__c":false,"SBQQ__ExcludeFromMaintenance__c":false,"SBQQ__IncludeInMaintenance__c":false,"SBQQ__NewQuoteGroup__c":false,"SBQQ__SubscriptionType__c":"Renewable","SBQQ__AssetConversion__c":"One per quote line","SBQQ__BlockPricingField__c":"Quantity","SBQQ__HasConfigurationAttributes__c":false,"SBQQ__HasConsumptionSchedule__c":false,"SBQQ__DefaultPricingTable__c":"Segmented","SBQQ__ExternallyConfigurable__c":false,"SBQQ__AssetAmendmentBehavior__c":"Default","SBQQ__Dimensions__r":{"totalSize":1,"done":true,"records":[{"attributes":{"type":"SBQQ__Dimension__c","url":"/services/data/v57.0/sobjects/SBQQ__Dimension__c/a0C5i000009BWHpEAO"},"SBQQ__Product__c":"01t5i000005LoM6AAK","Id":"a0C5i000009BWHpEAO","OwnerId":"0055i000007XncYAAS","IsDeleted":false,"Name":"Quarterly Pricing","CreatedDate":"2023-04-27T01:07:01.000+0000",

@pozil
Copy link
Collaborator

pozil commented Apr 28, 2023

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
Copy link
Author

Hi,

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

image

@pozil
Copy link
Collaborator

pozil commented Apr 28, 2023

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
Copy link
Author

inspired27 commented Apr 29, 2023 via email

@inspired27
Copy link
Author

inspired27 commented Apr 30, 2023

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
Copy link
Collaborator

pozil commented May 2, 2023

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
Copy link
Author

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

@pozil
Copy link
Collaborator

pozil commented May 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants