[API] Invalid API key or access token (unrecognized login or wrong password

Topic summary

Issue: Creating a product via Shopify Admin API returned “[API] Invalid API key or access token (unrecognized login or wrong password),” while other endpoints (orders, products, etc.) worked with the same approach.

Context: ASP.NET + RestSharp; request Content-Type was application/json. Initial implementation passed the token as an “access_token” parameter and serialized the product directly (without wrapper).

Resolution: Adding the authentication header “X-Shopify-Access-Token: ” to the POST request enabled product creation. The JSON payload was also wrapped as { “product”: … } and included fields like title, body_html, vendor, product_type, and price.

Key detail: “X-Shopify-Access-Token” is the required header for authenticating Shopify Admin REST API requests, especially for write operations. Passing the token as a parameter was insufficient for this endpoint.

Outcome: Success after adding the header; reasons why other calls worked without it remain unclear.

Artifacts: Code snippets are central to the fix and show the header addition and proper JSON structure.

Status: Resolved; action item is to include the “X-Shopify-Access-Token” header for product creation (and likely other write requests).

Summarized with AI on February 18. AI used: gpt-5.

I’m using asp.net and restsharp to connect to the api.

The code i’m using can successfully get orders, products, complete orders, uncomplete orders and a lot of other functions.

However, i’m trying to add a product and getting the error: [API] Invalid API key or access token (unrecognized login or wrong password

Code here:

Public api_token = "APITOKENGOESHERE"
     Public api_client = New RestSharp.RestClient("https://MYSTORE.myshopify.com")
     Public base_api_path = "/admin/api/2022-04/"

     Dim api_path As String = base_api_path & "products.json"
     Dim api_request = New RestSharp.RestRequest(api_path, Method.POST)

     Dim product = New Product()
     product.Title = "TEST PRODUCT"
     product.body_html = "body here"
     product.vendor = "TESTING"
     Dim json_object = JsonConvert.SerializeObject(product)

     api_request.AddJsonBody(json_object)

     api_request.AddParameter("access_token", api_token)
     Dim api_response As New RestSharp.RestResponse
     api_response = api_client.Execute(api_request)
     Dim my_result_json = api_response.Content.ToString

The JSON generated seems fine, and i’m authenticating the same way i authenticate dozens of other api calls that all work fine. The header for the request is correctly showing as “application/json”.

Any ideas? do these requests authenticate in a completely different way to other requests?

Solution in case anyone has similar in future:

Public api_token = "APITOKENGOESHERE"
     Public api_client = New RestSharp.RestClient("https://MYSTORE.myshopify.com")
     Public base_api_path = "/admin/api/2022-04/"

     Dim api_path As String = base_api_path & "products.json"
     Dim api_request = New RestSharp.RestRequest(api_path, Method.POST)

     api_request.AddHeader("X-Shopify-Access-Token", api_token)

     Dim product = New Product()
     product.Title = "TEST PRODUCT"
     product.body_html = "body here"
     product.vendor = "TESTING"
     product.product_type = "TEST"
     product.price = "1"

     Dim json_object = " { ""product"": " & JsonConvert.SerializeObject(product) & " }"

     api_request.AddJsonBody(json_object)

     api_request.AddParameter("access_token", api_token)
     Dim api_response As New RestSharp.RestResponse
     api_response = api_client.Execute(api_request)
     Dim my_result_json = api_response.Content.ToString

Essentially this was the crux of it:

api_request.AddHeader("X-Shopify-Access-Token", api_token)

Why this function needs this, yet none of my other functions do - i don’t know. But, success!