const axios = require('axios')
const getItem = async () => {
const res = await axios.get('https://www.supremenewyork.com/mobile_stock.json')
const data = await res.data
const products_and_categories = data['products_and_categories']['new']
for (let item of products_and_categories) {
if (item['name'].indexOf('Marble Silk S/S Shirt') != -1) {
itemId = item['id']
}
}
return itemId
}
const getStyle = async () => {
const id = await getItem()
const res = await axios.get(`https://www.supremenewyork.com/shop/${id}.json`)
const data = res.data
for (let value of data['styles']) {
if (value['name'].indexOf('Purple') != -1) {
for (let size of value['sizes']) {
if (size['name'].indexOf('Small') != -1 && size['stock_level'] > 0) {
itemStyle = {
'id': id,
'color': value['id'],
'size': size['id']
}
break
} else if (size['name'].indexOf('Medium') != -1 && size['stock_level'] > 0) {
itemStyle = {
'id': id,
'color': value['id'],
'size': size['id']
}
break
} else if (size['name'].indexOf('Large') != -1 && size['stock_level'] > 0) {
itemStyle = {
'id': id,
'color': value['id'],
'size': size['id']
}
break
} else if (size['name'].indexOf('Xlarge') != -1 && size['stock_level'] > 0) {
itemStyle = {
'id': id,
'color': value['id'],
'size': size['id']
}
break
}
}
}
}
return itemStyle
}
const addToBakset = async () => {
const item = await getStyle()
const id = await item['id']
// const res = axios.post(`https://www.supremenewyork.com/shop/${id}/add.json`)
const res = await axios({
url: `https://www.supremenewyork.com/shop/${id}/add.json`,
method: 'post',
headers: {'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25',
'content-type': 'application/x-www-form-urlencoded',
},
data: {
size: item['size'],
style: item['color'],
qty: 1
}
})
console.log(res.data)
}
addToBakset()