Sample code for 30+ languages & platforms
AutoIt

SugarCRM Create a Record List

See more SugarCRM Examples

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

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oRest = ObjCreate("Chilkat.Rest")

$bSuccess = $oRest.Connect("your.site.domain",443,True,True)
If ($bSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
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 = ObjCreate("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 = ObjCreate("Chilkat.StringBuilder")
$oJsonReq.EmitSb($oSbReq)

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

$oSbJson = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oRest.FullRequestSb("POST","/rest/v10/Accounts/record_list",$oSbReq,$oSbJson)
If ($bSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

If ($oRest.ResponseStatusCode <> 200) Then
    ConsoleWrite("Received error response code: " & $oRest.ResponseStatusCode & @CRLF)
    ConsoleWrite("Response body:" & @CRLF)
    ConsoleWrite($oSbJson.GetAsString() & @CRLF)
    Exit
EndIf

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.LoadSb($oSbJson)

; The following code parses the JSON response.
; A sample JSON response is shown below the sample code.
Local $sId
Local $sAssigned_user_id
Local $sModule_name
Local $sDate_modified
Local $i
Local $iCount_i
Local $strVal

$sId = $oJson.StringOf("id")
$sAssigned_user_id = $oJson.StringOf("assigned_user_id")
$sModule_name = $oJson.StringOf("module_name")
$sDate_modified = $oJson.StringOf("date_modified")
$i = 0
$iCount_i = $oJson.SizeOfArray("records")
While $i < $iCount_i
    $oJson.I = $i
    $strVal = $oJson.StringOf("records[i]")
    $i = $i + 1
Wend

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

ConsoleWrite("Example Completed." & @CRLF)