Habitica Wiki
Habitica Wiki
Advertisement
Habitica Wiki



Auto Accept Quests[]

by cTheDragons

(Note: An upgraded version of this script with an easy step-by-step setup guide with pictures can be found on this link)

Run hourly, this script will join a quest automatically if the invite is available in your party.

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor, replacing the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
 function scheduleJoinQuest() {
   var habId = "#HabiticaUserID#";
   var habToken = "#HabiticaAPIToken#";
 
   var paramsTemplate = {
     "method" : "get",
     "headers" : {
       "x-api-user" : habId, 
       "x-api-key" : habToken    
     }
   }  
   var response = UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party", paramsTemplate);
   var party = JSON.parse(response);
 
   if ((party.data.quest.key != undefined) && (party.data.quest.active != true) && (party.data.quest.members[habId] == undefined)){
   paramsTemplate = {
       "method" : "post",
       "headers" : {
         "x-api-user" : habId, 
         "x-api-key" : habToken       
       }     
     }
     var params = paramsTemplate;
  
     UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party/quests/accept", params)
   }
 }

OR more clear code below:

const scheduleJoinQuest = () => {
  const habId = '#HabiticaUserID#';
  const habToken = '#HabiticaAPIToken#';
  const partyAPI = 'https://habitica.com/api/v3/groups/party';
  const headers = {
    'x-api-user': habId,
    'x-api-key': habToken,
  };
  const response = UrlFetchApp.fetch(
    partyAPI,
    {
      method: 'get',
      headers
    }
  );
  const { data: { quest } } = JSON.parse(response);

  if (quest.key && !quest.active && !quest.members[habId]) {
    UrlFetchApp.fetch(
      `${partyAPI}/quests/accept`,
      {
        method: 'post',
        headers
      }
    );
  }
}
  • From the sidebar on the left, select Triggers. Then add a trigger that runs scheduleJoinQuest Time-driven on an Hour timer with the parameter of Every hour.
  • Save and you're done!
Advertisement