title: Any examples of getnextpage usage in the twilio api for c#?
body: <p>The old code I've inherited for Twilio retrieves messages using the absolute PageNumber property of the MessageListRequest but according to the documentation this is obsolete and I should be using GetNextPage and GetPrevPage.</p>
  
  <p>The API metadata shows this as obsolete with the message "Use GetNextPage and GetPreviousPage for paging. Page parameter is scheduled for end of life <a href="https://www.twilio.com/engineering/2015/04/16/replacing-absolute-paging-with-relative-paging" rel="nofollow">https://www.twilio.com/engineering/2015/04/16/replacing-absolute-paging-with-relative-paging</a>".</p>
  
  <p>Are there any examples of this usage? I couldn't find any in the documentation except in one of the API test methods and I'm not sure how well I can get to processing multiple pages with this example as a guide.</p>
  
  <pre><code>public class Foo : TwilioBase
  {
      public string Bar { get; set; }
  }
  
  public class FooResult : TwilioListBase
  {
      public List&lt;Foo&gt; Foos { get; set; }
  }
  [Test]
  public void ShouldGetNextPage()
  {
      IRestRequest savedRequest = null;
  
      FooResult firstPage = new FooResult();
      firstPage.NextPageUri = new Uri("/Foos?PageToken=abc123", UriKind.Relative);
  
      mockClient.Setup(trc =&gt; trc.Execute&lt;FooResult&gt;(It.IsAny&lt;IRestRequest&gt;()))
          .Callback&lt;IRestRequest&gt;((request) =&gt; savedRequest = request)
          .Returns(new FooResult());
      var client = mockClient.Object;
  
      var response = client.GetNextPage&lt;FooResult&gt;(firstPage);
  
      mockClient.Verify(trc =&gt; trc.Execute&lt;FooResult&gt;(It.IsAny&lt;IRestRequest&gt;()), Times.Once);
      Assert.IsNotNull(savedRequest);
      Assert.AreEqual("/Foos?PageToken=abc123", savedRequest.Resource);
      Assert.AreEqual(Method.GET, savedRequest.Method);
  
      Assert.IsNotNull(response);
  }
  </code></pre>
  
  <p>The old usage might look something like so:</p>
  
  <pre><code>var twilio = new TwilioRestClient(config.AccountSid, config.AuthToken);
  var result = new List&lt;Message&gt;();
  MessageResult tempResult;
  int page = 0;
  do
  {
      var request = new MessageListRequest();
      request = new MessageListRequest { Count = 1000, DateSent = newestDate, DateSentComparison = ComparisonType.GreaterThanOrEqualTo, PageNumber = page++, To = config.FromNumber };
  
      tempResult = twilio.ListMessages(request);
      result.AddRange(tempResult.Messages);
  } while (tempResult.NextPageUri != null);
  </code></pre>
  
  <p>Finally, I built the Twilio API 3.4.1.0 from the <a href="https://github.com/twilio/twilio-csharp" rel="nofollow">twilio-csharp GitHub project</a> instead of NuGet since I need to update it to use the MessagingServiceSid which isn't included in the API yet.</p>
  
  <p>Thanks for any pointers. I'll post a solution if I can figure it out on my own.</p>