Skip to content

How to use webhooks

onefriendaday edited this page Nov 14, 2014 · 1 revision

Define your URLs for receiving stock movements or created orders in the admin 'Settings' -> 'Integrations/Apis' -> 'Webhooks' and you will receive a post with following parameters:

For stock movements

{
  "stock_movement":{
    "product_id":"54",
	"variant_id":"524",
    "old_quantity":"3",
    "new_quantity":2
  }
}

ATTENTION: variant_id will be included only if item is a variant

For new orders

{
  "order":{
    "ship_id":"2188",
    "ship_created_at":"0000-00-00 00:00:00",
    "ship_company":"",
    "ship_firstname":"Alex",
    "ship_lastname":"Feigi",
    "ship_email":"[email protected]",
    "ship_phone":"(32) 41312-4231",
    "ship_address1":"Estrada do Col\u00e9gio",
    "ship_address2":"",
    "ship_anumber":"3",
    "ship_district":"Col\u00e9gio",
    "ship_city":"Rio de Janeiro",
    "ship_zip":"21235-280",
    "ship_zone_id":"458",
    "ship_zone":"RJ",
    "ship_country_id":"30",
    "ship_country":"Brazil",
    "ship_country_code":"BR",
    "ship_reference":"",
    "ship_extra":"{\"cnpj\":\"\",\"company_registration\":\"\",\"company_alt\":\"\"}",
    "ship_site_id":"10",
    "bill_id":"2188",
    "bill_created_at":"0000-00-00 00:00:00",
    "bill_company":"",
    "bill_firstname":"Alex",
    "bill_lastname":"Feigi",
    "bill_email":"[email protected]",
    "bill_phone":"(32) 41312-4231",
    "bill_address1":"Estrada do Col\u00e9gio",
    "bill_address2":"",
    "bill_anumber":"3",
    "bill_district":"Col\u00e9gio",
    "bill_city":"Rio de Janeiro",
    "bill_zip":"21235-280",
    "bill_zone_id":"458",
    "bill_zone":"RJ",
    "bill_country_id":"30",
    "bill_country":"Brazil",
    "bill_country_code":"BR",
    "bill_reference":"",
    "bill_extra":"{\"cnpj\":\"\",\"company_registration\":\"\",\"company_alt\":\"\"}",
    "bill_site_id":"10",
    "customer_id":"231",
    "customer_firstname":"Alex",
    "customer_lastname":"Feigi",
    "customer_email":"[email protected]",
    "customer_email_subscribe":"1",
    "customer_phone":"(32) 41312-4231",
    "customer_company":"",
    "customer_default_billing_address":"158",
    "customer_default_shipping_address":"158",
    "customer_ship_to_bill_address":"true",
    "customer_active":"1",
    "customer_group_id":"1",
    "customer_confirmed":"1",
    "customer_site_id":"10",
    "customer_sex":"0",
    "customer_cpf":"234.123.431-24",
    "customer_birthday":"1986-03-03",
    "customer_mobile":"",
    "customer_cnpj":"",
    "customer_company_alt":"",
    "customer_company_registration":"",
    "customer_company_registration_alt":"",
    "customer_subscribed":"0",
    "customer_job":"",
    "customer_company_description":"",
    "id":"2053",
    "order_number":"1415982620100",
    "status":"Pending",
    "ordered_on":"2014-11-14 14:30:44",
    "shipped_on":null,
    "tax":"0.00",
    "total":"22.50",
    "subtotal":"8.80",
    "gift_card_discount":"0.00",
    "coupon_discount":"0.00",
    "shipping":"13.70",
    "shipping_notes":"",
    "shipping_method":"PAC",
    "notes":null,
    "referral":"",
    "company":"",
    "firstname":"Alex",
    "lastname":"Feigi",
    "phone":"(32) 41312-4231",
    "email":"[email protected]",
    "site_id":"10",
    "history":"",
    "tracking_number":"",
    "payment_discount":"0.00",
    "delivery_time":"3",
    "production_time":"0",
    "days_until_shipped":"0",
    "approved_on":"0000-00-00 00:00:00",
    "contaazul":"0",
    "sentalert":"0",
    "nota_fiscal":"",
    "shipping_method_alt":"",
    "extra":"",
    "payment_type":"OTHER",
    "delivering_on":null,
    "origin_id":"0",
    "salesman_id":"0",
    "ship_address_id":"2188",
    "bill_address_id":"2188",
    "payment_options":"",
    "look_discount":"0.00",
    "contents":[
      {
        "order_id":"2053",
        "product_id":"54",
        "variant_id":null,
        "excerpt":"A bodycon skirt featuring a striped tribal print. Elasticized waist. Finished trim. Stretch-knit. Lightweight.",
        "description":"<p>A bodycon skirt featuring a striped tribal print. Elasticized waist. Finished trim. Stretch-knit. Lightweight.<\/p><p>DETAILS:<\/p><ul><li>15\" approx. length from waist to hem, 26\" waist<\/li><li>Measured from Small<\/li><li>95% cotton, 5% spandex<\/li><li>Machine wash cold, dry flat<\/li><li>Imported<\/li><\/ul>",
        "order_item_id":"4162",
        "id":"54",
        "sku":"MO8990",
        "name":"Saia Global Girl Bodycon",
        "slug":"Saia-Global-Girl-Bodycon",
        "price":"8.80",
        "saleprice":"0.00",
        "free_shipping":"0",
        "shippable":"1",
        "taxable":"0",
        "fixed_quantity":"0",
        "weight":"0.3",
        "track_stock":"1",
        "enabled":"1",
        "site_id":"10",
        "height":"5.00",
        "width":"20.00",
        "depth":"20.00",
        "factory_price":"2.00",
        "installments":"3",
        "stared":"0",
        "variant_details":"0",
        "subscription_days":"0",
        "subscription_period":"",
        "subscription_trial":null,
        "lookable":"0",
        "reduction_type":"",
        "reduction_amount":"0",
        "look_products":[

        ],
        "available_options":[

        ],
        "current_category":false,
        "base_price":"8.80",
        "file_list":[

        ],
        "is_gc":false,
        "quantity":1,
        "subtotal":8.8
      }
    ],
    "total_discounts":0
  }
}

Example for receiving a stock movement with PHP

$post = json_encode($_POST['stock_movement']);
$log = fopen('log.txt', 'w') or die('Unable to open file!');
fwrite($log, $post);
fclose($log);