using System; using System.Net.Http; using System.Net.Http.Headers; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace Content1FetchExample { class Program { static async Task Main(string[] args) { // Replace these values with your actual credentials var userGLN = "{{your GLN}}"; var appID = "{{your appid}}"; var secretKey = "{{your secret key}}"; var pageSize = "1"; // Default is 1000, max is 1000 var timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); var uri = $"/V1/product/fetch?timestamp={timestamp}&pageSize={pageSize}"; var encoding = Encoding.UTF8; using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("https://content1-api.1worldsync.com"); httpClient.DefaultRequestHeaders.Add("appId", appID); // Create a JSON content with an empty body string jsonString = "{ \"targetMarket\": \"US\" }"; var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); // Calculate the HMACSHA256 hash using (var hmac = new HMACSHA256(encoding.GetBytes(secretKey))) { var hashBytes = hmac.ComputeHash(encoding.GetBytes(uri)); var hashInBase64 = Convert.ToBase64String(hashBytes); httpClient.DefaultRequestHeaders.Add("hashcode", hashInBase64); } var response = await httpClient.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var responseContent = await response.Content.ReadAsStringAsync(); Console.WriteLine("Response:"); Console.WriteLine(responseContent); } else { Console.WriteLine($"HTTP Error: {response.StatusCode} - {response.ReasonPhrase}"); } } } } }