Sample code for 30+ languages & platforms
Lua

SugarCRM Getting a Record

See more SugarCRM Examples

Gets a record from the Sugar instance using the //:record endpoint. In this example we get an Account record by it's ID, but only request the Name, Email, and Industry fields.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl -H OAuth-Token:<access_token> -H Cache-Control:no-cache http://<site_url>/rest/v10/Accounts/<record_id>?fields=name,email1,industry

http:set_request_header("Cache-Control", "no-cache")
http:set_request_header("OAuth-Token", "<access_token>")

local sbResponseBody = chilkat.StringBuilder.new()
local success = http:quick_get_sb("http://<site_url>/rest/v10/Accounts/<record_id>?fields=name,email1,industry", sbResponseBody)
if not success then
    print(http.last_error_text)
    return
end

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(http.last_header)
    print("Failed.")
    return
end

-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "id": "ab2222df-73da-0e92-6887-5705428f4d68",
--   "name": "Test Record",
--   "date_modified": "2016-04-06T15:03:21-04:00",
--   "industry": "",
--   "email1": "test@sugar.com",
--   "_acl": {
--     "fields": {}
--   },
--   "_module": "Accounts"
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local id = jResp:string_of("id")
local name = jResp:string_of("name")
local date_modified = jResp:string_of("date_modified")
local industry = jResp:string_of("industry")
local email1 = jResp:string_of("email1")
local v_module = jResp:string_of("_module")