Skip to content

Instantly share code, notes, and snippets.

@guy0090
Last active July 30, 2022 11:21
Show Gist options
  • Save guy0090/0a8b7a1e69b03702bb45fb66a05dced5 to your computer and use it in GitHub Desktop.
Save guy0090/0a8b7a1e69b03702bb45fb66a05dced5 to your computer and use it in GitHub Desktop.
const axios = require('axios')
/**
* To get your TradeAuth_Session and __RequestVerificationToken cookies,
* you need to login to your region's web trade market.
*
* Below is a list of all regions and their respective web market URLs, choose
* your region and login to the web market. Once logged in, open your DevTools
* (in Chrome: Ctrl + Shift + I or F12) and click the Network tab.
*
* On the Web Market, click on a category and then subcategory from the
* left side menu of the page and check your Network tab.
*
* You should see a 'GetWorldMarketList' request, click on it
* and check the 'Cookies' tab.
*
* Copy the TradeAuth_Session (COOKIE_TRADE_AUTH) and
* __RequestVerificationToken (COOKIE_REQUEST_VERIFICATION_TOKEN) cookie
* and set their respective values in the constants below.
*
* The TradeAuth_Session cookie doesn't actually need to be filled in, however
* it must not be undefined.
*
* Now, from the 'Payload' tab, copy the __RequestVerificationToken value and set
* QUERY_REQUEST_VERFICATION_TOKEN to it's value.
*
* For parameters in requests, see https://developers.veliainn.com/
*/
const TRADE_AUTH_SESSION = 'TradeAuth_Session'
const REQUEST_VERIFICATION = '__RequestVerificationToken'
// Cookie: TradeAuth_Session
const COOKIE_TRADE_AUTH = ''
// Cookie: __RequestVerificationToken
const COOKIE_REQUEST_VERIFICATION_TOKEN = ''
// URL Encoded Param: __RequestVerificationToken
const QUERY_REQUEST_VERFICATION_TOKEN = ''
const REGIONS = {
na: "na-trade.naeu.playblackdesert.com",
eu: "eu-trade.naeu.playblackdesert.com",
sea: "trade.sea.playblackdesert.com",
mena: "trade.tr.playblackdesert.com",
kr: "trade.kr.playblackdesert.com",
ru: "trade.ru.playblackdesert.com",
jp: "trade.jp.playblackdesert.com",
th: "trade.th.playblackdesert.com",
tw: "trade.tw.playblackdesert.com",
sa: "blackdesert-tradeweb.playredfox.com",
console_eu: "eu-trade.console.playblackdesert.com",
console_na: "na-trade.console.playblackdesert.com",
console_asia: "asia-trade.console.playblackdesert.com"
}
/**
* @param {string} region Game region
* @returns {Promise<any>} Hot list items
*/
var GetWorldMarketHotList = (region) => {
return new Promise ((resolve, reject) => {
var options = {
method: 'post',
url: `https://${REGIONS[region]}/Home/GetWorldMarketHotList`,
headers: {
'Cookie': `${TRADE_AUTH_SESSION}=${COOKIE_TRADE_AUTH}; ${REQUEST_VERIFICATION}=${COOKIE_REQUEST_VERIFICATION_TOKEN}`,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
}
}
axios(options).then((res) => {
resolve(res.data)
}).catch((err) => {
console.error(err)
reject(err)
})
})
}
/**
* @param {string} region Game region
* @param {string | number} mainCategory Main category ID
* @param {string | number} subCategory Sub category ID
* @returns {Promise<any>} Items in sub category
*/
var GetWorldMarketList = (region, mainCategory, subCategory = 1) => {
return new Promise ((resolve, reject) => {
var params = new URLSearchParams()
params.append(REQUEST_VERIFICATION, QUERY_REQUEST_VERFICATION_TOKEN)
params.append('mainCategory', mainCategory)
params.append('subCategory', subCategory)
var options = {
method: 'post',
url: `https://${REGIONS[region]}/Home/GetWorldMarketList`,
headers: {
'Cookie': `${TRADE_AUTH_SESSION}=${COOKIE_TRADE_AUTH}; ${REQUEST_VERIFICATION}=${COOKIE_REQUEST_VERIFICATION_TOKEN}`,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
},
data: params
}
axios(options).then((res) => {
resolve(res.data)
}).catch((err) => {
console.error(err)
reject(err)
})
})
}
/**
* @param {string} region Game region
* @param {string} mainKey ID of item
* @returns {Promise<any>} Item details
*/
var GetWorldMarketSubList = (region, mainKey) => {
return new Promise ((resolve, reject) => {
var params = new URLSearchParams()
params.append(REQUEST_VERIFICATION, QUERY_REQUEST_VERFICATION_TOKEN)
params.append('mainKey', mainKey)
params.append('usingCleint', 0)
var options = {
method: 'post',
url: `https://${REGIONS[region]}/Home/GetWorldMarketSubList`,
headers: {
'Cookie': `${TRADE_AUTH_SESSION}=${COOKIE_TRADE_AUTH}; ${REQUEST_VERIFICATION}=${COOKIE_REQUEST_VERIFICATION_TOKEN}`,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
},
data: params
}
axios(options).then((res) => {
resolve(res.data)
}).catch((err) => {
console.error(err)
reject(err)
})
})
}
/**
* @param {string} region Game Region
* @param {string} search String to search for
* @returns {<Promise<any>>} The result of the search
* @example GetWorldMarketSearchList('na', 'Kzarka').then((data) => { ... })
*/
var GetWorldMarketSearchList = (region, search) => {
return new Promise ((resolve, reject) => {
var params = new URLSearchParams()
params.append(REQUEST_VERIFICATION, QUERY_REQUEST_VERFICATION_TOKEN)
params.append('searchText', search)
var options = {
method: 'post',
url: `https://${REGIONS[region]}/Home/GetWorldMarketSearchList`,
headers: {
'Cookie': `${TRADE_AUTH_SESSION}=${COOKIE_TRADE_AUTH}; ${REQUEST_VERIFICATION}=${COOKIE_REQUEST_VERIFICATION_TOKEN}`,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
},
data: params
}
axios(options).then((res) => {
resolve(res.data)
}).catch((err) => {
console.error(err)
reject(err)
})
})
}
/**
* @param {string} region Game region
* @param {string | number} mainKey ID of item
* @param {string | number} subKey Enhancement level if available (0-20)
* @returns {Promise<any>} Item details with price history and bidding information
*/
var GetItemSellBuyInfo = (region, mainKey, subKey) => {
return new Promise ((resolve, reject) => {
var params = new URLSearchParams()
params.append(REQUEST_VERIFICATION, QUERY_REQUEST_VERFICATION_TOKEN)
params.append('keyType', 0)
params.append('mainKey', mainKey)
params.append('subKey', subKey)
params.append('isUp', true)
var options = {
method: 'post',
url: `https://${REGIONS[region]}/Home/GetItemSellBuyInfo`,
headers: {
'Cookie': `${TRADE_AUTH_SESSION}=${COOKIE_TRADE_AUTH}; ${REQUEST_VERIFICATION}=${COOKIE_REQUEST_VERIFICATION_TOKEN}`,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
},
data: params
}
axios(options).then((res) => {
resolve(res.data)
}).catch((err) => {
console.error(err)
reject(err)
})
})
}
/**
* @param {string} region Game region
* @returns {Promise<any>} Item(s) in market wait list
*/
var GetWorldMarketWaitList = (region) => {
return new Promise ((resolve, reject) => {
var options = {
method: 'post',
url: `https://${REGIONS[region]}/Home/GetWorldMarketWaitList`,
headers: {
'Cookie': `${TRADE_AUTH_SESSION}=${COOKIE_TRADE_AUTH}; ${REQUEST_VERIFICATION}=${COOKIE_REQUEST_VERIFICATION_TOKEN}`,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
}
}
axios(options).then((res) => {
resolve(res.data)
}).catch((err) => {
console.error(err)
reject(err)
})
})
}
module.exports = {
GetWorldMarketHotList,
GetWorldMarketList,
GetWorldMarketSubList,
GetWorldMarketSearchList,
GetItemSellBuyInfo,
GetWorldMarketWaitList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment