Webhooks are a way to run code on an external server that integrates with events in the AmeriCommerce. When the conditions are fulfilled, the AmeriCommerce will make a request out to a URL, and, depending on the webhook, wait for a response.
In the case of events that expect responses, the timeout is intentionally short (3 seconds), since any delay can potentially be disrupting to users of the store. It is highly recommended that your service return results as quickly as possible.
| Event Type | Description | Reply? |
|---|---|---|
| AuthorizingPayment | Called to authorize a payment | Yes |
| CapturingPayment | Called to capture a payment | Yes |
| GetPrice | Called when calculating price for one or more products | Yes |
| GetProductStatus | Called when checking the status of a product for display | Yes |
| GetTax | Called when calculating tax for a cart | Yes |
| OrderApproved | Called after an order has been marked with an Approved order status | No |
| OrderCanceled | Called after an order has been marked with a Canceled order status | No |
| OrderDeclined | Called after an order has been marked with a Declined order status | No |
| OrderPlaced | Called after a new order has been placed | No |
| OrderShipped | Called after an order has been marked with a Shipped order status | No |
| PaymentProcessed | Called after a payment has finished processing | No |
| ProductStatusChanged | Called when a product's status has been changed | No |
| ValidateCart | Called when the current cart is being checked for errors | Yes |
| ValidateCheckout | Called when the checkout page is being checked for errors | Yes |
| GetDiscount | Called when calculating discounts for a cart | Yes |
Webhook subscriptions are accessible via /api/v1/webhooks, which works exactly the same as any other API endpoint. The webhook resource consists of the following fields:
event_type- The webhook type, as shown in the table above.url- The URL that will be sent a request when the conditions for the event are met.failure_type- What to do in the event of a failure, options are:"Ignore"- Disregard the failure and continue as normal, this is the default."Error"- Display an error message to the user."Fallback"- Call an alternate URL as indicated by thefallback_urlfield.
store_id- The ID of the store, as shown on thestoreresource, that this webhook applies to. Only events on this store will be triggered.cache_length- How long the response to this webhook request will be cached by the AmeriCommerce servers, options are:"Short"- 5 minutes"Long"- 30 minutes"NoCache"- Do not cache the response.
fallback_url- In the event of a failure, and thefailure_typeis set to"Fallback", this URL will be called next.
For this example, the token needs to have "View and change order data" and "Perform system tasks" scope.
curl -X POST \
-H "X-AC-Auth-Token: [TOKEN]" \
-H "Content-Type: application/json" \
-H "Cache-Control: no-cache" \
-d '{ \
"event_type": "OrderPlace", \
"url": "https://[webhookhost.com]/OrderPlacedProcessor", \
"failure_type": "Fallback", \
"store_id": 1, \
"cache_length": "Short", \
"fallback_url": "https://[webhookhost.com]/fallback/OrderPlacedProcessor" \
}' \
"https://[mystoredomain.com]/api/v1/webhooks" The request contains the following:
order_payment- Object. An order payment model, as shown on theorder_paymentsresource.
The response to this webhook is expected to contain:
approved- Boolean. Was this authorization approved or not.declined- Boolean. Was this authorization declined.authorization_code- String. Set if an authorization code was returned from the processor.transaction_id- String. Set if a transaction ID was returned from the processor.avs_code- String. Set if the processor uses AVS as a verification mechanism and returns this information.reject_reason- String. Reason for declining the authorization.notes- String. Any additional information about this authorization.outstanding_balance- Decimal. Remaining balance in the event that this authorization did not cover the full balance.
The request contains the following:
order_payment- Object. An order payment model, as shown on theorder_paymentsresource.
The response to this webhook is expected to contain:
approved- Boolean. Was this capture approved or not.declined- Boolean. Was this capture declined.authorization_code- String. Set if an authorization code was returned from the processor.transaction_id- String. Set if a transaction ID was returned from the processor.avs_code- String. Set if the processor uses AVS as a verification mechanism and returns this information.reject_reason- String. Reason for declining the authorization.notes- String. Any additional information about this authorization.outstanding_balance- Decimal. Remaining balance in the event that this capture did not cover the full balance.
The request contains the following:
items- Array. Contains summarized product information indicating the items we need pricing information for:item_number- String. The product's item number.quantity- Integer. The number of products we need pricing for.variant_ids- Array containing the integer IDs of theproduct_variantsselected, if any exist.variant_inventory_id- Integer. ID of the correspondingvariant_inventoryrecord.
customer_type_id- Thecustomer_typein effect at the time of the request.
The response to this webhook is expected to contain:
prices- Array. Consists of objects with the following information:item_number- String. This should match up with one of the request's item numbers.price- Decimal. The calculated final price for the item.cost- Decimal. The item's cost to the seller.retail- Decimal. The retail price for the item.pre_sale_cost- Decimal. The cost without any sale discount applied.pre_sale_price- Decimal. The price without any sale discount applied.
The request contains the following:
items- Array. Contains summarized information for the products we need status information for:product_id- Integer. The ID of theproduct.variant_inventory_id- Integer. The ID of the applicablevariant_inventoryrecord, if it exists.product_status_id- Integer. The ID of the currentproduct_status.product- Object. Product model as shown on theproductsresource.variant_inventory- Object. Variant inventory model as shown on thevariant_inventoryresource.product_status- Object. Product status model as shown on theproduct_statusesresource.inventory- Integer. Current stock of this item.item_number- String. The product's item number.manufacturer_item_number- String. The product's manufacturer item number.
The response to this webhook is expected to contain:
items- Array. Contains status information that corresponds to the data sent from the webhook request:product_id- Integer. The ID of theproductthat this data corresponds to.variant_inventory_id- Integer. The ID of the applicablevariant_inventoryrecord, if it exists.inventory- Integer. Current stock of this item.status_display_text- String. The text to display for this item's status on frontend pages.product_status_id- Integer. The ID of theproduct_statusto set for this product.is_unavailable- Boolean. Indicates that the product is not available for purchase.is_hidden- Boolean. Indicates that this product should be hidden from customer view.is_back_ordered- Boolean. Indicates that this product is currently backordered.
The request contains the following:
items- Array. Contains summarized information for the items in the cart that tax is being calculated for:cart_item_id- Integer. The ID of thecart_item.item_number- String. The product's item number.item_name- String. The product's name.manufacturer_item_number- String. The product's manufacturer item number.price- Decimal. The price of the item in the cart.discounted_price- Decimal. The price of the item in the cart with discounts applied.quantity- Integer. How many of this item are in the cart.is_tax_exempt- Boolean. Is the item flagged as being tax exempt.tax_code- String. Tax exempt code, if it exists.line_item_subtotal- Decimal. Price multiplied by quantity.origin_address- Object. Thewarehousethat the item is being shipped from.destination_address- Object. Theaddressthat the item is being shipped to.
shipping_total- Decimal. The amount calculated for shipping on the current cart.handling_total- Decimal. The amount calculated for handling on the current cart.
The response to this webhook is expected to contain:
items- Array. Contains information about the tax amounts for each item:cart_item_id- Integer. This should match acart_item_idon the incoming request. Specifies which cart item this tax amount is for.tax_amount- Decimal. The calculated tax amount for this cart item.
shipping_tax_amount- Decimal. The calculated tax amount for shipping.handling_tax_amount- Decimal. The calculated tax amount for handling.
The request contains the following:
order- Object. An order model, as shown on theordersresource.
The request contains the following:
order- Object. An order model, as shown on theordersresource.
The request contains the following:
order- Object. An order model, as shown on theordersresource.
The request contains the following:
order- Object. An order model, as shown on theordersresource.
The request contains the following:
order- Object. An order model, as shown on theordersresource.
The request contains the following:
order_payment- Object. An order payment model, as shown on theorder_paymentsresource.
The request contains the following:
item- Object. A summary of data about the item and its inventory informationproduct_id- Integer. The ID of theproduct.variant_inventory_id- Integer. The ID of the applicablevariant_inventoryrecord, if it exists.product_status_id- Integer. The ID of the currentproduct_status.product- Object. Product model as shown on theproductsresource.variant_inventory- Object. Variant inventory model as shown on thevariant_inventoryresource.product_status- Object. Product status model as shown on theproduct_statusesresource.inventory- Integer. Current stock of this item.item_number- String. The product's item number.manufacturer_item_number- String. The product's manufacturer item number.
The request contains the following:
cart- Object. A cart model as it appears on thecartsresource.
The response to this webhook is expected to contain:
validation_messages- Array. Consists of validation messages (strings) to display to the user.
The request contains the following:
customer- Object. A customer model as it appears on thecustomersresource.billing_address- Object. An address model as it appears on theaddressesresource.shipping_address- Object. An address model as it appears on theaddressesresource.cart- Object. A cart model as it appears on thecartsresource.order_custom_fields- Array. Objects that represent the information entered for order custom fields on the checkout page:name- String. The name of the custom field.value- String. The value entered for the custom field.
is_gift- Boolean. True if the customer checked "Is a Gift" at checkout.gift_message- String. The gift message entered by the customer.order_comments- String. Any order comments entered by the customer.shipping_methods- Array. Consists of the names of one or more shipping methods selected at checkout.payment_methods- Array. Consists of objects containing information about the payments applied:name- String. Name of the payment method.amount- Decimal. Amount of the payment.
The response to this webhook is expected to contain:
validation_messages- Array. Consists of validation messages (strings) to display to the user.
The request contains the following:
ad_code- String.ad codeset on the current session.billing_address- Object. An address model as it appears on theaddressesresource.campaign_code- String.campaign codeset on the cart.cart_id- Integer. ID of the currentcartcustomer_type- String. Thecustomer typenamecustomer_type_id- Integer. ID of thecustomer typedestination_address- Object. An address model as it appears on theaddressesresource.is_region_set- Boolean. Is a specific region set?items- Array of Objectscart_item_id- Integer. ID of thecart itemcategory_id- Array of Integers. List ofcategoryIDs this item belongs to.custom_fields- Objectname- Stringvalue- String
destination_address- Object. An address model as it appears on theaddressesresource.is_subscription_item- Boolean. Is this a subscription item?item_number- String. Item Number as it appears on theproductresource.manufacturer_id- Integer. ID of themanufacturerorigin_address- Object. An address model as it appears on theaddressesresource.parent_product_id- Integer. ID of theparent productprice- Decimal. Unit price of the item.product_id- Integer. ID of theproductproduct_list_id- Array of Integer. IDs of the product lists this product belongs to.quantity- Integer. Quantityshipping_classification_code- String. Breakout shipping classification codevariants- Array of Object.group- String. Variant groupvalue- String. Variant name
shipping_method_list- Object.classification_code- String. Breakout shipping classification codedelivery_date- String. Estimated delivery dateship_method- String. Selected shipping methodshipping_method_name- String. Selected shipping method name
shipping_region_id- Integer. ID of theshipping regionshipping_total- Decimal. Shipping Totalstore_id- Integer. ID of thestoresubscription_subtotal- Decimal. Subtotal of the subscription itemstax_region_id- Integer. ID of thetax regiontotal_weight- Decimal. Total weight of the items in the cart.
The response to this webhook is expected to contain:
cart_items- Array of Objects.cart_id- Integer. Must match thecart_idsent in the requestdescription- String. Optional Item level discount description.discount_amount- Decimal. The discount that should be applied for this item.
add_items- Array of Objects. New items that will be added to the cart as part of the discount.price- Decimal.product_id- Integer. ID of theproductquantity- Integer.variant_inventory_item_number-variant inventoryitem numbervariants- Array of Objects. If using variant inventory setvariant_inventory_item_numberinstead of this array.group- String. Variant group namevalue- String. Variant name
description- Array of String. Optional description of all discounts applied.discount- Decimal. Discount amount will be used in addition to anycart_items.discount_amountshipping_discount- Decimal. Specify this amount if shipping should be discounted separately.