Summary[]
This script allows a user to buy in bulk from the Enchanted Armoire and to view the results in the script's logs. This version allows you to "install" to run the script automatically at the repetitions and interval you choose.
Code[]
You can find the code here: Google Apps Script
Installation[]
Create the script[]
- Click here to go to the Bulk Buy Enchanted Armoire script.
- If you're not already signed into your Google account, you'll be asked to sign in.
- Go to the "Overview," the top tab on the left side (a circle with an āiā inside)
- Click the "Copy" icon on the far right (two papers)
- Rename your new script, removing āCopy ofā
- Save the script (disk icon)
Personalize the script[]
- Open your API Settings. Highlight and copy your User ID (it looks something like this:
377a4d3d-c55c-48b8-9bf8-59b97480daf8). In the Reschedule Tasks script, paste your User ID between the quotations where it saysconst USER_ID = "".- It should now look something like this:
const USER_ID = "377a4d3d-c55c-48b8-9bf8-59b97480daf8".
- It should now look something like this:
- On the same page where you copied your User ID, click the "Show API Token" button, and copy your API Token. In the Google script, paste your API Token between the quotations where it says
const API_TOKEN = "".- It should now look something like this:
const API_TOKEN = "377a4d3d-c55c-48b8-9bf8-59b97480daf8".
- It should now look something like this:
- Enter your desired
repetions(how many times you want to purchase each time this script runs). - Enter your desired
frequency(the the number of hours between purchases, e.g. "purchase every 2 hours") - Save the script (disk icon)
Run the Install function[]
- Ensure that the
installfunction is listed in the drop down menu to the right of ādebugā - Click ārun,ā to the left of ādebugā
- You should see "Execution completed" in the Execution Log.
You may need to authorize the script[]
The first time you run a function or deploy the script, it will ask you to grant permission on your Google account. When you see this pop-up:
- Click "Review permissions" then select your Google account
- Click "Advanced," a small blue link at the bottom
- Click "Go to [name of script] (unsafe)"
- Click "Allow" at the bottom
Modify / Uninstall[]
- To change the trigger frequency, simply change the Frequency variable and then run the
installfunction - To modify the number of purchases, change the Repetitions variable and save the script
- To remove the trigger, simply run the
uninstallfunction
Contact[]
Please message @benniefolyfe for questions, suggestions, or troubleshooting. I'm happy to help!
Gratitude[]
Thanks to cTheDragons for laying the foundation for this script!
Legacy Code[]
Below is cTheDragons' original code to purchase from the armoire:
function bulkBuyArmorie() {
var habId = "#HabiticaUserID#";
var habToken = "#HabiticaAPIToken#";
var ntimes = 5
var url = "https://habitica.com/api/v3/user/buy-armoire"
var sleepTime = 30000
var response
//set paramaters
var paramsTemplate = {
"method": "post",
"headers": {
"x-api-user": habId,
"x-api-key": habToken,
"x-client": habId + "-Bulk Buy Enchanted Armoire"
}
}
var params = paramsTemplate;
for (var i = 0; i < ntimes; i++) {
response = UrlFetchApp.fetch(url, params)
var result = JSON.parse(response);
Logger.log(result.message)
if (result.data.armoire.type == 'food') {
Logger.log("You gained " + result.data.armoire.dropText + ".")
} else {
Logger.log("You gained " + result.data.armoire.value + " " + result.data.armoire.type + ".")
}
Utilities.sleep(sleepTime);// pause in the loop for 30000 milliseconds (30 seconds); this is to avoid the servers being overloaded
}
}