Getting 422 Unprocessable Conte

I am getting this error while fetching data from a model through POS UI extensions heres the code const [{ data, fetching, error: queryError }] = useFindMany( api.buyBackProduct, { pause: !ready, } );
No description
53 Replies
Ahmad Bilal
Ahmad BilalOP5mo ago
How can i changed the request url to a different environment
Chocci_Milk
Chocci_Milk5mo ago
Where you instantiate the client, you need to set the environment arguement. Have a look at these docs: https://docs.gadget.dev/api/example-app/development/external-api-calls/installing#connecting-to-a-specific-environment
Chocci_Milk
Chocci_Milk5mo ago
For example:
export const api = new Client({ environment: "development"})
export const api = new Client({ environment: "development"})
Ahmad Bilal
Ahmad BilalOP5mo ago
Actually this is set right as when i fetch it through app it return OK. But when i use Extensions to fetch data it gives me the above error
No description
Ahmad Bilal
Ahmad BilalOP5mo ago
Why its not working through extensions
No description
Chocci_Milk
Chocci_Milk5mo ago
Could you please show me how you instantiate in the extension? Please note that the extension doesn't have access to the current node_env
Ahmad Bilal
Ahmad BilalOP5mo ago
I just used this in a custom hook import { useApi } from "@shopify/ui-extensions-react/point-of-sale"; import { useFindMany } from "@gadgetinc/react"; Not sure where to initilize it
Chocci_Milk
Chocci_Milk5mo ago
Whats the name of your application?
Chocci_Milk
Chocci_Milk5mo ago
True, I could have taken it from the image Is this code from another extension or is it the theme app extension? If it's the theme app extension, React hooks and typical API calls won't work
Ahmad Bilal
Ahmad BilalOP5mo ago
Its POS UI extension
Chocci_Milk
Chocci_Milk5mo ago
Sorry, I should have been more clear. The extension you're working on doesn't seem to be in the application so I can't quickly look at the code and tell you whats wrong
Ahmad Bilal
Ahmad BilalOP5mo ago
Oh let me push Please check now
Chocci_Milk
Chocci_Milk5mo ago
Sidenote, you don't need to add these packages to your extension package.json:
No description
Chocci_Milk
Chocci_Milk5mo ago
Looks like this is your issue:
No description
Chocci_Milk
Chocci_Milk5mo ago
I don't think that isDevStore is ever set So you default to production
Ahmad Bilal
Ahmad BilalOP5mo ago
Yeah that was the case But now getting this GGT_INVALID_SHOPIFY_SESSION_TOKEN: Invalid Shopify Session Token passed in Authorization header, token could not be decoded"
Chocci_Milk
Chocci_Milk5mo ago
What dev store are you testing on? And should you be testing on the development env or ahmad-dev In your case you would probably want this:
export const api = new Client({
environment: "ahmad-dev"
})
export const api = new Client({
environment: "ahmad-dev"
})
Ahmad Bilal
Ahmad BilalOP5mo ago
Ahmed-dev
Chocci_Milk
Chocci_Milk5mo ago
And the store you're working on? Is it roadmap-ahmad.myshopify.com? Thats the only store that you have your application installed on, on your env
Ahmad Bilal
Ahmad BilalOP5mo ago
Yes Working on that store
Ahmad Bilal
Ahmad BilalOP5mo ago
Now getting this. Is it due to entry wasnt found?
No description
Ahmad Bilal
Ahmad BilalOP5mo ago
And is the request method correct? I am using the useFindMany hook
Chocci_Milk
Chocci_Milk5mo ago
Are you seeing any errors in the console or just in the network tab?
Ahmad Bilal
Ahmad BilalOP5mo ago
Console as well
Ahmad Bilal
Ahmad BilalOP5mo ago
No description
Ahmad Bilal
Ahmad BilalOP5mo ago
Should i use routes to fetch instead if possible? Whats the recommended approach here?
Chocci_Milk
Chocci_Milk5mo ago
I think that this is happening cause of something else
Ahmad Bilal
Ahmad BilalOP5mo ago
Like?
Chocci_Milk
Chocci_Milk5mo ago
Digging now Can I move some stuff around?
Ahmad Bilal
Ahmad BilalOP5mo ago
Sure
Chocci_Milk
Chocci_Milk5mo ago
Test that and see what you get
Ahmad Bilal
Ahmad BilalOP5mo ago
On it
Ahmad Bilal
Ahmad BilalOP5mo ago
Getting this now
No description
Chocci_Milk
Chocci_Milk5mo ago
Ok so I fixed the auth issues by changing the way that you set up the provider
Chocci_Milk
Chocci_Milk5mo ago
No description
Chocci_Milk
Chocci_Milk5mo ago
Thats why your current issue is happening
Chocci_Milk
Chocci_Milk5mo ago
No description
Ahmad Bilal
Ahmad BilalOP5mo ago
Yeah
Chocci_Milk
Chocci_Milk5mo ago
Let me change something
Ahmad Bilal
Ahmad BilalOP5mo ago
Ok
Chocci_Milk
Chocci_Milk5mo ago
Try it now The error might have actually hidden any other errors. We'll see Is everything working as expected?
Ahmad Bilal
Ahmad BilalOP5mo ago
No description
Chocci_Milk
Chocci_Milk5mo ago
Ok so I see a 401 there I feel like we're missing something LEt me tak a look at your backend logs
Ahmad Bilal
Ahmad BilalOP5mo ago
Sure
Chocci_Milk
Chocci_Milk5mo ago
What store is the extension running on right now? You might have selected the incorrect one when initializing shopify app dev. I'm just curious Interesting that I see a 530 error though
Ahmad Bilal
Ahmad BilalOP5mo ago
• Dev store: roadmap-ahmad.myshopify.com The store is right Did you find anything?
Chocci_Milk
Chocci_Milk5mo ago
Still digging
Ahmad Bilal
Ahmad BilalOP5mo ago
It worked
Chocci_Milk
Chocci_Milk5mo ago
Did you change something?
Ahmad Bilal
Ahmad BilalOP5mo ago
I changed the environment to ahmed-dev with your new code const api = new Client({ environment: "ahmad-dev", }); Thanks so much! For all the help!
Chocci_Milk
Chocci_Milk5mo ago
No problem!

Did you find this page helpful?