Re: Error "Shopify Remix Extension - API POST Call Not Working but Works on Admin Side"

Error "Shopify Remix Extension - API POST Call Not Working but Works on Admin Side"

Iamumar12
Shopify Partner
5 0 0

I'm working on Shopify Remix, but the API POST call is not working on the extension side. However, the same API call works fine on the admin side. I've attached my code below. Can you suggest a solution?
Response 
Bad request
No host provided

Replies 5 (5)

Blackpent
Shopify Partner
11 0 1

Hello!

Sorry, where is the code you've attached? 😶

Iamumar12
Shopify Partner
5 0 0

this is my code 

Blackpent
Shopify Partner
11 0 1

In the attached file indicated at the end:

" this is an error show "
"Request URL:"
"https://viral-hms.myshopify.com/apps/proxy/notify"
"Request Method:"
"POST"
"Status Code:"
"400 Bad Request"
""
"Response"
"No host provided"


It seems that the URL configured to be proxied by Shopify is wrong or the destination address is not right.

I'd start checking those values.

Iamumar12
Shopify Partner
5 0 0

My API URL is correct, but it's giving a 400 error. If the API URL is not correct, it should throw a 404 error. Sometimes I get a 500 error, and sometimes I get a 400 error. Please guide me a little more.
And on the admin side, when I make the call, it works perfectly fine, but on the frontend (extension side), the API is not working

Blackpent
Shopify Partner
11 0 1

I think I've faced a similar problem but not with the remix framework, just with Javascript and React, when delivering requests from the extension to the backend.

 

You said that on the admin side is working but not on the extension side, so you are using the same path for the call, right?

As you can see the error is complaining about the "host". This parameter is expected for the Shopify middleware that authenticates the session. But from the proxy, this process is different (at the moment I faced the problem)

 

In my case, to avoid this problem, I used different base-paths for admin requests, and proxy requests: "/api" and "/api_proxy/".  So the middleware for "admin-request" does not try to authenticate the request from the extensions. 

Nevertheless, incoming requests from the proxy must include another different middleware o method to validate its origin. 

Check this doc: https://shopify.dev/docs/api/shopify-app-remix/v2/authenticate/public/app-proxy