Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hello all,
I am trying to write some C# code to update content on a Shopify page in my store. When I use https://{apiKey}:{apiPassword}@phytools1.myshopify.com/admin/api/2023-01/pages/103974338796.json, I can retrieve the page information. However, when I use the following C# code, I get a 401 unauthorized error. The only API credentials that I show on my Custom App in my Shopify Admin are (Admin API access token, API key, API secret key). Any help is apreciated.
using (var client = new HttpClient())
{
client.BaseAddress = new Uri($"https://phytools1.myshopify.com/admin/api/2023-01/");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{apiKey}:{apiPassword}")));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.PutAsync($"pages/{pageId}.json",
new StringContent(jsonPayload, Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine($"New page created successfully: {responseContent}");
}
else
{
Console.WriteLine($"Error creating page: {response.StatusCode}");
}
}
Solved! Go to the solution
This is an accepted solution.
I think you need to use the accesstoken using the header X-Shopify-Access-Token instead of basic authentication.
Cheers,
Gary
This is an accepted solution.
I think you need to use the accesstoken using the header X-Shopify-Access-Token instead of basic authentication.
Cheers,
Gary