Global API
...
Requests
Item
Create
1min
The following is an example of creating an Item where we are setting every possible field (See Item for the available fields). The response will return the exact request data plus the new NetSuite item Id (internalId) and the newly created Salesforce item Id (salesforceID).
Pass skipDML as true in the request to skip the DML operation in Salesforce.
Request
Response
1// Create a Map to store all the data of an Item 1
2Map<String, Object> nsItem1 = new Map<String, Object>();
3 nsItem1.put('itemType', 'nonInventoryResaleItem');
4 nsItem1.put('itemId', 'Leather Jacket');
5 nsItem1.put('taxSchedule', new Map<String, Object>{'internalId'=>'1'});
6 nsItem1.put('incomeAccount', new Map<String, Object>{'internalId'=>'54'});
7 nsItem1.put('expenseAccount', new Map<String, Object>{'internalId'=>'58'});
8 nsItem1.put('salesDescription', 'Blue Color Leather Jacket');
9 nsItem1.put('upcCode', '00123456789012');
10
11 // Provide the Subsidiary List
12 List<Object> subsidiaryList1 = new List<Object>{new Map<String, Object>{'internalId'=>'1'}};
13 nsItem1.put('subsidiaryList', new Map<String, Object>{'recordRef'=>subsidiaryList1});
14 nsItem1.put('includeChildren', TRUE);
15
16 // Initializing the Item Custom Fields
17 List<Object> itemCustomFieldList = new List<Object>();
18 Map<String, Object> itemCustomField = new Map<String, Object>();
19 itemCustomField.put('fieldType', 'select');
20 itemCustomField.put('scriptId', 'custitem_standardlist');
21 itemCustomField.put('valueLookup', new Map<String, Object>{'internalId'=>'2'});
22 itemCustomFieldList.add(itemCustomField);
23 Map<String, Object> itemCustomField1 = new Map<String, Object>();
24 itemCustomField1.put('fieldType', 'boolean');
25 itemCustomField1.put('scriptId', 'custitem_checkbox');
26 itemCustomField1.put('value','true');
27 itemCustomFieldList.add(itemCustomField1);
28
29// Adding the Item Custom Fields
30 nsItem1.put('customFieldList', new Map<String, Object>{'customField'=>itemCustomFieldList});
31
32// Create a Map to store all the data of an Item 2
33Map<String, Object> nsItem2 = new Map<String, Object>();
34 nsItem2.put('itemType', 'nonInventorySaleItem');
35 nsItem2.put('itemId', 'Laptop');
36 nsItem2.put('taxSchedule', new Map<String, Object>{'internalId'=>'1'});
37
38// Provide the Subsidiary List
39 List<Object> subsidiaryList2 = new List<Object>{new Map<String, Object>{'internalId'=>'1'}};
40 nsItem2.put('subsidiaryList', new Map<String, Object>{'recordRef'=>subsidiaryList2});
41
42
43// Initializing the RequestJSON Data to be passed.
44Map<String, Object> requestJSONMap = new Map<String, Object>();
45 requestJSONMap.put('items', new List<Object>{nsItem1, nsItem2}); // similarly we can upto 20 items to the list
46 String reqJSON = JSON.serialize(requestJSONMap);
47
48Map<String, Object> reqObj = new Map<String, Object>();
49 reqObj.put('version', '1.0');
50 reqObj.put('action', 'createItem');
51 reqObj.put('skipDML', false);
52 reqObj.put('requestJSON', reqJSON);
53
54// Placing a request to Breadwinner Global API
55Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
56System.debug(resp);