Storing Metadata

Use Keygen's API and your client-side code to store metadata on your user resources. If you need help after reading this, can reach out to us anytime at [email protected].

This tutorial is written in JavaScript, but you can follow along in any other language that you're comfortable in. Throughout this tutorial, you will see placeholders such as {ACCOUNT} within the code examples that will need to be replaced with an ID for that particular resource type.

Keygen supports adding arbitrary metadata to most resources, such as the user resource. Metadata is for your use only and is not explicity shown to customers unless you display it (though note that it is included in API responses e.g. when you request a user resource).

With metadata, you can associate other information, such as the user's customer_id within your payment system, the user's shipping address, etc. Any metadata you include will be viewable within your dashboard (e.g. when looking at an individual resource).

Be aware that since the metadata attribute is simply a key-value store (hash), all write operations will overwrite the entire hash, so be sure to merge existing data on your end when performing partial updates.

The response of this request will either be an error, or the full user resource including your user's updated metadata.

const response = await fetch("{ACCOUNT}/users", {
  method: "PATCH",
  headers: {
    "Content-Type": "application/vnd.api+json",
    "Accept": "application/vnd.api+json",
    "Authorization": "Bearer {PRODUCT_TOKEN}"
  body: JSON.stringify({
    "data": {
      "type": "users",
      "attributes": {
        "metadata": {
          "customerId": "cus_VuAsGNTGqYgz1P"

const { data, errors } = await response.json()
When storing initial metadata (via a POST request), a user or activation token may be used. However, updating metadata requires an admin or product token.

Next steps

Congrats! You've stored metadata on one of your users using Keygen. Next up, we can create a license for your user and learn how to validate it. If you have any questions about what you've learned today, be sure to reach out!