Add product to cart via script

Add product to cart via script

Looking for a way to add an item to the cart using a script. In Shopify I can do this using a URL or a script Ike shown below. 
URL: https://mysite.com/cart/add?id=32068170743923&quantity=1
or
script 
  1. $.post('/cart/add.js', { //Post the below in the cart
    quantity: 1, //Add the quantity of products
    id:31947959435111 //product variant id
    },function(){
    window.location.reload();
    });