0

I'm receiving errors which look similar to a previous question (System.JSONException: Unexpected character ('a' (code 97)): was expecting double-quote to start field name at [line:1, column:3]) to which i posted a comment however I was thinking as it's an already answered question I might need to open a new one to re-engage the conversation. (I'm not sure if comments on answered questions get picked up often) I hope that's ok!

I'm trying to test out the following API https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_api_add_products.htm

For the sample JSON provided it does include escapes for double-quotes

{"context":"{\\"quote\\":{\\"record\\":{\\"attributes\\":{\\"type\\":\\"SBQQ__Quote__c\\",\\"url\\":\\"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK\\"},
\\"Name\\":\\"Q-00905\\",\\"Id\\":\\"a0p61000004IpR8AAK\\"},\\"nextKey\\":2,\\"netTotal\\":0.00,\\"lineItems\\":[],\\"lineItemGroups\\":[],
\\"customerTotal\\":0.00},\\"products\\":[],\\"groupKey\\":0, \\"ignoreCalculate\\": true}"}

Initially I received an error "Unexpected parameter encountered during deserialization: context at [line:1, column:13]"

I then added escapes to the double-quotes around context also.

{\\"context\\":"{\\"quote\\":{\\"record\\":{\\"attributes\\":{\\"type\\":\\"SBQQ__Quote__c\\",\\"url\\":\\"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK\\"},
\\"Name\\":\\"Q-00905\\",\\"Id\\":\\"a0p61000004IpR8AAK\\"},\\"nextKey\\":2,\\"netTotal\\":0.00,\\"lineItems\\":[],\\"lineItemGroups\\":[],
\\"customerTotal\\":0.00},\\"products\\":[],\\"groupKey\\":0, \\"ignoreCalculate\\": true}"}

I received the following error. Unexpected character ('' (code 92)): was expecting double-quote to start field name at [line:1, column:3]

I then thought that the values might require double quotes also

{\\"context\\":"{\\"quote\\":{\\"record\\":{\\"attributes\\":{\\"type\\":\\"SBQQ__Quote__c\\",\\"url\\":\\"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK\\"},
\\"Name\\":\\"Q-00905\\",\\"Id\\":\\"a0p61000004IpR8AAK\\"},\\"nextKey\\":\\"2\\",\\"netTotal\\":\\"0.00\\",\\"lineItems\\":[],\\"lineItemGroups\\":[],
\\"customerTotal\\":\\"0.00\\"},\\"products\\":[],\\"groupKey\\":\\"0\\", \\"ignoreCalculate\\": \\"true\\"}"}

but the same error occurs.

Does anyone know what format is required to allow this to parse successfully in Apex? Note to get the \'s to appear in this question I had to \\ them :)

Thanks for any help on this. I've been trying out many combinations without success.

1
  • Are you calling this from Apex or from an external app?
    – identigral
    Commented Aug 26, 2022 at 15:20

1 Answer 1

0

The example has line breaks for legibility, but they shouldn't actually be in there.

If you're trying this in apex, call it with the JSON as follows:

String sample = 
    '{"context":"{\\"quote\\":{\\"record\\":{\\"attributes\\":{\\"type\\"'+
    ':\\"SBQQ__Quote__c\\",\\"url\\":\\"/services/data/v41.0/sobjects'+ 
    '/SBQQ__Quote__c/a0p61000004IpR8AAK\\"},\\"Name\\":\\"Q-00905\\",'+
    '\\"Id\\":\\"a0p61000004IpR8AAK\\"},\\"nextKey\\":2,\\"netTotal\\"'+
    ':0.00,\\"lineItems\\":[],\\"lineItemGroups\\":[],\\"customerTotal'+
    '\\":0.00},\\"products\\":[],\\"groupKey\\":0, \\"ignoreCalculate\\": true}"}';

If you're trying to do it with curl/Postman/etc, just make sure that there are no line breaks:

{"context":"{\"quote\":{\"record\":{\"attributes\":{\"type\":\"SBQQ__Quote__c\",\"url\":\"/services/data/v41.0/sobjects/SBQQ__Quote__c/a0p61000004IpR8AAK\"},\"Name\":\"Q-00905\",\"Id\":\"a0p61000004IpR8AAK\"},\"nextKey\":2,\"netTotal\":0.00,\"lineItems\":[],\"lineItemGroups\":[],\"customerTotal\":0.00},\"products\":[],\"groupKey\":0, \"ignoreCalculate\": true}"}
1
  • Thank you @sfdcfox for your help
    – RedQueries
    Commented Aug 30, 2022 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .