Basic Admin API operations with PowerShell

Just trying to get authenticated and pull some basic data. I configured an app in the admin panel and have the API token. The code below is what I’m working with. I keep getting “errors: not found” with any query. I’m using the GraphiQL app to validate my queries but nothing seems to work.

Anyone have any idea what I’m doing wrong?

# Define your Shopify store and API token
$shopName = "myshop"
$apiToken = "myKey"

# Define the GraphQL endpoint
$graphqlEndpoint = "https://$shopName.myshopify.com/admin/api/2024-10/graphql.json"

# Define your GraphQL query
$query = @"
{
  shop {
    name
  }
}
"@

# Create the HTTP request headers
$headers = @{
    "Content-Type"           = "application/json"
    "X-Shopify-Access-Token" = $apiToken
}

# Create the HTTP request body
$body = @{
    query = $query
} | ConvertTo-Json

# Make the HTTP POST request
$response = Invoke-RestMethod -Uri $graphqlEndpoint -Method Post -Headers $headers -Body $body

# Output the response
$response

I am not familiar with Powershell, however, I do know that the error you are seeing is one you will get when the URL is not correct. And so my hypothesis is that either the shop name is incorrect or that the script is doing something to mangle the URL. I say that because this part “myshopify.com/admin/api/2024-10/graphql.json” of the URL is correct.

Have you tried using an even simpler client such as Postman to first make sure that you can get results?

Have not used Postman, will have to figure that out. Is there somewhere in the admin console to validate what the url should be? I was just using the actual shop url.

Could you try a different call with Curl from Terminal, eg:

curl -X GET "https://store-name.myshopify.com/admin/api/2024-10/orders.json?status=open&limit=5" -H "X-Shopify-Access-Token: {YOUR_ACCESS_TOKEN}"

(assuming your private app has read_orders scope)

and the store name would be what you’d see here:

For anyone reading this trying to get a PowerShell call to work. Use the default shop url that is created when you open the shop. I was trying to use the domain I added.

Shopify creates something like ‘3e4698-df.shopify’. I added myshop dot com as an allowed domain in the admin panel. The failure is because I was using myshop.myshopify.com/admin/api/2024-10/graphql.json. Use the default url value and the code works.

Thanks @Liam-Shopify