如何使用Zoho Deluge的POST方法访问json数组?

bjp0bcyl  于 2022-11-19  发布在  其他
关注(0)|答案(1)|浏览(82)

我在访问Zoho inventory的api时遇到了一点麻烦,它有一个数据数组,这是它的外观

{
    "date": "2015-05-28",
    "reason": "Damaged goods",
    "description": "Just a sample description.",
    "reference_number": "REF-IA-00001",
    "adjustment_type": "quantity",
    "line_items": [
        {
            "item_id": 4815000000044100,
            "name": "Laptop-white/15inch/dell",
            "description": "Just a sample description.",
            "quantity_adjusted": 10,
            "item_total": 244,
            "unit": "qty",
            "is_combo_product": false,
            "adjustment_account_id": 4815000000000388,
            "adjustment_account_name": "Cost of Goods Sold",
            "warehouse_id": 4815000000000390,
            "warehouse_name": "MyWarehouse"
        }
    ]
}

这是我当前的代码

headersMap = Map();
headersMap.put("Authorization","Zoho-oauthtoken xxxxxxxxxxxxxxxxx");
parametersMap = Map();
response = invokeurl
[
    url :"https://inventory.zoho.com/api/v1/inventoryadjustments?organization_id=xxxx"
    type :POST
    headers:headersMap
];
dateVal = input.Date_field;
reasonVal = input.Reason;
descriptionVal = input.Description1;
referenceNumberVal = input.Reference_Number;
adjustmentTypeVal = input.Adjustment_Type;
itemIDVal = input.Item_ID;
nameVal = input.Name1;
quantityAdjustedVal = input.Quantity_Adjusted;
itemTotalVal = input.Item_Total;
unitVal = input.Unit;
isComboProductVal = input.Is_Combo_Product;
adjustmentAccountIdVal = input.Adjustment_Account_ID;
adjustmentAccountNameVal = input.Adjustment_Account_Name;
warehouseIdVal = input.Warehouse_ID;
warehouseNameVal = input.Warehouse_Name;

parametersMap.put("date",dateVal);
parametersMap.put("reason",reasonVal);
parametersMap.put("description",descriptionVal);
parametersMap.put("reference_number",referenceNumberVal);
parametersMap.put("adjustment_type",adjustmentTypeVal);

我已经为所有的值创建了变量,但是我对如何写“line_items”数组的键有点困惑,任何关于这方面的帮助都将非常感谢。

wfveoks0

wfveoks01#

修订版2:
1.“line_items”看起来像是“对映清单”。每个项目有一个“对映”。范例中的“line_item”特定程式码在注解中有“Line_Items:“信头。
1.似乎应在调用invokeurl之前设置parameterMap。
然后invokeurl应该包含parameterMap。
示例:

headersMap = Map();
headersMap.put("Authorization","Zoho-oauthtoken xxxxxxxxxxxxxxxxx");

// Setup parametersMap
//----------------------------------------------------
parametersMap = Map();

dateVal = input.Date_field;
reasonVal = input.Reason;
descriptionVal = input.Description1;
referenceNumberVal = input.Reference_Number;
adjustmentTypeVal = input.Adjustment_Type;
itemIDVal = input.Item_ID;
nameVal = input.Name1;
quantityAdjustedVal = input.Quantity_Adjusted;
itemTotalVal = input.Item_Total;
unitVal = input.Unit;
isComboProductVal = input.Is_Combo_Product;
adjustmentAccountIdVal = input.Adjustment_Account_ID;
adjustmentAccountNameVal = input.Adjustment_Account_Name;
warehouseIdVal = input.Warehouse_ID;
warehouseNameVal = input.Warehouse_Name;

//----------------------------------------------------
// Line_Items:
// Configure an item's data as a Deluge Map
//----------------------------------------------------
OneItem = Map();
OneItem.put("item_id", 4815000000044100);
OneItem.put("name", "Laptop-white/15inch/dell");
OneItem.put("description", "Just a sample description.");
OneItem.put("quantity_adjusted", 10);
OneItem.put("item_total", 244);
OneItem.put("unit", "qty");
OneItem.put("is_combo_product", false);
OneItem.put("adjustment_account_id", 4815000000000388);
OneItem.put("adjustment_account_name", "Cost of Goods Sold");
OneItem.put("warehouse_id", 4815000000000390);
OneItem.put("warehouse_name", "MyWarehouse");

//----------------------------------------------------
// Line_Items:
// Add the items(s) to a line_items Deluge List
//----------------------------------------------------
MyItems = List();
MyItems.add(OneItem);

//----------------------------------------------------
// Line_Items:
// Add the line_items Deluge List to the parametersMap
//----------------------------------------------------
parametersMap.put.("line_items", MyItems);

parametersMap.put("date",dateVal);
parametersMap.put("reason",reasonVal);
parametersMap.put("description",descriptionVal);
parametersMap.put("reference_number",referenceNumberVal);
parametersMap.put("adjustment_type",adjustmentTypeVal);

// Then call invokeurl
// - Include: parameters:parametersMap
//----------------------------------------------------
response = invokeurl
[
    url :"https://inventory.zoho.com/api/v1/inventoryadjustments?organization_id=xxxx"
    type :POST
    headers:headersMap
    parameters:parametersMap
];

// display the response
info response;

相关问题