Lua
Lua
SugarCRM Create a Record List
See more SugarCRM Examples
Create a record list in Sugar consisting of a set of ids.Chilkat Lua Downloads
local chilkat = require("chilkat")
local rest = chilkat.Rest.new()
local success = rest:connect("your.site.domain", 443, true, true)
if not success then
print(rest.last_error_text)
return
end
rest:add_header("Cache-Control", "no-cache")
rest:add_header("OAuth-Token", "<access_token>")
-- The following code creates the JSON request body.
-- The JSON created by this code is shown below.
local jsonReq = chilkat.JsonObject.new()
jsonReq:update_string("records[0]", "f16760a4-3a52-f77d-1522-5703ca28925f")
jsonReq:update_string("records[1]", "ec409fbb-2b22-4f32-7fa1-5703caf78dc3")
-- The JSON request body created by the above code:
-- {
-- "records": [
-- "f16760a4-3a52-f77d-1522-5703ca28925f",
-- "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
-- ]
-- }
local sbReq = chilkat.StringBuilder.new()
jsonReq:emit_sb(sbReq)
rest:add_header("Content-Type", "application/json")
local sbJson = chilkat.StringBuilder.new()
success = rest:full_request_sb("POST", "/rest/v10/Accounts/record_list", sbReq, sbJson)
if not success then
print(rest.last_error_text)
return
end
if rest.response_status_code ~= 200 then
print("Received error response code: " .. rest.response_status_code)
print("Response body:")
print(sbJson:get_as_string())
return
end
local json = chilkat.JsonObject.new()
json:load_sb(sbJson)
-- The following code parses the JSON response.
-- A sample JSON response is shown below the sample code.
local strVal = ""
local id = json:string_of("id")
local assigned_user_id = json:string_of("assigned_user_id")
local module_name = json:string_of("module_name")
local date_modified = json:string_of("date_modified")
local i = 0
local count_i = json:size_of_array("records")
while i < count_i do
json.i = i
strVal = json:string_of("records[i]")
i = i + 1
end
-- A sample JSON response body that is parsed by the above code:
-- {
-- "id": "ef963176-4845-bc55-b03e-570430b4173c",
-- "assigned_user_id": "1",
-- "module_name": "Accounts",
-- "records": [
-- "f16760a4-3a52-f77d-1522-5703ca28925f",
-- "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
-- ],
-- "date_modified": "2016-04-05 21:39:19"
-- }
print("Example Completed.")