"The Tackifier" Blog by FindTape

"The Tackifier" Blog by FindTape

Adhesive tape news, issues and commentary

NAVIGATION - SEARCH

C#: Walmart oAuth-based authentication API transition from digital signature-based authentication

Had to switch over to using Walmart's new oAuth-based authentication to generate an access token for integration into their Seller Center API. Had to piece together information from a few web sources so figured would post our request code here in case anyone else had to do the same.

string uri = "https://marketplace.walmartapis.com/v3/token";

HttpClient client = new HttpClient();

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(CLIENT_ID + ":" + CLIENT_SECRET)));

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("WM_SVC.NAME", "Walmart Marketplace");
client.DefaultRequestHeaders.Add("WM_QOS.CORRELATION_ID", System.Guid.NewGuid().ToString()); //any random ID
client.DefaultRequestHeaders.Add("WM_SVC.VERSION", "1.0.0");

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri);

List<KeyValuePair<string, string>> lstKVs = new List<KeyValuePair<string, string>>();
lstKVs.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));
request.Content = new FormUrlEncodedContent(lstKVs);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");