Last active
March 12, 2021 18:49
-
-
Save leadbi/e55559788cd459c927aab255d46ffdb3 to your computer and use it in GitHub Desktop.
LeadBI ECommerce JavaScript API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LeadBI Shop API | |
// Shop.identify(user, callback) | |
window.$leadbi_website.getCurrentUser(function (err, user) { | |
return user.getShop(function (err, shop) { | |
return shop.identify({ | |
first_name: 'Andrei', // optional | |
last_name: 'Tofan', // optional | |
email: 'andrei@leadbi.com', // required | |
company: 'LeadBI', // optional | |
phone: '+40769329925', | |
role: 'CTO', // optional | |
attributes: { // other attributes to be associated with the user | |
example_attribute: 'test' | |
} | |
}, function (err) { | |
console.log(err); | |
}) | |
}); | |
}); | |
// Shop.viewProduct(product, callback) | |
window.$leadbi_website.getCurrentUser(function (err, user) { | |
return user.getShop(function (err, shop) { | |
return shop.viewProduct({ | |
id: '6', | |
name: 'Example Product', | |
url: 'http://test.com/product/6', | |
img: 'http://test.com/img.jpg', | |
price: '80 EUR', | |
promo_price: '70 EUR', | |
available_inventory: 1, | |
category_id: 22, | |
category_name: 'test' | |
}, function (err) { | |
console.log(err); | |
}); | |
}); | |
}); | |
// Shop.trackPurchase(purchase, callback) | |
window.$leadbi_website.getCurrentUser(function (err, user) { | |
return user.getShop(function (err, shop) { | |
return shop.trackPurchase({ | |
order_no: '6', | |
name: 'Example Product 1', | |
url: 'http://test.com/product/6', | |
img: 'http://test.com/img.jpg', | |
price: '80 EUR', | |
promo_price: '70 EUR', | |
available_inventory: true, | |
quantity: 1, | |
category_id: 22, | |
category_name: 'test', | |
total: '80 EUR', | |
}, function (err) { | |
console.log(err); | |
}); | |
}); | |
}); | |
// Shop.clickImage(product_id, callback) | |
window.$leadbi_website.getCurrentUser(function (err, user) { | |
return user.getShop(function (err, shop) { | |
var product = { | |
id: '6', | |
name: 'Example Product 1', | |
url: 'http://test.com/product/6', | |
img: 'http://test.com/img.jpg', | |
price: '80 EUR', | |
promo_price: '70 EUR', | |
available_inventory: 100, | |
quantity: 1, | |
category_id: 22, | |
category_name: 'test' | |
}; | |
return shop.clickImage(product, function (err) { | |
console.log(err); | |
}) | |
}); | |
}); | |
// Shop.Cart.addProduct(product, callback) | |
window.$leadbi_website.getCurrentUser(function (err, user) { | |
return user.getShop(function (err, shop) { | |
return shop.getCart('default', function (err, cart) { | |
return cart.addProduct({ | |
id: '6', | |
name: 'Example Product 1', | |
url: 'http://test.com/product/6', | |
img: 'http://test.com/img.jpg', | |
price: '80 EUR', | |
promo_price: '70 EUR', | |
available_inventory: 100, | |
quantity: 1, | |
category_id: 22, | |
category_name: 'test' | |
}, function (err) { | |
console.log(err); | |
}); | |
}); | |
}); | |
}); | |
// Shop.Cart.removeProduct(product_id, callback) | |
window.$leadbi_website.getCurrentUser(function (err, user) { | |
return user.getShop(function (err, shop) { | |
return shop.getCart('default', function (err, cart) { | |
var product_id = 22; | |
return cart.removeProduct(product_id, function (err) { | |
console.log(err); | |
}); | |
}); | |
}); | |
}); | |
// Shop.Cart.createOrder(order, callback) | |
window.$leadbi_website.getCurrentUser(function (err, user) { | |
return user.getShop(function (err, shop) { | |
return shop.getCart('default', function (err, cart) { | |
return cart.createOrder({ | |
order_no: '232', | |
last_name: 'John', | |
first_name: 'Doe', | |
email: 'jd@example.com', | |
phone: '+40879826392', | |
state: 'NY', | |
city: 'New York', | |
address: '1st Av.', | |
discount_code: 'None', | |
discount: 'None', | |
shipping: 'Mail', | |
total: '80 EUR', | |
}, function (err) { | |
console.log(err); | |
}); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment