Return Only Specific Statuses From Woo Commerce API
Budget: $10 – $30 USD
0
I am trying to utilize the WooCommerce API and return only two specific statuses using RestSharp. My issue is that when my code executes my variable orders has over 8,000 entries, and I expect it to only have around 550. What have I set-up incorrectly in this code? How do I fix?
Enumerable<WooCommerceApiResponse> orders = await GetAllOrders(e);
async Task<IEnumerable<WooCommerceApiResponse>> GetAllOrders(string manager)
{
RestClient restClient = await WooCommerceRestClient(manager);
List<WooCommerceApiResponse> response = new List<WooCommerceApiResponse>();
RestRequest restRequest = new RestRequest($"{OrdersApiEndpoint}&page=1&status=processed,completed”);
response = await restClient.GetAsync<List<WooCommerceApiResponse>>(restRequest);
var result = restClient.Get(restRequest);
int pageCount = Convert.ToInt32(result.Headers.FirstOrDefault(f => f.Name == "X-Wp-Totalpages").Value);
for (int i = 1; i <= pageCount; i++)
{
restRequest = new RestRequest($"{OrdersApiEndpoint}&page={i}");
var res = await restClient.GetAsync<List<WooCommerceApiResponse>>(restRequest);
response.AddRange(res);
}
return response;
}
if needed this is a link to the API documentation:
https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-orders
I am trying to utilize the WooCommerce API and return only two specific statuses using RestSharp. My issue is that when my code executes my variable orders has over 8,000 entries, and I expect it to only have around 550. What have I set-up incorrectly in this code? How do I fix?
Enumerable<WooCommerceApiResponse> orders = await GetAllOrders(e);
async Task<IEnumerable<WooCommerceApiResponse>> GetAllOrders(string manager)
{
RestClient restClient = await WooCommerceRestClient(manager);
List<WooCommerceApiResponse> response = new List<WooCommerceApiResponse>();
RestRequest restRequest = new RestRequest($"{OrdersApiEndpoint}&page=1&status=processed,completed”);
response = await restClient.GetAsync<List<WooCommerceApiResponse>>(restRequest);
var result = restClient.Get(restRequest);
int pageCount = Convert.ToInt32(result.Headers.FirstOrDefault(f => f.Name == "X-Wp-Totalpages").Value);
for (int i = 1; i <= pageCount; i++)
{
restRequest = new RestRequest($"{OrdersApiEndpoint}&page={i}");
var res = await restClient.GetAsync<List<WooCommerceApiResponse>>(restRequest);
response.AddRange(res);
}
return response;
}
if needed this is a link to the API documentation:
https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-orders