Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Id
string ls_Name
string ls_Date_modified
string ls_Industry
string ls_Email1
string ls_V_module

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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

loo_Http.SetRequestHeader("Cache-Control","no-cache")
loo_Http.SetRequestHeader("OAuth-Token","<access_token>")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("http://<site_url>/rest/v10/Accounts/<record_id>?fields=name,email1,industry",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

// 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

ls_Id = loo_JResp.StringOf("id")
ls_Name = loo_JResp.StringOf("name")
ls_Date_modified = loo_JResp.StringOf("date_modified")
ls_Industry = loo_JResp.StringOf("industry")
ls_Email1 = loo_JResp.StringOf("email1")
ls_V_module = loo_JResp.StringOf("_module")


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp