Reputation: 3111
I have the following piece of code that retrieves transactions from a Dynamics CRM (querying with OData):
public async Task<IEnumerable<Transaccion>> GetTransactions()
{
var tableName = Transaccion.CrmTableName;
var request = new RestRequest($"/api/data/v8.0/{tableName}");
request.AddHeader("Prefer", "odata.maxpagesize=500");
var responseData = await client.ExecuteGetTaskAsync<ODataResponse<List<Transaccion>>>(request);
var transactions = responseData.Data.Value;
while (responseData.Data.NextLink != null)
{
request = new RestRequest(responseData.Data.NextLink);
request.AddHeader("Prefer", "odata.maxpagesize=500");
responseData = await client.ExecuteGetTaskAsync<ODataResponse<List<Transaccion>>>(request);
transactions.AddRange(responseData.Data.Value);
}
return transactions;
}
once I execute the first "ExecuteGetTaskAsync", I get for my example and as expected a NextLink attribute that points to the next set of entities that I need to retrieve. However, when I try to perform the next RestRequest, I don't get a JSON as response, but a Html page corresponding to a redirect, where I can read the error message "".
It's weird, since the first call could be made correctly because the Restclient was correctly authenticated.
What's going on? How can I do paging with Dynamics CRM in .Net and use the NextLink?
Upvotes: 3
Views: 2866
Reputation: 73
In my case URL in @odata.nextLink was with an error.
How it was:
http://[Organization URI]/api/data/v8.2/[entity]/(68e95f08-d372-e711-966b-defe0719ce9e)/[relation entity]?$select=ne_name
And that did not work, but this did:
http://[Organization URI]/api/data/v8.2/[entity](68e95f08-d372-e711-966b-defe0719ce9e)/[relation entity]?$select=ne_name
There is no "/" between [entity] and (id)
Upvotes: 2
Reputation: 1
The odada nextlink returns the full URL of the next request so you'll need to parse it to get only the /api/** portion.
Upvotes: 0