Using Webhooks on SamCart

Automatically send HTTP POST Notifications containing order, subscription, and customer information to your own desired endpoint.

Need to integrate SamCart with your own application or create a custom integration with your website? SamCart's Webhook capabilities allow you to do exactly that.

Below, we'll break down how to use the webhook in tandem with SamCart's App Marketplace to create rules allowing you to automate the management of your SamCart customers with your desired endpoint. 

Connecting Your Webhook to the SamCart 

Start by clicking over to your App Marketplace by clicking Apps in your lefthand marketplace navigation bar. Once in the App Marketplace, search for Webhooks and click Install

This will bring up a popup window where you will be asked to enter the Webhook (endpoint/Notify URL) that would like SamCart to send an HTTP POST. Make sure you include "https://" when you enter this Webhook! Click Connect once you have entered your webhook in the box labeled Notify URL. 

After clicking Connect, the Webhook should be successfully set up! You will land on the Installed tab of your App Marketplace, where you can see all your installed Apps. Click on Webhooks to see your new connection.

Now that you've got your Webhook set up within SamCart, we're ready to create some Rules to dictate what to send to your Webhook and when! 

Creating Rules for Webhooks

Now that SamCart is "connected" to your Webhook, you'll need to establish simple rules that tell SamCart to send an HTTP POST to your Notify URL when certain actions takes place in your SamCart Marketplace. 

From the Webhooks page within the App Marketplace, click on + Add New Rule

Clicking Add New Rule will bring up a side window where you can get started creating this rule! 

1) Global Rule or Product Specific Rule - First, you’ll need to decide if you want this rule to apply to all products (global) or only some specific products. Selecting Product Specific Rule will allow you to search your products and choose to add the rule to just one product or multiple specific products.

2) Select an Action - The Action is the functionality available from Webhooks. For Webhooks we have the ability to Send NotifyURL Post (most commonly used), Send NotifyURL Post for Orders and Send NotifyURL Post for Courses. 

3) Select a Trigger - The Trigger is the event that occurs within SamCart to Trigger the Action for the Webhook. 

NOTE: Each application has different Actions available. The following are available integrating with a webhook.

Product Purchased isn't the only SamCart event that can trigger an HTTP POST. Here's the full list: 

  • Product Purchased
  • Product Refunded
  • Product Added to Order
  • Subscription Canceled
  • Subscription Delinquent
  • Subscription Recovered
  • Subscription Restarted
  • Subscription Charged
  • Subscription Charge Failed
  • Order Completed
  • Upsell Purchased
  • Subscription Completed

4) Add Rule - Click Add Rule to complete adding this rule for Webhooks. That's it, you're done! SamCart will send an HTTP POST to your Webhook each time your Product is purchased. 

You can also view / add rules at the product level! To do this, just head over to the specific product you want to add a Webhook rule for and go to the Apps tab. This is where you can view any Global or Product Specific rules that apply to this product. You can also add new rules by clicking + Add New Rule on this page! 

Clicking Add New Rule here will bring up a side window very similar to the one that appears when clicking Add New Rule from the Webhooks page in the App Marketplace. This popup, however, will ask you to choose the App or App instance you would like to create a rule for - in this case you would want to select the Webhooks app! You also have the ability to select any additional products you'd like to add the rule for, in addition to the product you are adding the rule to directly. From there, the steps for creating a rule will be exactly the same as the steps above! 

Data Payload

Here's a sample JSON sent to the notification URL looks like:

{   
"type":"Order",
    "api_key":null,

    "product": {
          "id": 10,
          "name": "Test",
          "price": 25
    },

    "customer": {
          "first_name": "Brian",
          "last_name": "Moran",
          "email": "bri@samcart.com",
          "phone_number": "5551235555",
          "billing_address": "10000 Maple Lawn Blvd",
          "billing_city": "Fulton",
          "billing_state": "Maryland",
          "billing_zip": "21044",
          "billing_country": "USA"
    },

    "order": {
          "id": 12412041,
          "total": 25,
          "shipping_address": null,
          "shipping_city": null,
          "shipping_state": null,
          "shipping_zip": null,
          "shipping_country": null,
          "ip_address": "192.168.56.1",
          "stripe_id": 66,
"subscription_id": 55,
          "custom_fields": {
               "name": "shirt size",
               "slug": "shirt-size",
               "value": "medium"
    },

    "affiliate": {
          "id": null,
          "token": null
    }

}

Values that don’t exist (in this case, shipping address) are represented as NULL values.

Additional event payloads

Less information is passed for the following events:

  • Refund
  • Cancel
  • RecurringPaymentFailed
  • RecurringPaymentRecovered
  • RecurringPaymentSucceeded
  • Custom Field Data
{   
"type":"<eventType>",
    "api_key":"<key>",

    "product": {
          "id": 10,
          "name": "Test",
          "price": 25
    },

    "customer": {
          "first_name": "Brian",
          "last_name": “Moran",
          "email": "bri@samcart.com",
          "phone_number": "5551235555",
    },

    "order": {
          "id": 12412041,
          "total": 25,
          "ip_address": "192.168.56.1"
    }

}

Example PHP code for using this would be:

<?php 
  $inputData = json_decode(file_get_contents('php://input'));
  $firstName = $inputData->{'customer'}->{'first_name'};
  $lastName = $inputData->{'customer'}->{'last_name'};
  $customerName = $firstName . ' ' . $lastName; echo $customerName;
?>

Frequently Asked Questions

Q: My integration seems to be functioning properly, but HTTP POST isn't firing seemingly at random. What happened? 

A: If an integration rule fails to fire, there's always a reason. The Integration Engine keeps a record of the last 1,000 integration events that took place in your Marketplace, and they can be viewed by heading to the App Marketplace and clicking on your Webhooks connection, then just scroll down to the bottom to view the Configuation or Action logs.  

Here, you can search for the event in question and check if anything went wrong. 99% of the time the Logs can provide insight into exactly what might've went wrong with that action. 

Q: How can I uninstall, refresh, or change my Webhooks connection if I made some changes to my Webhook? 

A: Head to the Webhooks connection within the App Marketplace. To completely uninstall the app, click the 3 dots on the right side of the page and click Uninstall App. Clicking those 3 dots will also show show an option to Change App Credentials, click this if you just want to change your NotifyURL endpoint for the connection. You will also see a Refresh Connection button on the left side of the page, you can click this to just refresh the connection. 

Q: Can I have multiple webhooks for my Marketplace/Product?

A: You can indeed! To add an additional Webhook connection, simply click the 3 dots on the left side of the page mentioned in the FAQ above and click Connect New App Instance. This will allow you to add another webhook connection with a new NotifyURL endo

Q: If I have a base product plus a bundled product with a "Product Purchased" trigger utilizing the webhook integration, will the webhook integration fire for both the base product AND the bundled product?

A: Yes, the "Product Purchased" trigger will fire for each item in the order. If you'd prefer for it to only fire once, you could use an "Order Completed" trigger instead.

Q: What data is sent over for each event?

A: Here are samples for each SamCart action available with webhooks: 

Prospect Created

{
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": null,
"product_id": 350399,
"product_name": "Product Name",
"product_price": "10.00",
"currency": "USD",
"billing_addresses": [],
"shipping_addresses": []
}

Order Completed (sends complete order) 

{
"type": "Order",
"api_key": null,
"products": [
{
"id": 411191,
"name": "Product Name",
"price": "5.00",
"status": "Charged",
"shipping": "0.00",
"tax": "0.00",
"transaction_id": "ch_1Ikxxxxxxxxxxxx",
"subscription_id": 1635935,      "sku":"sku_1234"
},
{
"id": 350399,
"name": "Upsell Product Name",
"price": "5.00",
"status": "Charged",
"shipping": "0.00",
"tax": "0.00",
"transaction_id": "ch_1Ikxxxxxxxxxxxx",
"funnel_info": {
"upsell_id": 27429,
"funnel_id": 17455
}
}
],
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5540183,
"billing_address": "100 Main Street",
"billing_city": "Austin",
"billing_state": "TX",
"billing_zip": "78701",
"billing_country": "United States"
},
"order": {
"created_at": "2021-04-27T15:34:40-05:00",
"id": 8674655,
"total": "10.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"total_tax": "0.00",
"total_shipping": "0.00",
"processor": "Stripe",
"custom_fields": [],
"upsell_custom_fields": [],
"transaction_id": [
"ch_1Ikxxxxxxxxxxxx",
"ch_1Ikxxxxxxxxxxxx"
],
"shipping_address": "100 Main Street",
"shipping_city": "Austin",
"shipping_state": "TX",
"shipping_zip": "78701",
"shipping_country": "United States"
},
"affiliate": []
}

Product Purchased  (sends each product from an order)

{
"type": "Order",
"api_key": null,
"product": {
"id": 350399,
"name": "Product Name",
"price": "10.00",
"quantity": 5,
"shipping": "0.00",
"tax": "0.00",
"transaction_id": "ch_1Igtzmxxxxxxxxxxx"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": null,
"customer_id": 5584065,
"billing_address": "100 Main Street",
"billing_city": "Austin",
"billing_state": "TX",
"billing_zip": "78701",
"billing_country": "United States"
},
"order": {
"id": 8560842,
"created_at": "2021-04-16T10:54:15-05:00",
"total": "50.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"total_tax": "0.00",
"total_shipping": "0.00",
"processor": "Stripe",
"custom_fields": [],
"transaction_id": [
"ch_1Igtzmxxxxxxxxxxx"
],
"shipping_address": "100 Main Street",
"shipping_city": "Austin",
"shipping_state": "TX",
"shipping_zip": "78701",
"shipping_country": "United States"
},
"affiliate": []
}

Product Partial Refund (refunded $10 of a $50 order)

{
"type": "PartialRefund",
"api_key": null,
"product": {
"id": 350399,
"name": "Product Name",
"price": "10.00",
"transaction_id": "ch_1Igtzmxxxxxxxxxxx"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5584065
},
"order": {
"id": 8560842,
"total": "40.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"custom_fields": [],
"transaction_id": [
"ch_1Igtzmxxxxxxxxxxx"
]
},
"processor": "Stripe",
"refund_transaction_id": "re_xxxxxxxxx"
}

Product Refunded 

{
"type": "Refund",
"api_key": null,
"product": {
"id": 350399,
"name": "Product Name",
"price": "10.00",
"transaction_id": "ch_1Igtzmxxxxxxxxxxx"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5584065
},
"order": {
"id": 8560842,
"total": "0.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"custom_fields": [],
"transaction_id": [
"ch_1Igtzmxxxxxxxxxxx"
]
},
"processor": "Stripe",
"refund_transaction_id": "re_xxxxxxxxx"
}

Upsell Purchased

{
"type": "UpsellPurchased",
"api_key": null,
"product": {
"id": 350399,
"name": "Upsell Product Name",
"price": "10.00"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5540183
},
"order": {
"id": 8674655,
"total": "10.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"custom_fields": []
}
}

Subscription Charged

{
"type": "RecurringPaymentSucceeded",
"api_key": null,
"product": {
"id": 440369,
"name": "Product Name",
"price": "10.00"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5540183
},
"order": {
"id": 8675100,
"total": "10.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"subscription_id": 1636015,
"custom_fields": []
}
}

Subscription Charge Failed

{
"type": "RecurringPaymentFailed",
"api_key": null,
"product": {
"id": 440369,
"name": "Product Name",
"price": "10.00"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5540183
},
"order": {
"id": 8675100,
"total": "10.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"custom_fields": [],
"subscription_id": 1636015
}
}

Subscription Charge Refunded

{
"type": "SubscriptionChargeRefunded",
"api_key": null,
"product": {
"id": 440369,
"name": "Product Name",
"price": "10.00",
"transaction_id": "ch_1Ixxxxxxxxxxxx"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5540183
},
"order": {
"id": 8675100,
"total": "10.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_JNxxxxxxxxxxxx",
"custom_fields": [],
"subscription_id": 1636015,
"transaction_id": [
"ch_1Ixxxxxxxxxxxx",
"ch_1Ixxxxxxxxxxxx"
]
},
"processor": "Stripe",
"refund_transaction_id": "re_1Ixxxxxxxxxxxx"
}

Subscription Cancelled

{
"type": "Cancel",
"api_key": null,
"product": {
"id": 411191,
"name": "Product Name",
"price": "10.00"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5540183
},
"order": {
"id": 8674655,
"total": "10.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"custom_fields": [],
"subscription_id": 1635935
}
}

Subscription Delinquent 

{
"type": "SubscriptionDelinquent",
"api_key": null,
"product": {
"id": 440369,
"name": "Product Name",
"price": "10.00"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5540183
},
"order": {
"id": 8675100,
"total": "10.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"custom_fields": [],
"subscription_id": 1636015
}
}

Subscription Restarted & Subscription Recovered

{
"type": "SubscriptionRestarted",
"api_key": null,
"product": {
"id": 440369,
"name": "Product Name",
"price": "10.00"
},
"customer": {
"first_name": "SamCart",
"last_name": "Test",
"email": "example@samcart.com",
"phone_number": "5552225555",
"customer_id": 5540183
},
"order": {
"id": 8675100,
"total": "10.00",
"ip_address": "00.00.000.00",
"stripe_id": "cus_xxxxxxxxx",
"custom_fields": [],
"subscription_id": 1636015
}
}


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.