How to use Walmart API to find store locations

In this post, I will share code snippet from our HomeRP® portal where we integrate Walmart API for locating stores. You will have to send following GET request to Walmart services to get one or more stores based on the search query parameters.

You can append following query parameters to this URL to refine your search.

  • city: Name of nearest city
  • zip: Postal code of nearest city
  • lon: Longitude of nearest city location
  • lat: Latitude of nearest city location

Although the documentation says that all query parameters are optional, it is not true. You have to specify at least one of the parameters. Walmart does not allow an open search of store locations by not specifying any parameter. Omitting query parameters will complete the request but no results will be returned. Following code snippet shows .Net code that send a request to Walmart service. I use Store class that is used to deserialize JSON response into typed object.

public IList FindStores(string city = "", string state = "", 
         string postalCode = "", int? longitude = null, int? latitude = null) 
                var httpClient = new HttpClient();
                var requestUri = $"{BaseUrl}stores";
                if (!string.IsNullOrEmpty(city)) { requestUri += $"?city={city.Trim()}"; }
                if (!string.IsNullOrEmpty(postalCode)) { requestUri += $"?zip={postalCode.Trim()}"; }
                if (longitude.HasValue) { requestUri += $"?lon={longitude}"; }
                if (latitude.HasValue) { requestUri += $"?lat={latitude}"; }

                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<IList<Store>>(content.Result);
                        _logger.Error("Walmart Api", 
                              $"Error finding store: {response.StatusCode}: {content.Result}");
            catch (Exception ex)
                _logger.Error("Walmart Api", $"Error finding store", exception: ex);

            return new List<Store>();

public class Store
        public int Id { get; set; }
        public string Name { get; set; }
        public string Country { get; set; }
        public string[] Coordinates { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string PostalCode { get; set; }
        public string Phone { get; set; }




3.1 °C / 37.6 °F

weather conditions Clouds

Monthly Posts

Blog Tags