This example queries the accounts entity set and uses the $select system query option to return the name property for each account.
curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts?$select=name \
-H "Accept: application/json" \
-H "OData-MaxVersion: 4.0" \
-H "OData-Version: 4.0" \
-H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"
integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
integer i
integer li_Count_i
string ls_OdataContext
string ls_OdataEtag
string ls_Name
string ls_Accountid
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
// URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts?$select=name
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("my-dynamics-domain.api.crm.dynamics.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
loo_Rest.AddHeader("OData-MaxVersion","4.0")
loo_Rest.AddHeader("Accept","application/json")
loo_Rest.AddHeader("OData-Version","4.0")
loo_Rest.AddHeader("Authorization","Bearer DYNAMICS_CRM_ACCESS_TOKEN")
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")
li_Success = loo_Rest.FullRequestNoBodySb("GET","/api/data/v9.0/accounts?$select=name",loo_SbResponseBody)
if li_Success <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_SbResponseBody
return
end if
li_RespStatusCode = loo_Rest.ResponseStatusCode
if li_RespStatusCode >= 400 then
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
Write-Debug "Response Header:"
Write-Debug loo_Rest.ResponseHeader
Write-Debug "Response Body:"
Write-Debug loo_SbResponseBody.GetAsString()
destroy loo_Rest
destroy loo_SbResponseBody
return
end if
loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")
loo_JsonResponse.LoadSb(loo_SbResponseBody)
ls_OdataContext = loo_JsonResponse.StringOf("\"@odata.context\"")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("value")
do while i < li_Count_i
loo_JsonResponse.I = i
ls_OdataEtag = loo_JsonResponse.StringOf("value[i].\"@odata.etag\"")
ls_Name = loo_JsonResponse.StringOf("value[i].name")
ls_Accountid = loo_JsonResponse.StringOf("value[i].accountid")
i = i + 1
loop
destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_JsonResponse
{
"@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v8.2/$metadata#accounts(name)",
"value": [
{
"@odata.etag": "W/\"1817213\"",
"name": "A. Datum",
"accountid": "475b158c-541c-e511-80d3-3863bb347ba8"
},
{
"@odata.etag": "W/\"1817214\"",
"name": "Adventure Works",
"accountid": "a8a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817215\"",
"name": "Alpine Ski House",
"accountid": "aaa19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817216\"",
"name": "Blue Yonder Airlines",
"accountid": "aca19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817217\"",
"name": "City Power & Light",
"accountid": "aea19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817218\"",
"name": "Coho Winery",
"accountid": "b0a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817219\"",
"name": "Consolidated Messenger",
"accountid": "b2a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817220\"",
"name": "Fabrikam, Inc.",
"accountid": "b4a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817221\"",
"name": "Fourth Coffee",
"accountid": "b6a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817222\"",
"name": "Graphic Design Institute",
"accountid": "b8a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817223\"",
"name": "Humongous Insurance",
"accountid": "baa19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817224\"",
"name": "Litware",
"accountid": "bca19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817225\"",
"name": "Lucerne Publishing",
"accountid": "bea19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817226\"",
"name": "Margie's Travel",
"accountid": "c0a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817227\"",
"name": "Northwind Traders",
"accountid": "c2a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817228\"",
"name": "Proseware, Inc.",
"accountid": "c4a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817229\"",
"name": "School of Fine Art",
"accountid": "c6a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817230\"",
"name": "Southridge Video",
"accountid": "c8a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817231\"",
"name": "Tailspin Toys",
"accountid": "caa19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817232\"",
"name": "The Phone Company",
"accountid": "cca19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817233\"",
"name": "Trey Research",
"accountid": "cea19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817234\"",
"name": "Wide World Importers",
"accountid": "d0a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817235\"",
"name": "Wingtip Toys",
"accountid": "d2a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817236\"",
"name": "Woodgrove Bank",
"accountid": "d4a19cdd-88df-e311-b8e5-6c3be5a8b200"
},
{
"@odata.etag": "W/\"1817237\"",
"name": "Best o' Sales",
"accountid": "2123455d-be62-e411-80d6-b4b52f567ec8"
},
{
"@odata.etag": "W/\"1817238\"",
"name": "Microsoft",
"accountid": "d3ae1b3a-8bd2-e411-80ef-c4346bac7be8"
}
]
}