I am still new to C# and API's in general. I've had no issues with this API until yesterday when I realized I wasn't getting all the data I was expecting in my response.
What I am trying to do is call this API link to get the JSON response then convert it to XML and save the document, which works perfect but there is a page-size limit on this endpoint.
There is a odata.nextLink in the response but I don't know how to use it.
What I have tried is "Searching" the response for the text string "odata.nextLink". I was able to search for that string and it gave me the value that I needed but I couldn't figure out how to use it in a do-while loop to append the data from each response.
Any help pointing me in the right direction would be much appreciated.
Here is the code I am using (Access_Token blocked out for security reasons)
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using Newtonsoft.Json;
using RestSharp;
namespace GetProducts
{
public class WebRequestGet
{
public static void Main()
{
var client = new RestClient("https://api.channeladvisor.com/v1/Products?access_token=*******************&$select=Sku,ID&$count=true");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
var content = response.Content;
string json = content;
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json, "Channeladvisor");
doc.Save(@"C:\Users\NHead\Documents\Visual Studio 2015\Projects\GetProducts\GetProducts\bin\Debug\Response.xml");
Console.WriteLine(content);
Console.ReadLine();
}
}
}
And here is the response I get before it gets converted to XML.
{
"@odata.context":"https://api.channeladvisor.com/v1/$metadata#Products(Sku,ID)","@odata.count":10728,"value":[
{
"Sku":"650SheetSets-P","ID":4932487
},{
"Sku":"400SheetSets-P","ID":4932488
},{
"Sku":"1500SheetSets-P","ID":4932489
},{
"Sku":"650TWSH SL WH","ID":4932510
},{
"Sku":"650TWSH SL BL","ID":4932511
},{
"Sku":"650TWSH SL GD","ID":4932512
},{
"Sku":"650TWSH SL MDBL","ID":4932513
},{
"Sku":"650TWSH SL IV","ID":4932514
},{
"Sku":"650TWSH SL BGY","ID":4932515
},{
"Sku":"650TWSH SL SKBL","ID":4932516
},{
"Sku":"650TWSH SL CHC","ID":4932517
},{
"Sku":"650TWSH SL SG","ID":4932518
},{
"Sku":"650TWSH SL TP","ID":4932519
},{
"Sku":"650SKSH SL WH","ID":4932520
},{
"Sku":"650SKSH SL BL","ID":4932521
},{
"Sku":"650SKSH SL GLD","ID":4932522
},{
"Sku":"650SKSH SL MDBL","ID":4932523
},{
"Sku":"650SKSH SL IV","ID":4932524
},{
"Sku":"650SKSH SL BGY","ID":4932525
},{
"Sku":"650SKSH SL SKBL","ID":4932526
},{
"Sku":"650SKSH SL CHC","ID":4932527
},{
"Sku":"650SKSH SL SG","ID":4932528
},{
"Sku":"650SKSH SL TP","ID":4932529
},{
"Sku":"650QNSH SL WH","ID":4932530
},{
"Sku":"650QNSH SL BL","ID":4932531
},{
"Sku":"650QNSH SL GLD","ID":4932532
},{
"Sku":"650QNSH SL MDBL","ID":4932533
},{
"Sku":"650QNSH SL IV","ID":4932534
},{
"Sku":"650QNSH SL BGY","ID":4932535
},{
"Sku":"650QNSH SL SKBL","ID":4932536
},{
"Sku":"650QNSH SL CHC","ID":4932537
},{
"Sku":"650QNSH SL SG","ID":4932538
},{
"Sku":"650QNSH SL TP","ID":4932539
},{
"Sku":"650KGSH SL WH","ID":4932540
},{
"Sku":"650KGSH SL BL","ID":4932541
},{
"Sku":"650KGSH SL GLD","ID":4932542
},{
"Sku":"650KGSH SL MDBL","ID":4932543
},{
"Sku":"650KGSH SL IV","ID":4932544
},{
"Sku":"650KGSH SL BGY","ID":4932545
},{
"Sku":"650KGSH SL SKBL","ID":4932546
},{
"Sku":"650KGSH SL CHC","ID":4932547
},{
"Sku":"650KGSH SL SG","ID":4932548
},{
"Sku":"650KGSH SL TP","ID":4932549
},{
"Sku":"650FLSH SL WH","ID":4932550
},{
"Sku":"650FLSH SL BL","ID":4932551
},{
"Sku":"650FLSH SL GLD","ID":4932552
},{
"Sku":"650FLSH SL MDBL","ID":4932553
},{
"Sku":"650FLSH SL IV","ID":4932554
},{
"Sku":"650FLSH SL BGY","ID":4932555
},{
"Sku":"650FLSH SL SKBL","ID":4932556
},{
"Sku":"650FLSH SL CHC","ID":4932557
},{
"Sku":"650FLSH SL SG","ID":4932558
},{
"Sku":"650FLSH SL TP","ID":4932559
},{
"Sku":"650CKSH SL WH","ID":4932560
},{
"Sku":"650CKSH SL BL","ID":4932561
},{
"Sku":"650CKSH SL GLD","ID":4932562
},{
"Sku":"650CKSH SL MDBL","ID":4932563
},{
"Sku":"650CKSH SL IV","ID":4932564
},{
"Sku":"650CKSH SL BGY","ID":4932565
},{
"Sku":"650CKSH SL SKBL","ID":4932566
},{
"Sku":"650CKSH SL CHC","ID":4932567
},{
"Sku":"650CKSH SL SG","ID":4932568
},{
"Sku":"650CKSH SL TP","ID":4932569
},{
"Sku":"400TWSH SL WH","ID":4932598
},{
"Sku":"400TWSH SL IV","ID":4932602
},{
"Sku":"400TWSH SL BGY","ID":4932603
},{
"Sku":"400TWSH SL SKBL","ID":4932604
},{
"Sku":"400TWSH SL SG","ID":4932605
},{
"Sku":"400TWSH SL CHC","ID":4932606
},{
"Sku":"400TWSH SL TP","ID":4932607
},{
"Sku":"400QNSH SL WH","ID":4932608
},{
"Sku":"400QNSH SL IV","ID":4932612
},{
"Sku":"400QNSH SL BGY","ID":4932613
},{
"Sku":"400QNSH SL SKBL","ID":4932614
},{
"Sku":"400QNSH SL CHC","ID":4932615
},{
"Sku":"400QNSH SL SG","ID":4932616
},{
"Sku":"400QNSH SL TP","ID":4932617
},{
"Sku":"400SKSH SL WH","ID":4932618
},{
"Sku":"400SKSH SL IV","ID":4932622
},{
"Sku":"400SKSH SL BGY","ID":4932623
},{
"Sku":"400SKSH SL SKBL","ID":4932624
},{
"Sku":"400SKSH SL CHC","ID":4932625
},{
"Sku":"400SKSH SL SG","ID":4932626
},{
"Sku":"400SKSH SL TP","ID":4932627
},{
"Sku":"400KGSH SL WH","ID":4932628
},{
"Sku":"400KGSH SL IV","ID":4932632
},{
"Sku":"400KGSH SL BGY","ID":4932633
},{
"Sku":"400KGSH SL SKBL","ID":4932634
},{
"Sku":"400KGSH SL CHC","ID":4932635
},{
"Sku":"400KGSH SL SG","ID":4932636
},{
"Sku":"400KGSH SL TP","ID":4932637
},{
"Sku":"400FLSH SL WH","ID":4932638
},{
"Sku":"400FLSH SL GLD","ID":4932640
},{
"Sku":"400FLSH SL IV","ID":4932642
},{
"Sku":"400FLSH SL BGY","ID":4932643
},{
"Sku":"400FLSH SL SKBL","ID":4932644
},{
"Sku":"400FLSH SL CHC","ID":4932645
},{
"Sku":"400FLSH SL SG","ID":4932646
},{
"Sku":"400FLSH SL TP","ID":4932647
},{
"Sku":"400CKSH SL WH","ID":4932648
}
],"@odata.nextLink":"https://api.channeladvisor.com/v1/Products?access_token=***************************************&$select=Sku%2CID&$count=true&$skip=100"
}
I think this might help you
But situation here is you need to read the value also of the nextLink. and thus you can use Newtonsoft to read it. But I see a point here is that in the nextLink it just adds
$skip=100
at the end of the URL. So I am assuming that if you have more data it would add$skip=200
next time and thus you could have a workaround without creating the classes to read the complete JSON