---
title: Create
slug: quickbooks/jNFP-create
description: Learn how to create a credit memo in this comprehensive document. It covers all the necessary fields and their values, including transaction date, document number, exchange rate, custom fields, address information, sales terms, customer reference, billing
docTags: 
createdAt: 2021-12-31T06:38:39.000Z
---

The following is an example of create a Credit Memo where we are setting every possible field (See [Credit Memo](docId\:X6Nlsr2VQhr25341RoqD0) 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)

:::hint{type="info"}
Note:  You can only create one record at a time.
:::

:::CodeblockTabs
Request

```apex
//  Create a Map to store all the data of a Credit Memo
List<Object> creditMemoList = new List<Object>();
Map<String, Object> creditMemoMap = new Map<String, Object>();
    creditMemoMap.put('TxnDate', '2021/08/11');
    creditMemoMap.put('DocNumber', '1201');
    creditMemoMap.put('ExchangeRate', 1.0);

    //  Initializing the Credit Memo Custom Fields
    List<Object> customFieldList = new List<Object>();
      Map<String, Object> customFiel1dMap = new Map<String, Object>(); 
      customFiel1dMap.put('DefinitionId','1');
      customFiel1dMap.put('Type','StringType');
      customFiel1dMap.put('StringValue','Received');
      customFieldList.add(customFiel1dMap);

    //  Adding the Credit Memo Custom Fields
    creditMemoMap.put('CustomField',customFieldList);

    creditMemoMap.put('Address',new Map<String, Object>{'FreeFormNumber' => '+919090909090'});
    creditMemoMap.put('SalesTermRef',new Map<String, Object>{'value' => '4'});
    creditMemoMap.put('CustomerRef',new Map<String, Object>{'value' => '29'});

    //  Initializing the Billing Address
    Map<String, Object> billAddrMap = new Map<String, Object>();
        billAddrMap.put('City' , 'Suryapet');
        billAddrMap.put('Country' , 'India');
        billAddrMap.put('Line3' , 'Kodad');
        billAddrMap.put('Line2' , 'First Lane');
        billAddrMap.put('Line1' , '1-24');
        billAddrMap.put('PostalCode' , '508238');
        billAddrMap.put('CountrySubDivisionCode' , '');
    creditMemoMap.put('BillAddr',billAddrMap);

    //  Initializing the Credit Memo Line Items
    List<Object> lineItemList = new List<Object>();
        Map<String, Object> lineItemMap = new Map<String, Object>(); 
        lineItemMap.put('LineNum',1);
        lineItemMap.put('Amount',100);
        lineItemMap.put('Description','Description');
		lineItemMap.put('DetailType', 'SalesItemLineDetail');

        Map<String, Object> salesLineItemDetailMap = new Map<String, Object>();
            salesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => '1'});
			      salesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'});
            salesLineItemDetailMap.put('ClassRef' , new Map<String, Object>{'value' => '5000000000000193289'});
            salesLineItemDetailMap.put('ServiceDate','1993/05/25'); //yyyy/MM/dd
            salesLineItemDetailMap.put('Qty',2);
            salesLineItemDetailMap.put('UnitPrice',50);
            salesLineItemDetailMap.put('TaxInclusiveAmt',22);
        
        lineItemMap.put('SalesItemLineDetail', salesLineItemDetailMap);
        lineItemList.add(lineItemMap);

    //  Adding the Line Items to Credit Memo
    creditMemoMap.put('Line',lineItemList);
    creditMemoList.add(creditMemoMap);

//  Initializing the RequestJSON Data to be passed.
    Map<String, Object> reqJSONMap = new Map<String, Object>(); 
    reqJSONMap.put('creditmemos' , creditMemoList); 
    String reqJSON = JSON.serialize(reqJSONMap); 

    Map<String, Object> finalReqMap = new Map<String, Object>(); 
    Map<String, Object> reqOptions = new Map<String, Object>(); 
    finalReqMap.put('options' , reqOptions); 
    finalReqMap.put('version' , '1.0'); 
    finalReqMap.put('action' , 'createCreditMemo'); 
    finalReqMap.put('RequestJSON' , reqJSON); 
    finalReqMap.put('skipDML' , false);
    //Required, if QuickBooks Multi-Org is enabled in Breadwinner. 
    finalReqMap.put('qbOrgId', '4620816365285051610'); 
    System.debug('Request ::: ' + finalReqMap);

//  Placing a request to Breadwinner Global API
    Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(finalReqMap);
    System.debug('Response ::: ' + respMap);
```

Response

```json
{
  action=createCreditMemo,
  responseJSON={
    "statusCode": 200,
    "creditMemos": [
      {
        "TxnTaxDetail": {
          "TotalTax": 0
        },
        "TxnDate": "2021-08-11",
        "TotalAmt": 100.00,
        "SyncToken": "0",
        "sparse": false,
        "SFRecordID": "a0A5j000000vDppEAE",
        "salesforceRecordId": "a0A5j000000vDppEAE",
        "RemainingCredit": 100.00,
        "MetaData": {
          "LastUpdatedTime": "2021-12-31T02:35:26-08:00",
          "CreateTime": "2021-12-31T02:35:26-08:00"
        },
        "Line": [
          {
            "SalesItemLineDetail": {
              "UnitPrice": 50,
              "TaxCodeRef": {
                "value": "TAX"
              },
              "ServiceDate": "1993-05-25",
              "Qty": 2,
              "ItemRef": {
                "value": "1",
                "name": "Services"
              }
            },
            "LineNum": 1,
            "Id": "1",
            "DetailType": "SalesItemLineDetail",
            "Description": "Description",
            "Amount": 100.00
          },
          {
            "DetailType": "SubTotalLineDetail",
            "Amount": 100.00
          }
        ],
        "Id": "187",
        "EmailStatus": "NotSet",
        "DocNumber": "1201",
        "CustomField": [
          {
            "Type": "StringType",
            "StringValue": "Received",
            "Name": "Crew #",
            "DefinitionId": "1"
          },
          {
            "Type": "StringType",
            "Name": "Test 2",
            "DefinitionId": "2"
          },
          {
            "Type": "StringType",
            "DefinitionId": "3"
          }
        ],
        "CustomerRef": {
          "value": "29",
          "name": "Weiskopf Consulting"
        },
        "CurrencyRef": {
          "value": "USD",
          "name": "United States Dollar"
        },
        "BillAddr": {
          "PostalCode": "508238",
          "Line3": "Kodad",
          "Line2": "First Lane",
          "Line1": "1-24",
          "Id": "191",
          "Country": "India",
          "City": "Suryapet"
        },
        "Balance": 100.00
      }
    ]
  },
  timestamp=1640946928725,
  validRequest=true,
  version=1.0
}
```
:::

Do you want to link a Credit Note to an Invoice ? See [here](https://app.archbee.com/docs/gaRAXzBPU8gEodLU0-0q-/nNmzKcy44XElGf3_h_ZjU)
