Link

Create Estimate

Sample Requests and Responses

The following is an example request which can be used while using ‘createEstimate’ action.

Request

//  Create a Map to store all the data of an Estimate
Map<String, Object> nsEstimate = new Map<String, Object>();
    nsEstimate.put('classification', new Map<String, Object>{'internalId'=>'5'});
    nsEstimate.put('currencyRecord', new Map<String, Object>{'internalId'=>'2'});
    nsEstimate.put('customForm', new Map<String, Object>{'internalId'=>'124'});
    nsEstimate.put('department', new Map<String, Object>{'internalId'=>'2'});
    nsEstimate.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
    nsEstimate.put('discountRate', '-15');
    nsEstimate.put('dueDate', DateTime.newInstance(2020, 12, 31).getTime()/1000);
    nsEstimate.put('entity', new Map<String, Object>{'internalId'=>'362'});
    nsEstimate.put('entityStatus', new Map<String, Object>{'internalId'=>'8'});
    nsEstimate.put('expectedCloseDate', DateTime.newInstance(2020, 12, 31).getTime()/1000);
    nsEstimate.put('externalId', 'SFId: a012w00000Oyssh');
    nsEstimate.put('memo', 'Order 25');
    nsEstimate.put('otherRefNum', '4343399');
    nsEstimate.put('probability', 35);
    nsEstimate.put('title', 'SF Estimate');
    nsEstimate.put('tranDate', DateTime.newInstance(2020, 09, 07).getTime()/1000);
//  Initializing the Estimate Custom Fields
List<Object> estCustomFieldList = new List<Object>();
Map<String,Object> estCustomField = new Map<String,Object>();
    estCustomField.put('fieldType', 'select');
    estCustomField.put('scriptId', 'custbody_customlist');
    estCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'2'});
    estCustomFieldList.add(estCustomField);

//  Adding the Estimate Custom Fields
    nsEstimate.put('customFieldList', new Map<String,Object>{'customField'=>estCustomFieldList});

//  Initializing the Estimate Line Items
List<Object> lineItemList = new List<Object>();
Map<String, Object> lineItem = new Map<String, Object>();
    lineItem.put('description', 'A weapon for shooting arrows');
    lineItem.put('item', new Map<String, Object>{'internalId'=>'239'});
    lineItem.put('quantity', 1);
    lineItem.put('rate', '999');

//  Initializing the Line Item custom fields
List<Object> liCustomFieldList = new List<Object>();
Map<String, Object> liCustomField = new Map<String, Object>();
    liCustomField.put('fieldType', 'boolean');
    liCustomField.put('scriptId', 'custbody_checkbox');
    liCustomField.put('value', 'true');
    liCustomFieldList.add(liCustomField);

//  Adding the Estimate Line Item Custom Fields
    lineItem.put('customFieldList',new Map<String,Object>{'customField'=>liCustomFieldList});
    lineItemList.add(lineItem);

//  Adding the Line Items to Estimate
Map<String, Object> estimateLineitemList = new Map<String, Object>();
    estimateLineitemList.put('item',lineItemList);
    nsEstimate.put('itemList',estimateLineitemList);

//  Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
    requestJSONMap.put('estimates', new List<Object>{nsEstimate});
    String reqJSON = JSON.serialize(requestJSONMap);

Map<String, Object> reqObj = new Map<String, Object>();
    reqObj.put('version', '1.0');
    reqObj.put('action', 'createEstimate');
    reqObj.put('requestJSON', reqJSON);

//  Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);

Response

{
    action=createEstimate,
    timestamp=1599492195201, 
    validRequest=true,
    version=1.0, 
    responseJSON={
      "errors": [],
      "status": "200",
      "estimates": [
        {
          "tranId": "98",
          "tranDate": 1599417000,
          "total": 984,
          "title": "SF Estimate",
          "taxTotal": 0,
          "subTotal": 999,
          "subsidiary": {
            "type": null,
            "name": "Parent Company",
            "internalId": "1",
            "externalId": null
          },
          "status": "Open",
          "shippingCost": null,
          "salesRep": null,
          "salesforceID": "a042v00002e7WeKAAU",
          "probability": 35,
          "otherRefNum": "4343399",
          "nullFieldList": null,
          "memo": "Database order 25",
          "lastModifiedDate": 1599492192,
          "itemList": {
            "item": [
              {
                "taxRate1": 0,
                "taxCode": {
                  "type": null,
                  "name": "VAT_IN:UNDEF-IN",
                  "internalId": "5",
                  "externalId": null
                },
                "tax1Amt": 0,
                "revRecStartDate": null,
                "revRecSchedule": null,
                "revRecEndDate": null,
                "rate": "999.00",
                "quantity": 1,
                "price": {
                  "type": null,
                  "name": null,
                  "internalId": "-1",
                  "externalId": null
                },
                "location": null,
                "line": 1,
                "item": {
                  "type": null,
                  "name": "Bow",
                  "internalId": "239",
                  "externalId": null
                },
                "grossAmt": 999,
                "description": "A weapon for shooting arrows",
                "department": null,
                "customFieldList": {
                  "customField": [
                    {
                      "valueLookup": null,
                      "value": "false",
                      "scriptId": "custcol_checkbox",
                      "internalId": "443",
                      "fieldType": null
                    }
                  ]
                },
                "classification": null,
                "amount": 999
              }
            ]
          },
          "internalId": "38310",
          "handlingCost": null,
          "externalId": "SFId: a012w00000Oyssh",
          "expectedCloseDate": 1609353000,
          "exchangeRate": 1,
          "entityStatus": {
            "type": null,
            "name": "In Discussion",
            "internalId": "8",
            "externalId": null
          },
          "entity": {
            "type": null,
            "name": "21 Atherton Grocery",
            "internalId": "362",
            "externalId": null
          },
          "dueDate": 1609353000,
          "discountTotal": -15,
          "discountRate": "-15.00",
          "discountItem": {
            "type": null,
            "name": "Partner Discount",
            "internalId": "-6",
            "externalId": null
          },
          "department": {
            "type": null,
            "name": "Sales",
            "internalId": "2",
            "externalId": null
          },
          "customForm": {
            "type": null,
            "name": "Custom Estimate 2",
            "internalId": "124",
            "externalId": null
          },
          "customFieldList": {
            "customField": [
              {
                "valueLookup": {
                  "type": null,
                  "name": "B",
                  "internalId": "2",
                  "externalId": null
                },
                "value": null,
                "scriptId": "custbody_customlist",
                "internalId": "458",
                "fieldType": null
              },
              {
                "valueLookup": null,
                "value": "false",
                "scriptId": "custbody_checkbox",
                "internalId": "272",
                "fieldType": null
              }
            ]
          },
          "currencyRecord": null,
          "currencyName": "US Dollars",
          "createdDate": 1599492192,
          "classification": {
            "type": null,
            "name": "Corporate Sales",
            "internalId": "5",
            "externalId": null
          }
        }
      ]
    }
}