Field 'collection' doesn't exist on type 'QueryRoot'

Solved
Highlighted
Excursionist
22 3 0

I can't figure out why my query doesn't work. I attached two screenshots below.

 

Screen Shot 2019-06-28 at 5.08.25 PM.png

 

In the docs under QueryRoot it clearly states collection as a field. it is right above collectionByHandle which is the first query in my screenshot that works:

 

Screen Shot 2019-06-28 at 5.10.21 PM.png

 

Any insight would be greatly appreciated. Thanks!

0 Likes
Excursionist
22 3 0

Nevermind, I think the issue is I was calling the storefront api but needed to be calling the admin api. Now I'm having a separate issue where I'm getting the following error: 

 

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

 

Here is my code if anyone has any insight:

 

$collection_handle = $_POST['collection_handle'];
$collection_id = $_POST['collection_id'];
$cursor = $_POST['cursor'];

$curl = curl_init('https://universal-auto-parts.myshopify.com/admin/api/2019-04/graphql.json');

$query = <<<'JSON'
query($collection_handle: String!) {
collectionByHandle(handle: $collection_handle) {
title
}
}
JSON;

$post_data = array();

$vars = array();

$vars['cursor'] = $cursor;
$vars['collection_handle'] = $collection_handle;
$vars['collection_id'] = $collection_id;

$post_data['query'] = $query;

$post_data['variables'] = $vars;

$post_data = json_encode($post_data);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-Shopify-Access-Token : <MY ACCESS TOKEN>')
);

$curl_response = curl_exec($curl);
curl_close($curl);

0 Likes
Shopify Partner
1665 51 184

Recheck your credentials , did you setup the app for the storefront api but need to redo for the admin api?


@Jackson_Behan1 wrote:

Nevermind, I think the issue is I was calling the storefront api but needed to be calling the admin api. Now I'm having a separate issue where I'm getting the following error: 

 

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


 

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Excursionist
22 3 0

I don't believe these questions are relevant because the credentials are correct but I'm curious anyway: Why would I have to re do it for the admin api? How do I even re do the admin api credentials?

 

I have 4 screenshots below of calls to the storefront api and the admin api. Each call is calling the same thing, getting a collection by it's handle.

One is a call to the storefront api using curl in the terminal which works.

The second is a call to the storefront api using curl in php which works.

The third is a call to the admin api using curl in the terminal which works.

The last is a call to the admin api using curl in php which does not work and returns: "[API] Invalid API key or access token (unrecognized login or wrong password)"

 

storefront api using curl in the terminal:

storefront-api-curl.png

 

storefront api using curl in php:

storefront-api-php-curl.png

 

admin api using curl:

admin-api-curl.png

 

admin api using curl in php, throws error: "[API] Invalid API key or access token (unrecognized login or wrong password)"

admin-api-php-curl.png

 

Thanks for your help

0 Likes
Shopify Partner
1665 51 184

That is strange the last combination doesn't work.

The last call using curl-in-php might be an env issue? either echo out the auth token or inspect the request being sent and verify the tokens.

What happens if the key:password is passed in the url instead?

What happens if the query is empty?

And maybe if it's a private app recheck the private apps config for access to products /shrug

If it's a "public" app , then oauth handshake is needed https://help.shopify.com/en/api/getting-started/authentication/oauth


@Jackson_Behan1 wrote:

I don't believe these questions are relevant because the credentials are correct.

In the second post there's a confusion between the two apis:

Nevermind, I think the issue is I was calling the storefront api but needed to be calling the admin api....


Thus a reminder to do a full recheck of the credentials configuration is the first step to troubleshoot "[API] Invalid API key or access token (unrecognized login or wrong password)"

 


@Jackson_Behan1 wrote:

Why would I have to re do it for the admin api? 


If it's a private app you have to enable access for different permissions, so if you only enabled the storefront permissions you'd need to go back into and set the permissions for that admin api in the private app as part of troubleshooting.

 

 

 

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Excursionist
22 3 0

It is not an env issue because when I am testing I am hardcoding the tokens in. In my screenshots I just take them out.

If I use key:password instead of just the password I get the same error.

If the query is empty I get the same error.

 

It is a private app and I have all api permissions enabled:

permissions-1.pngpermissions-2.pngpermissions-3.png

 

 

Here is a screenshot of the admin api credentials section. I am using the password for the access token:

credentials.png

0 Likes
Shopify Partner
1665 51 184

FYI: as a matter of practice please censor all sensitive data in images as it's not uncommon for  scrapers to also now OCR.

Recommend you delete that last image.


@Jackson_Behan1 wrote:

It is not an env issue because when I am testing I am hardcoding the tokens in.


Oops, apologies I meant not just env variables but also the environment itself: version,requests, print_r($_REQUEST),  setting curl to verbose,user-agent ,etc.

 

After that if the env is good, and the request and tokens are aren't giving clues for the problem, ummm Idk what to tell you.

Very frustrating.

 

Next steps get more and more involved, unless someone else has some insight like we're missing a typo, config issue, or some other small thing.

Steps such as redoing the php and api setup from scratch for reproducibility, then if it still fails do it again but on another system.

Or sharing|containerizing the setup for someone else to try and replicate the issue with their keys /shrug.

 

 

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Excursionist
22 3 0

How do I edit a previous post? I can't find anything.

0 Likes

Success.

Excursionist
22 3 0

wow, I found it. Basically a typo.

 

I have a space between X-Shopify-Access-Token and the colon after.

 

4 days off from looking at it and boom find the problem in a few minutes lol.

 

Sorry to waste your time and thank you for helping. 

 

I can't figure out how to edit a previous post though and delete that screenshot.

0 Likes
Shopify Partner
1665 51 184

Typical isn't it 🤦‍♂️🤣, no worries not really a waste of time just more information for the troubleshooting, and anyone making a linter.

 


@Jackson_Behan1 wrote:

I can't figure out how to edit a previous post though and delete that screenshot.


Should be in the dropdown(...) but the window to edit posts is reeeeeally small for some stupid reason.

Contact communitymailer@shopify.com or at least redo all app setup to change tokens if this is ever going to production.

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes