From 52e00cae33f15638c3e65170016617b08e44da9e Mon Sep 17 00:00:00 2001 From: sbansla Date: Mon, 6 Apr 2026 19:04:16 +0530 Subject: [PATCH 1/2] chore: added apistd pagination details --- src/Twilio/Base/Page.cs | 49 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/Twilio/Base/Page.cs b/src/Twilio/Base/Page.cs index 50b95e66e..3f7853932 100644 --- a/src/Twilio/Base/Page.cs +++ b/src/Twilio/Base/Page.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Xml; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Twilio.Rest; @@ -119,13 +120,35 @@ public bool HasNextPage() /// JSON payload /// Page of results public static Page FromJson(string recordKey, string json) + { + return FromJson(recordKey, json, null); + } + + /// + /// Converts a JSON payload to a Page of results + /// + /// JSON key where the records are + /// JSON payload + /// Original request URL, used for token-based pagination + /// Page of results + public static Page FromJson(string recordKey, string json, string requestUrl) { var root = JObject.Parse(json); var records = root[recordKey]; - var parsedRecords = records.Children().Select( - record => JsonConvert.DeserializeObject(record.ToString()) - ).ToList(); - + List parsedRecords; + if (records.Children().Any() && records.Children().First().Type != JTokenType.Object) + { + parsedRecords = records.Children().Select( + record => (T)System.Activator.CreateInstance(typeof(T), record.ToString()) + ).ToList(); + } + else + { + parsedRecords = records.Children().Select( + record => JsonConvert.DeserializeObject(record.ToString()) + ).ToList(); + } + if(root["uri"] != null){ var uriNode = root["uri"]; if (uriNode != null) @@ -147,9 +170,25 @@ record => JsonConvert.DeserializeObject(record.ToString()) } } - // next-gen API if(root["meta"] != null){ var meta = root["meta"]; + + // token-based pagination + if (meta["pageSize"] != null) + { + var nextToken = meta["nextToken"]?.Value(); + var previousToken = meta["previousToken"]?.Value(); + string baseUrl = requestUrl != null ? requestUrl.Split('?')[0] : null; + + return new Page( + parsedRecords, + meta["pageSize"].Value(), + nextPageUrl: nextToken != null && baseUrl != null ? baseUrl + "?pageToken=" + nextToken : null, + previousPageUrl: previousToken != null && baseUrl != null ? baseUrl + "?pageToken=" + previousToken : null + ); + } + + // next-gen API return new Page( parsedRecords, meta["page_size"].Value(), From 72100ae0adcee3b819a94c291b165623508d36bc Mon Sep 17 00:00:00 2001 From: sbansla Date: Mon, 6 Apr 2026 19:09:26 +0530 Subject: [PATCH 2/2] added domain --- src/Twilio/Rest/Domain.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Twilio/Rest/Domain.cs b/src/Twilio/Rest/Domain.cs index b15f1b510..602451563 100644 --- a/src/Twilio/Rest/Domain.cs +++ b/src/Twilio/Rest/Domain.cs @@ -42,6 +42,7 @@ public static implicit operator Domain(string value) public static readonly Domain Marketplace = new Domain("marketplace"); public static readonly Domain Messaging = new Domain("messaging"); public static readonly Domain Monitor = new Domain("monitor"); + public static readonly Domain Memory = new Domain("memory"); public static readonly Domain Notify = new Domain("notify"); public static readonly Domain Numbers = new Domain("numbers"); public static readonly Domain Oauth = new Domain("oauth");