Global API
...
Request
Credit Memo
Create
1min
The following is an example of create a Credit Memo where we are setting every possible field (See Credit Memo for the available fields). The response will return the exact request data plus the new QuickBooks Credit Memo Id (Id) and the newly created Salesforce Credit Memo Id (salesforceRecordId)
Note: You can only create one record at a time.
Request
Response
1// Create a Map to store all the data of a Credit Memo
2List<Object> creditMemoList = new List<Object>();
3Map<String, Object> creditMemoMap = new Map<String, Object>();
4 creditMemoMap.put('TxnDate', '2021/08/11');
5 creditMemoMap.put('DocNumber', '1201');
6 creditMemoMap.put('ExchangeRate', 1.0);
7
8 // Initializing the Credit Memo Custom Fields
9 List<Object> customFieldList = new List<Object>();
10 Map<String, Object> customFiel1dMap = new Map<String, Object>();
11 customFiel1dMap.put('DefinitionId','1');
12 customFiel1dMap.put('Type','StringType');
13 customFiel1dMap.put('StringValue','Received');
14 customFieldList.add(customFiel1dMap);
15
16 // Adding the Credit Memo Custom Fields
17 creditMemoMap.put('CustomField',customFieldList);
18
19 creditMemoMap.put('Address',new Map<String, Object>{'FreeFormNumber' => '+919090909090'});
20 creditMemoMap.put('SalesTermRef',new Map<String, Object>{'value' => '4'});
21 creditMemoMap.put('CustomerRef',new Map<String, Object>{'value' => '29'});
22
23 // Initializing the Billing Address
24 Map<String, Object> billAddrMap = new Map<String, Object>();
25 billAddrMap.put('City' , 'Suryapet');
26 billAddrMap.put('Country' , 'India');
27 billAddrMap.put('Line3' , 'Kodad');
28 billAddrMap.put('Line2' , 'First Lane');
29 billAddrMap.put('Line1' , '1-24');
30 billAddrMap.put('PostalCode' , '508238');
31 billAddrMap.put('CountrySubDivisionCode' , '');
32 creditMemoMap.put('BillAddr',billAddrMap);
33
34 // Initializing the Credit Memo Line Items
35 List<Object> lineItemList = new List<Object>();
36 Map<String, Object> lineItemMap = new Map<String, Object>();
37 lineItemMap.put('LineNum',1);
38 lineItemMap.put('Amount',100);
39 lineItemMap.put('Description','Description');
40 lineItemMap.put('DetailType', 'SalesItemLineDetail');
41
42 Map<String, Object> salesLineItemDetailMap = new Map<String, Object>();
43 salesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => '1'});
44 salesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'});
45 salesLineItemDetailMap.put('ClassRef' , new Map<String, Object>{'value' => '5000000000000193289'});
46 salesLineItemDetailMap.put('ServiceDate','1993/05/25'); //yyyy/MM/dd
47 salesLineItemDetailMap.put('Qty',2);
48 salesLineItemDetailMap.put('UnitPrice',50);
49 salesLineItemDetailMap.put('TaxInclusiveAmt',22);
50
51 lineItemMap.put('SalesItemLineDetail', salesLineItemDetailMap);
52 lineItemList.add(lineItemMap);
53
54 // Adding the Line Items to Credit Memo
55 creditMemoMap.put('Line',lineItemList);
56 creditMemoList.add(creditMemoMap);
57
58// Initializing the RequestJSON Data to be passed.
59 Map<String, Object> reqJSONMap = new Map<String, Object>();
60 reqJSONMap.put('creditmemos' , creditMemoList);
61 String reqJSON = JSON.serialize(reqJSONMap);
62
63 Map<String, Object> finalReqMap = new Map<String, Object>();
64 Map<String, Object> reqOptions = new Map<String, Object>();
65 finalReqMap.put('options' , reqOptions);
66 finalReqMap.put('version' , '1.0');
67 finalReqMap.put('action' , 'createCreditMemo');
68 finalReqMap.put('RequestJSON' , reqJSON);
69 finalReqMap.put('skipDML' , false);
70 //Required, if QuickBooks Multi-Org is enabled in Breadwinner.
71 finalReqMap.put('qbOrgId', '4620816365285051610');
72 System.debug('Request ::: ' + finalReqMap);
73
74// Placing a request to Breadwinner Global API
75 Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(finalReqMap);
76 System.debug('Response ::: ' + respMap);
Do you want to link a Credit Note to an Invoice ? See here