Many parts of Polymart require JavaScript to function correctly.
Click here to enable JavaScript.

Webhooks

Back to Wiki Home
You can edit webhooks on your resource by going to your resource page and clicking the "Webhooks" button in the edit section.

Automatic Discord Integration
Polymart automatically integrates with Discord webhooks. However, this doesn't give you nearly as much customization as if you build your own API for receiving webhooks. If you want to learn more about how to build your own API for receiving webhooks, keep reading!

Webhook Overview
ping — Sent whenever you click the "ping" button on your resource's webhooks page

product.update — Sent whenever you post an update to your resource
product.user.purchase — Sent when a user purchases your resource
product.user.purchaseRemoved — Sent when a user issues a chargeback or is refunded
product.user.firstDownload — Sent when a user first downloads your resource

About Webhooks
When a webhook event is called, Polymart will send a request to the URL you provide on your resource page. With each request, the following headers will be sent:

X-Polymart-Webhook-Version: 1

X-Polymart-Signature will be a signature that verifies that the webhook request is in-fact valid. This is a SHA256 HMAC hash, where the data is the data that was POSTed, and the key is your webhook secret. Your webhook secret generated when you create a new webhook. YOU MUST VALIDATE THAT THIS IS CORRECT. If you do not, attackers will easily be able to send random, invalid webhooks to your server

The data that is POSTed to your webhook will be in this format
{
  "event": <event type>,
  "time": <current unix time>,
  "nonce": <random nonce>,
  "payload": {
    <key 1>: <val 1>,
    <key 2>: <val 2>,
    <...>: <...>
  }
}
So, the top-level information might look something like this
{
  "event": "product.update",
  "time": 1711702787,
  "nonce": "Px7nER0ASyzgjkqv",
  "payload": <...>
}
Putting it all together, this is what a full valid request to https://example.com/polymartWebhook might look like, given the webhook secret psKvvXoRExeliNUp
POST /polymartWebhook HTTP/1.1
X-Polymart-Webhook-Version: 1
X-Polymart-Signature: a75cfac9f67e9e13da2f997942c8f23e7ce32b6f0949f12b7059de08bd4ddcb5
Content-Type: application/json
Content-Length: 166

{
    "event": "testEvent",
    "time": 1711702787,
    "nonce": "AcLmFblyT7-vN2JS",
    "payload": {
        "webhook": "https://example.com/polymartWebhook"
    }
}
Use this to test your webhook! This webhook event is called when you click the "send a ping" button on your resource's webhooks page.

Format
{
  "event": "ping",
  "time": <current unix time>,
  "nonce": <random nonce>,
  "payload": {
    "product": {
      "id": <resource id>,
      "title": <resource title>,
      "subtitle": <resource subtitle>,
      "url": <resource url>
    },
    "webhook": {
      "url": <your webhook url>
    }
  }
}
Example
{
  "event": "ping",
  "time": 1711702787,
  "nonce": "sKDEqZ_SB7MAteC-",
  "payload": {
    "product": {
      "id": "1",
      "title": "CustomItems",
      "subtitle": "Design new Custom items and blocks!",
      "url": "https://polymart.org/resource/1"
    },
    "webhook": {
      "url": "https://example.com/polymartWebhook"
    }
  }
}

If your webhook secret is psKvvXoRExeliNUp, then the signature of this request will be ed8a5a9dc16ffbf39e9d6cf854eca12ce66a5ca847eba28a044ed82d6f78593c
product.update Back to top
This webhook event is called when your resource is updated.

Format
{
  "event": "resource.update",
  "time": <current unix time>,
  "nonce": <random nonce>,
  "payload": {
    "product": {
      "id": <resource id>,
      "title": <resource title>,
      "subtitle": <resource subtitle>,
      "url": <resource url>
    },
    "previous": {
      "version": <old version>,
      "id": <old version ID>,
      "time": <old version update time>,
      "size": <old size>,
      "fileType": <old file type>,
      "branch": <beta|snapshot|release>
    },
    "update": {
      "version": <new version>,
      "id": <new version ID>,
      "time": <update time>,
      "size": <new size>,
      "fileType": <new file type>,
      "branch": <beta|snapshot|release>,
      "title": <update title>,
      "description": <update description>
    }
  }
}
Example
{
  "event": "product.update",
  "time": 1711702787,
  "nonce": "2zCnhwV_YicJnOPC",
  "payload": {
    "product": {
      "id": "1",
      "title": "CustomItems",
      "subtitle": "Design new Custom items and blocks!",
      "url": "https://polymart.org/resource/1"
    },
    "previous": {
      "version": "2.19.5",
      "id": "91",
      "time": 1711699187,
      "size": "716624",
      "fileType": "jar",
      "branch": "snapshot"
    },
    "update": {
      "version": "3.0",
      "id": "107",
      "time": 1711702787,
      "size": "718232",
      "fileType": "jar",
      "branch": "release",
      "title": "Automatic Resource Pack Generation",
      "description": "This version adds an automatic resource pack generator to CustomItems!"
    }
  }
}

If your webhook secret is psKvvXoRExeliNUp, then the signature of this request will be 5917de8e70f3cde3a83ae7b24430eccf2854e83ae6cb7103c34e97f48be07468
product.user.purchase Back to top
This webhook event is called when a user purchases your resource

Format
{
  "event": "product.user.purchase",
  "time": <current unix time>,
  "nonce": <random nonce>,
  "payload": {
    "product": {
      "id": <resource id>,
      "title": <resource title>,
      "subtitle": <resource subtitle>,
      "url": <resource url>
    },
    "user": {
      "id": <user id>
    }
  }
}
Example
{
  "event": "product.user.purchase",
  "time": 1711702787,
  "nonce": "MbRzjL_Nc6yBYZhv",
  "payload": {
    "product": {
      "id": "1",
      "title": "CustomItems",
      "subtitle": "Design new Custom items and blocks!",
      "url": "https://polymart.org/resource/1"
    },
    "user": {
      "id": 84076
    }
  }
}

If your webhook secret is psKvvXoRExeliNUp, then the signature of this request will be f8947c7320ffcfabf28d95774569fb44d8557fc61de8088e9f53d7564ccab27e
product.user.purchaseRemoved Back to top
This webhook event is called when you issue a refund to a user, or they issue a chargeback. This event may be called more than once for a given user

Format
{
  "event": "product.user.purchaseRemoved",
  "time": <current unix time>,
  "nonce": <random nonce>,
  "payload": {
    "product": {
      "id": <resource id>,
      "title": <resource title>,
      "subtitle": <resource subtitle>,
      "url": <resource url>
    },
    "user": {
      "id": <user id>
    }
  }
}
Example
{
  "event": "product.user.purchaseRemoved",
  "time": 1711702787,
  "nonce": "aTcNJo-ZcICdGErh",
  "payload": {
    "product": {
      "id": "1",
      "title": "CustomItems",
      "subtitle": "Design new Custom items and blocks!",
      "url": "https://polymart.org/resource/1"
    },
    "user": {
      "id": 40865
    }
  }
}

If your webhook secret is psKvvXoRExeliNUp, then the signature of this request will be 8d9c0e4149e374bdd685061203acd3d0f67f6d116717b0400341e0b08fb52808
product.user.firstDownload Back to top
This webhook event is called when a user downloads your resource for the first time

Format
{
  "event": "product.user.firstDownload",
  "time": <current unix time>,
  "nonce": <random nonce>,
  "payload": {
    "product": {
      "id": <resource id>,
      "title": <resource title>,
      "subtitle": <resource subtitle>,
      "url": <resource url>
    },
    "user": {
      "id": <user id>
    }
  }
}
Example
{
  "event": "product.user.firstDownload",
  "time": 1711702787,
  "nonce": "gZ3YIm-eLT00ti7s",
  "payload": {
    "product": {
      "id": "1",
      "title": "CustomItems",
      "subtitle": "Design new Custom items and blocks!",
      "url": "https://polymart.org/resource/1"
    },
    "user": {
      "id": 30525
    }
  }
}

If your webhook secret is psKvvXoRExeliNUp, then the signature of this request will be 15bef4cbea2d69e0208d41be49f488910241eff6fae121c59abc16b22e4d2f4e