Blog

🎯 Running an AppSumo campaign for Gato GraphQL, with Gato GraphQL and Lemon Squeezy

Leonardo Losoviz
By Leonardo Losoviz Β·

Gato GraphQL is launching today in AppSumo! πŸ™Œ

As a requirement, the Gato GraphQL team had to send 10.000 redemption codes to AppSumo. These codes are the bridge between AppSumo (where the user pays for the product) and Gato GraphQL (where the user downloads the plugin).

When the user comes to gatographql.com to redeem the codes, we produce a corresponding "100% discount code" (redeemable only once, and restricted to that specific product), and have the user "purchase" the plugin using the discount code.

Redeeming Gato GraphQL with the AppSumo code - The 100% discount code is automatically applied

The thousands of discount codes had to be created in advance, and stored in our marketplace provider, Lemon Squeezy.

Lemon Squeezy enables creating discounts via its API. Since Gato GraphQL has an HTTP Client, we have then executed a GraphQL query that connects against the Lemon Squeezy API and creates the thousands of discount codes. (In other words, Gato GraphQL is powering its own AppSumo campaign πŸ˜†)

The 10.000 redemption codes for AppSumo were created by running this GraphQL query:

The corresponding discount codes were created by running this GraphQL query:

The first query is very simple. The second query is a bit more complex. Let's explore it in more detail.

Creating the discount code

The GraphQL query uses field _generateRandomString to generate the discount code as a random string, using chars ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.

The code is also prepended with a namespace (via the $codePrefix variable), to match a specific product and tier.

For instance, namespace APSMV1T1 means:

  • AppSumo campaign
  • Variation 1 product
  • Tier 1

All discount codes are also given a unique descriptive name, to help us find it in the Lemon Squeezy dashboard:

  • Appsumo campaign #1
  • Appsumo campaign #2
  • Appsumo campaign #3
  • ...
  • Appsumo campaign #{recordNumber}

Then, searching for Appsumo campaign #, we can visualize the codes:

Generated discount codes in Lemon Squeezy
Generated discount codes in Lemon Squeezy

And clicking on any of them, we see that it applies to a single product and variation:

Discount code in Lemon Squeezy
Discount code in Lemon Squeezy

Executing the query multiple times via a bash script

The query executes (by default) 100 async HTTP requests against the LemonSqueezy API, with each request creating a single discount code. As such, running the query will produce 100 discount codes.

We don't execute all 10.000 requests at once because, at some point (certainly with 500 calls), the LemonSqueezy API produces a "Too many requests" error.

That's why we split the execution of the query into batches of 100 requests, and add a delay in between.

The first step is to create a persisted query in our WordPress site, copy/paste the query, and publish it:

Persisted query
Persisted query

Once published, we can execute the persisted query at will within a bash script using curl, providing the GraphQL variables as parameters to the persisted query URL.

This batch script executes the persisted query 100 times (100 x 100 = 10.000), passing the appropriate variables to each request, and waiting 30 seconds in between (here is the code for the first 300 discount codes):

curl --user "{username}:{applicationPassword}" "https://my-wp-site.com/graphql-query/create-redemption-codes-for-appsumo-in-lemonsqueezy/?codePrefix=APSMV1T1&storeID={storeId}&variantIDs[]={productVariantId}&lemonSqueezyAccessToken={accessToken}&postId={postId}"
sleep 30
curl --user "{username}:{applicationPassword}" "https://my-wp-site.com/graphql-query/create-redemption-codes-for-appsumo-in-lemonsqueezy/?firstRecordNumber=101&codePrefix=APSMV1T1&storeID={storeId}&variantIDs[]={productVariantId}&lemonSqueezyAccessToken={accessToken}&postId={postId}"
sleep 30
curl --user "{username}:{applicationPassword}" "https://my-wp-site.com/graphql-query/create-redemption-codes-for-appsumo-in-lemonsqueezy/?firstRecordNumber=201&codePrefix=APSMV1T1&storeID={storeId}&variantIDs[]={productVariantId}&lemonSqueezyAccessToken={accessToken}&postId={postId}"
# ...

Collecting all generated codes

Since we're operating in our WordPress site, we can conveniently create a post to collect all the newly-generated discount codes.

Providing a $postId parameter, every time the query is executed it will append the new 100 codes at the end of that post.

Collecting the redemption codes
Collecting the redemption codes

By the end of executing the bash script, the post will contain all 10.000 codes.

The task is done

I run the first query, copied all 10.000 random strings, pasted it in a new codes.csv file, and sent it to AppSumo.

I run the second query, copied the 10.000 discount codes, and pasted them in the logic of my application to have the user download the plugin.

Gato GraphQL is ready for the AppSumo campaign.

Wish us good luck πŸ™


Subscribe to our newsletter

Stay in the loop on all new things concerning Gato GraphQL.