Create Access Page for Logged-in Users

I’d like to code a page on my site that will display certain products to a SnipCart user if they are logged in and have the product in their order history, but I’m at a loss as to how I would call the currently logged-in user via the API. Once I have that, it seems like I can fetch their orders via the API but I don’t see how to fetch the current user without also creating an account on our website for them, which we’d prefer not to do.

Can someone help me with the curl language to get me started?

Hi @rekkajay, are you using the JS API?
You could fetch the current logged user with Snipcart.api.customer.fetchDetails()
That should give you the customer ID which you can use to get the orders.

Is this information what you are loonking for? If not, can you give us more details of your setup?


Thank you for responding.

Yes, I am using the javascript code in the footer of the site to run the cart. I use PHP&html for the site content (running the current version of ProcessWire as our CMS).

What I want to do is check the user’s order history for certain products, then use that to grant them access to related content on the website. We are running Snipcart v2.

So I add this code to the JS in the footer, along with what? I assume there’s more to it.

I see a curl call in the documentation but it requires the customer id to be known already:

…Or will that {id} be filled in as long as the line is in the JS snippet?

Thanks for your patience with me. I’m not used to having to modify the JS.

Let me know if you need any further detail. I’m trying to turn the product in their order history into a TRUE/FALSE response that I can use to display page links (or not).