Gets the accountid by name.
curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts
-H "Accept: application/json" \
-H "OData-MaxVersion: 4.0" \
-H "OData-Version: 4.0" \
-d "$select=accountid" \
-d "$filter=name eq 'Blue Yonder Airlines'" \
-H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"
require 'chilkat'
rest = Chilkat::CkRest.new()
# URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/accounts
bTls = true
port = 443
bAutoReconnect = true
success = rest.Connect("my-dynamics-domain.api.crm.dynamics.com",port,bTls,bAutoReconnect)
if (success != true)
print "ConnectFailReason: " + rest.get_ConnectFailReason().to_s() + "\n";
print rest.lastErrorText() + "\n";
exit
end
rest.AddQueryParam("$select","accountid")
rest.AddQueryParam("$filter","name eq 'Blue Yonder Airlines'")
rest.AddHeader("OData-MaxVersion","4.0")
rest.AddHeader("Accept","application/json")
rest.AddHeader("OData-Version","4.0")
rest.AddHeader("Authorization","Bearer DYNAMICS_CRM_ACCESS_TOKEN")
sbResponseBody = Chilkat::CkStringBuilder.new()
success = rest.FullRequestNoBodySb("GET","/api/data/v9.0/accounts",sbResponseBody)
if (success != true)
print rest.lastErrorText() + "\n";
exit
end
respStatusCode = rest.get_ResponseStatusCode()
if (respStatusCode >= 400)
print "Response Status Code = " + respStatusCode.to_s() + "\n";
print "Response Header:" + "\n";
print rest.responseHeader() + "\n";
print "Response Body:" + "\n";
print sbResponseBody.getAsString() + "\n";
exit
end
jsonResponse = Chilkat::CkJsonObject.new()
jsonResponse.LoadSb(sbResponseBody)
odataContext = jsonResponse.stringOf("\"@odata.context\"")
i = 0
count_i = jsonResponse.SizeOfArray("value")
while i < count_i
jsonResponse.put_I(i)
odataEtag = jsonResponse.stringOf("value[i].\"@odata.etag\"")
accountid = jsonResponse.stringOf("value[i].accountid")
i = i + 1
end
{
"@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#accounts(accountid)",
"value": [
{
"@odata.etag": "W/\"1817216\"",
"accountid": "aca19cdd-88df-e311-b8e5-6c3be5a8b200"
}
]
}