Single-use access code and checkout limit

I’m looking to do two things:

  • Issue a single use code to customers (I have a list of signed up customers by email for our app)

  • Limit the number of items that can be bought with that code to (2).

Note this is not an optional discount code, but a code required for the buyer to access the product or checkout.

Basically, I have limited inventory and I am working to share it with as many people as possible. I can generate codes on my end and upload them to Shopify.

I’ve been trying to hack it together with Shopify apps but haven’t found the right combo.

Any help appreciated!