Redirect after creating recurring application charge does not contain host name as query

Solved
Flafi87
Tourist
7 1 2

Hello,

I started to update applications(Next,React) to use the new Appbridge v2. During testing it turned out when I am creating the recurring application charge and making redirect at the end with the received confirmationUrl as before the query only contains shopOrigin and chargeID, and not host. I am trying to get the host as the shopOrigin, so in the getInitialProps at the frontend. Later when I am opening app from the admin panel it works fine. Did I miss something?

0 Likes
NabeelAhsen
Shopify Staff
Shopify Staff
5 2 2

Hi there, I'm trying to gather a little more information.

A recurring application charge returns a "confirmation_url" that usually looks something like "https://{shop}/admin/charges/{charge_id}/confirm_recurring_application_charge?signature={signature}".

A shopOrigin or host parameter would be mostly be useful on the "return_url" or "decorated_return_url" return parameters so that the app can use these parameters to initialize app bridge. Could you confirm that you originally received the shopOrigin on the "confirmation_url" instead?

Thanks!

0 Likes
Flafi87
Tourist
7 1 2

Hello,

Thank you for the fast response! I was superficial.

The application is fully following the tutorial on shopify website https://github.com/Shopify/shopify-app-node 

What I can see is after the charge is created there is a redirect to "/?charge_id=123456789&shop=xxxxxxx.myshopify.com".

With previous versions of AppBridge it was enough and it was working because for the provider shop parameter was available for shopOrigin.

There was a reload after that and the application was shown correctly inside the admin panel and I can see there is the correct call with all parameters.See below

"/?charge_id=123456789&hmac=xxx&host=xxx&locale=en-US&new_design_language=true&session=xxx&shop=xxxxxxxxx.myshopify.com&timestamp=1620761749"

But now because the first redirect is not containing host parameter the App stuck with error that host is missing for Provider.

0 Likes
NabeelAhsen
Shopify Staff
Shopify Staff
5 2 2

Thanks for the additional info!

Are you able to share details on the "return_url" that your app specifies on the body when making the POST request to create a new recurring application charge? Does your app include any query/search parameters on this "return_url"?
See the "Endpoints" section for more clarity on what I'm referring to: https://shopify.dev/docs/admin-api/rest/reference/billing/recurringapplicationcharge

This information will be useful when investigating a fix for this!

0 Likes
Flafi87
Tourist
7 1 2

Yes, it is containing the shop as a query parameter as it is in the tutorial.

 https://github.com/Shopify/shopify-app-node/blob/d30e9bcd552372a6997233439ed74847e625a33f/server.js#... 

0 Likes
NabeelAhsen
Shopify Staff
Shopify Staff
5 2 2

This is an accepted solution.

Just to follow up on this, thanks for flagging this discrepancy! From what I'm aware, our libraries are beginning to roll out support for App Bridge 2.x. In the meantime, here's some information that may help you get unstuck if you're still running into this issue.

1. Most URLs built by Shopify that target your app have the "host" parameter included as a query parameter
2. This includes the URLs that are built to embed your app and the URLs built when finishing the OAuth flow. 

Knowing this, it's possible to extract the previously ignored "host" parameter where relevant and add it to your "returnUrl" parameter. I drafted and tested this commit to demo one way of doing this.

https://github.com/Shopify/shopify-app-node/compare/d30e9bcd552372a6997233439ed74847e625a33f...nabee...

This is most likely not the best/only way to do this, but I believe that it's one workaround to extracting the "host" parameters needed on the server and client code when needed. Let me know if this is helpful!

Flafi87
Tourist
7 1 2

Brilliant! Works like a charm! Thank you!

cormacncheese
Tourist
6 0 0

How were you able to pass the "host" param from the server side to the client in _app.js?

My ctx.query.host is returning undefined

0 Likes
Flafi87
Tourist
7 1 2