Find a contactid given a fullname.
curl -X GET https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/contacts
-H "Accept: application/json" \
-H "OData-MaxVersion: 4.0" \
-H "OData-Version: 4.0" \
-d "$select=contactid" \
-d "$filter=fullname eq 'Tomasz Bochenek'" \
-H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN"
var
rest: TChilkatRest;
success: Integer;
bTls: Integer;
port: Integer;
bAutoReconnect: Integer;
sbResponseBody: TChilkatStringBuilder;
respStatusCode: Integer;
jsonResponse: TChilkatJsonObject;
i: Integer;
count_i: Integer;
odataContext: WideString;
odataEtag: WideString;
contactid: WideString;
begin
rest := TChilkatRest.Create(Self);
// URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/contacts
bTls := 1;
port := 443;
bAutoReconnect := 1;
success := rest.Connect('my-dynamics-domain.api.crm.dynamics.com',port,bTls,bAutoReconnect);
if (success <> 1) then
begin
Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(rest.ConnectFailReason));
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
rest.AddQueryParam('$select','contactid');
rest.AddQueryParam('$filter','fullname eq ''Tomasz Bochenek''');
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 := TChilkatStringBuilder.Create(Self);
success := rest.FullRequestNoBodySb('GET','/api/data/v9.0/contacts',sbResponseBody.ControlInterface);
if (success <> 1) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
respStatusCode := rest.ResponseStatusCode;
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(rest.ResponseHeader);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(sbResponseBody.GetAsString());
Exit;
end;
jsonResponse := TChilkatJsonObject.Create(Self);
jsonResponse.LoadSb(sbResponseBody.ControlInterface);
odataContext := jsonResponse.StringOf('"@odata.context"');
i := 0;
count_i := jsonResponse.SizeOfArray('value');
while i < count_i do
begin
jsonResponse.I := i;
odataEtag := jsonResponse.StringOf('value[i]."@odata.etag"');
contactid := jsonResponse.StringOf('value[i].contactid');
i := i + 1;
end;
{
"@odata.context": "https://mydomain.api.crm.dynamics.com/api/data/v9.0/$metadata#contacts(contactid)",
"value": [
{
"@odata.etag": "W/\"1162210\"",
"contactid": "1fa1e5b9-88df-e311-b8e5-6c3be5a8b200"
}
]
}