Re: Distinguish callback URL

How can I identify if a callback URL is for first-time app installation or reopening?

notavailable
Tourist
5 0 2

Hi,

Install URL: http://localhost:4000/shopify

Callback URL: http://localhost:4000/shopify/callback

Everything works fine. However, Im not able to figure out following:

When app is installed for first, it goes to install URL(without session in query) and then to callback url after permissions are accepted. 

When we click on the installed app in list on store, it gets back to install URL(with session in query) and then to callback url(no permissions are shown this time). 

Is there any way to identify that CALLBACK URL is being called for first time install of app OR opening already installed app? Please help.

Replies 11 (11)

OliUK
Shopify Partner
235 2 56

Hey,

You need to use a tunneling service to expose local host to the internet. Shopify recommend NGROK. So, for local development your new address would be something's like ngrok.dsadsa.com

Also, we list a https and a http address in our callback url settings.

Good luck,

Oli

 

——————————

Founder @ www.preproduct.io

Test and make sales for future products

 

 

notavailable
Tourist
5 0 2

@OliUK

I understand that. Please read my question again. It is not about how can I expose my URLs to internet. Server is already setup. For testing purpose, Im using localhost.

Callback URL will be called when

a) user install app for first time

b) app is already installed and user click on that app in store. https://shop-name.com/admin/apps

My question is that is there any way to figure out if callback url is called to install app or opening already installed app. I hope you will understand my concern now.

notavailable
Tourist
5 0 2

@OliUK 

To make it even more clear, I want to do something after app is installed. After installation it comes back to callback url so I can do that in callback url. But same callback url is called when INSTALLED app is clicked on in store. So callback url is multipurpose. How can I identify if callback url is called after installation or clicking in store?

OliUK
Shopify Partner
235 2 56

Hi,

I still don’t quite see how your local host URLs would work (even in testing) as your app URL would have to be exposed to the web in order to load the app into the Shopify dashboard. Anyway, I might be missing something, to answer the rest of your question:

Ok I think I understand what you’re trying to do. I’ve never tried to do this the way you’re describing, so I can’t help you there. Why don’t you just  run some code before you create a database entry for the shop? v.rough example:

@shop = ShopifyAPI::Shop.current
if Shop.find_by(shopify_domain: @shop.myshopify_domain)
      #shop already exsists
else
     #some logic here
     @db_shop = Shop.new
     @db_shop.shopify_domain = @shop.myshopify_domain
     #etc
     @db_shop.save
end

 

Cheers,

Oli

 

——————————

Founder @ www.preproduct.io

Test and make sales for future products

 

notavailable
Tourist
5 0 2

@OliUK 

Thanks for replying back.

Im not saving shop and access token as soon as I get it. I install the app, it hits callback api, on receiving access token, it redirect to my app's user registration page. On registering, Im saving that token and shop in db.

So in case, user installs the app but does not register, how can I figure it out that app is already installed so don't perform specific actions(such as sending notification that a shop has installed your app)

 

 

OliUK
Shopify Partner
235 2 56

Ah I understand. That's a tricky one, I take it there aren't params sent to the callback URL from Shopify that you can use?

 

——————————

Founder @ www.preproduct.io

Test and make sales for future products

 

 

notavailable
Tourist
5 0 2
shop, hmac, code, state, signature, timestamp. These are params which I get during callback which I don't find helpful to resolve my problem.
 
Is there anyway I can use these to identify if app is already installed?
OliUK
Shopify Partner
235 2 56

At this point I only really know as much as you do. I take it the 'state' param isn't returning anything promising.

Again, if you had a list of shop names stored in your database, you could just check to see if the shop in shop param had an entry yet.

Here's a link to the Rails Shopify callback controller , even if you're not a Ruby developer, it's really nicely written and easy to understand. Maybe there's a clue in there.

 

——————————

Founder @ www.preproduct.io

Test and make sales for future products

 

Todd_Trimakas
Shopify Partner
145 0 28

This ever get resolved? I'm having the exact same issue.. 

ByteStand - Amazon to Shopify in one click

DanyPell
Shopify Partner
2 0 1

Any luck with this problem?

ivpoov
Shopify Partner
1 0 0

I am experiencing the same problem. The funny thing is that all data (cookies, query params, headers) is the same for the first app install, app update, or app open cases, so it's impossible to distinguish what is happening now. The only option I've found is enabling an 'embedded' app option. With an embedded app, the set of cookies from an open app event is different from the app install or app update. But the embedded app is not what I want; in the case of opening the app, I just want to redirect the merchant to my stand-alone site