How to use Walmart search API using .Net

I have integrated Walmart API into our HomeRP® application. If you are familiar with Amazon's product search API, then this will come as no surprise.

Walmart has following API that you can use for search.

Above request is the use of the API in its simplest form. You will provide your search phrase in query query parameter. This API has additional query parameters to refine the results.

  • start:Starting point of the results within the matching set of items - upto 10 items will be returned starting from this item
  • numItems :Number of matching items to be returned, max value 25. Default is 10.
  • sort:Sorting criteria, allowed sort types are [relevance, price, title, bestseller, customerRating, new]. Default sort is by relevance.
  • order:Sort ordering criteria, allowed values are [ascending, descending]. This parameter is needed only for the sort types [price, title, customerRating].

There are some additional query string parameter including above list. You can read about them on Walmart developer site. All query string parameters other then query are optional.

public SearchResults Search(string term, int startIndex = 1, int maxResults = 10)
                var httpClient = new HttpClient();
                var requestUri = new Uri($"{BaseUrl}search?query={term}&start={startIndex}&numItems={maxResults}");

                var getTask = Task.Run(async () => await httpClient.GetAsync(requestUri));
                var response = getTask.Result;
                var content = Task.Run(async () => await response.Content.ReadAsStringAsync());
                switch (response.StatusCode)
                    case HttpStatusCode.OK:
                        return JsonConvert.DeserializeObject<SearchResults>(content.Result);
                        _logger.Error("Walmart Api", $"Error searching by query: {response.StatusCode}: {content.Result}");
            catch (Exception ex)
                _logger.Error("Walmart Api", $"Error searching by query {term}", exception: ex);

            return null;

The API will return the results as JSON response. The details of this response can be found on following page.

Search Response Details




19.9 °C / 67.9 °F

weather conditions Clouds

Monthly Posts

Blog Tags