Link

Create Purchase Order

Sample Requests and Responses

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

Request

//  Create a Map to store all the data of a Purchase Order
Map<String, Object> nsPurchaseorder = new Map<String, Object>();
    nsPurchaseorder.put('classification', new Map<String, Object>{'internalId'=>'5'});
    nsPurchaseorder.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
    nsPurchaseorder.put('department', new Map<String, Object>{'internalId'=>'2'});
    nsPurchaseorder.put('dueDate', DateTime.newInstance(2020, 12, 31).getTime()/1000);
    nsPurchaseorder.put('entity', new Map<String, Object>{'internalId'=>'30440'});
    nsPurchaseorder.put('shipTo', new Map<String, Object>{'internalId'=>'362'});
    nsPurchaseorder.put('memo', 'PO 12');
    nsPurchaseorder.put('otherRefNum', '4343399');
    nsPurchaseorder.put('tranDate', DateTime.newInstance(2020, 09, 07).getTime()/1000);

//  Initializing the Purchase Order Custom Fields
List<Object> poCustomFieldList = new List<Object>();
Map<String,Object> poCustomField = new Map<String,Object>();
    poCustomField.put('fieldType', 'select');
    poCustomField.put('scriptId', 'custbody_customlist');
    poCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'2'});
    poCustomFieldList.add(poCustomField);

//  Adding the Purchase Order Custom Fields
    nsPurchaseorder.put('customFieldList', new Map<String,Object>{'customField'=>poCustomFieldList});

//  Initializing the Purchase Order 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', 'custcol_checkbox');
    liCustomField.put('value', 'true');
    liCustomFieldList.add(liCustomField);

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

//  Adding the Line Items to Purchase Order
Map<String, Object> poLineitemList = new Map<String, Object>();
    poLineitemList.put('item',lineItemList);
    nsPurchaseorder.put('itemList',poLineitemList);

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

Map<String, Object> reqObj = new Map<String, Object>();
    reqObj.put('version', '1.0');
    reqObj.put('action', 'createPurchaseOrder');
    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=createPurchaseOrder,
  timestamp=1606481122212,
  validRequest=true,
  version=1.0,
  responseJSON={
    "status": "200",
    "errors": [],
    "purchaseOrders": [
      {
        "tranId": "360",
        "tranDate": 1599417000,
        "trackingNumbers": null,
        "total": 1178.82,
        "terms": null,
        "taxTotal": 179.82,
        "subTotal": 999.0,
        "subsidiary": {
          "type": null,
          "name": "Parent Company",
          "internalId": "1",
          "externalId": null
        },
        "status": "Pending Receipt",
        "source": "Web Services",
        "shipTo": {
          "type": null,
          "name": "21 Atherton Grocery",
          "internalId": "362",
          "externalId": null
        },
        "shippingAddress": {
          "zip": "94567",
          "state": "CA",
          "internalId": null,
          "country": "_unitedStates",
          "city": "Pope Valley",
          "attention": null,
          "addrPhone": null,
          "addressee": null,
          "addr3": null,
          "addr2": "Palo Alto",
          "addr1": null
        },
        "shipMethod": null,
        "shipDate": 1606415400,
        "salesforceID": "a0O2w000001rix8EAA",
        "otherRefNum": "4343399",
        "nullFieldList": null,
        "memo": "PO 12",
        "location": null,
        "lastModifiedDate": 1606481119,
        "itemList": {
          "replaceAll": null,
          "item": [
            {
              "unitsDisplay": null,
              "taxRate1": "18.0",
              "taxCode": {
                "type": null,
                "name": "VAT_IN:GST 18",
                "internalId": "36",
                "externalId": null
              },
              "tax1Amt": 179.82,
              "shipMethod": null,
              "shipGroup": null,
              "serialNumbers": null,
              "revRecStartDate": null,
              "revRecSchedule": null,
              "revRecEndDate": null,
              "rate": "999.00",
              "quantityRemaining": null,
              "quantityReceived": 0.0,
              "quantityBilled": 0.0,
              "quantity": 1.0,
              "price": null,
              "poNum": null,
              "orderLine": null,
              "onHand": null,
              "location": null,
              "line": 1,
              "jobName": null,
              "itemReceive": null,
              "itemName": null,
              "itemIsFulfilled": null,
              "item": {
                "type": null,
                "name": "Bow",
                "internalId": "239",
                "externalId": null
              },
              "grossAmt": 1178.82,
              "expectedReceiptDate": 1599417000,
              "description": "A weapon for shooting arrows",
              "department": null,
              "customFieldList": {
                "customField": [
                  {
                    "valueLookup": null,
                    "value": "1",
                    "scriptId": "custcol_gh_line_no",
                    "internalId": "175",
                    "fieldType": null
                  },
                  {
                    "valueLookup": null,
                    "value": "true",
                    "scriptId": "custcol_checkbox",
                    "internalId": "443",
                    "fieldType": null
                  }
                ]
              },
              "createPo": null,
              "costEstimateType": null,
              "costEstimate": null,
              "classification": null,
              "amount": 999.0
            }
          ]
        },
        "internalId": "54653",
        "fax": null,
        "externalId": null,
        "exchangeRate": 1.0,
        "entity": {
          "type": null,
          "name": "RM Textiles",
          "internalId": "30440",
          "externalId": null
        },
        "employee": null,
        "email": null,
        "dueDate": 1609353000,
        "department": {
          "type": null,
          "name": "Sales",
          "internalId": "2",
          "externalId": null
        },
        "customForm": {
          "type": null,
          "name": "Custom Drop Ship Purchase Order 6",
          "internalId": "119",
          "externalId": null
        },
        "customFieldList": {
          "customField": [
            {
              "valueLookup": null,
              "value": "false",
              "scriptId": "custbody34",
              "internalId": "558",
              "fieldType": null
            },
            {
              "valueLookup": {
                "type": null,
                "name": "B",
                "internalId": "2",
                "externalId": null
              },
              "value": null,
              "scriptId": "custbody_customlist",
              "internalId": "458",
              "fieldType": null
            }
          ]
        },
        "currencyRecord": null,
        "currencyName": "INR",
        "createdFrom": null,
        "createdDate": 1606481118,
        "classification": {
          "type": null,
          "name": "Corporate Sales",
          "internalId": "5",
          "externalId": null
        },
        "billingAddress": null
      }
    ]
  }
}