Sample code for 30+ languages & platforms
Xbase++

SugarCRM Create a Record List

See more SugarCRM Examples

Create a record list in Sugar consisting of a set of ids.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL oJsonReq
LOCAL oSbReq
LOCAL oSbJson
LOCAL oJson
LOCAL cId
LOCAL cAssigned_user_id
LOCAL cModule_name
LOCAL cDate_modified
LOCAL i
LOCAL nCount_i
LOCAL cStrVal

nSuccess := 0

oRest := CreateObject("Chilkat.Rest")

nSuccess := oRest:Connect("your.site.domain", 443, 1, 1)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

oRest:AddHeader("Cache-Control", "no-cache")
oRest:AddHeader("OAuth-Token", "<access_token>")

//  The following code creates the JSON request body.
//  The JSON created by this code is shown below.
oJsonReq := CreateObject("Chilkat.JsonObject")
oJsonReq:UpdateString("records[0]", "f16760a4-3a52-f77d-1522-5703ca28925f")
oJsonReq:UpdateString("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"
//    ]
//  }

oSbReq := CreateObject("Chilkat.StringBuilder")
oJsonReq:EmitSb(oSbReq)

oRest:AddHeader("Content-Type", "application/json")

oSbJson := CreateObject("Chilkat.StringBuilder")
nSuccess := oRest:FullRequestSb("POST", "/rest/v10/Accounts/record_list", oSbReq, oSbJson)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oRest:destroy()
    oJsonReq:destroy()
    oSbReq:destroy()
    oSbJson:destroy()
    RETURN
ENDIF

IF (oRest:ResponseStatusCode != 200)
    ? "Received error response code: " + Str(oRest:ResponseStatusCode)
    ? "Response body:"
    ? oSbJson:GetAsString()
    oRest:destroy()
    oJsonReq:destroy()
    oSbReq:destroy()
    oSbJson:destroy()
    RETURN
ENDIF

oJson := CreateObject("Chilkat.JsonObject")
oJson:LoadSb(oSbJson)

//  The following code parses the JSON response.
//  A sample JSON response is shown below the sample code.

cId := oJson:StringOf("id")
cAssigned_user_id := oJson:StringOf("assigned_user_id")
cModule_name := oJson:StringOf("module_name")
cDate_modified := oJson:StringOf("date_modified")
i := 0
nCount_i := oJson:SizeOfArray("records")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("records[i]")
    i := i + 1
ENDDO

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

? "Example Completed."

oRest:destroy()
oJsonReq:destroy()
oSbReq:destroy()
oSbJson:destroy()
oJson:destroy()