def getAuthenticatedProfile(self, userFields = None): """ User - Get the authenticated user's profile The user profile contains data related to the authenticated user including (but not limited to); Achievements Authentications (including types and timestamps) Challenges Flags (including armoire, tutorial, tour etc...) Guilds History (including timestamps and values) Inbox Invitations (to parties/guilds) Items (character's full inventory) New Messages (flags for groups/guilds that have new messages) Notifications Party (includes current quest information) Preferences (user selected prefs) Profile (name, photo url, blurb) Purchased (includes purchase history, gem purchased items, plans) PushDevices (identifiers for mobile devices authorized) Stats (standard RPG stats, class, buffs, xp, etc..) Tags TasksOrder (list of all ids for dailys, habits, rewards and todos) userFields: A list of comma separated user fields to be returned instead of the entire document. Notifications are always returned. Example usage: "achievements,items.mounts" """ if userFields == None: url = "https://habitica.com/api/v3/user" return(getUrl(url, self.credentials)) else: url = "https://habitica.com/api/v3/user?userFields=" + userFields return(getUrl(url, self.credentials))
def getContent(contentType=None, language=None): """ Get all available content objects language: Language code used for the items' strings. If the authenticated user makes the request, the content will return with the user's configured language. Default value: en Allowed values: "bg", "cs", "da", "de", "en", "en@pirate", "en_GB", "es", "es_419", "fr", "he", "hu", "id", "it", "ja", "nl", "pl", "pt", "pt_BR", "ro", "ru", "sk", "sr", "sv", "uk", "zh", "zh_TW" contentType: Various data about the content of Habitica. The content route contains many keys, but the data listed below are the recomended data to use. Type: string mystery: The mystery sets awarded to paying subscribers. gear: The gear that can be equipped. tree: Detailed information about the gear, organized by type. flat: The full key of each equipment. spells: The skills organized by class. Includes cards and visual buffs. potion: Data about the health potion. armoire: Data about the armoire. classes: The available classes. eggs: All available eggs. timeTravelStable: The animals available in the Time Traveler's stable, separated into pets and mounts. hatchingPotions: All the hatching potions. petInfo: All the pets with extra info. mountInfo: All the mounts with extra info. food: All the food. userCanOwnQuestCategories: The types of quests that a user can own. quests: Data about the quests. appearances: Data about the apperance properties. hair: Data about available hair options. shirt: Data about available shirt options. size: Data about available body size options. skin: Data about available skin options. chair: Data about available chair options. background: Data about available background options. backgrounds: Data about the background sets. subscriptionBlocks: Data about the various subscirption blocks. """ # Get language. Add to URL as query parameter if specified. if language == None: url = 'https://habitica.com/api/v3/content' else: url = 'https://habitica.com/api/v3/content?language=' + language # Return only specified content. If none specified, return all content. if contentType == None: return (getUrl(url)['data']) else: return (getUrl(url)['data'][contentType])
def getGearAvailableForPurchase(self): """ User - Get the gear items available for purchase for the authenticated user """ url = "https://habitica.com/api/v3/user/inventory/buy" return(getUrl(url, self.credentials))
def getInAppRewards(self): """ User - Get the in app items appearing in the user's reward column """ url = "https://habitica.com/api/v3/user/in-app-rewards" return(getUrl(url, self.credentials))
def getTasks(creds, taskType=None): """ Task - Get a user's tasks creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} taskType: one of ['habits', 'dailys', 'todos', 'rewards', 'completedTodos'] (optional) The returned dictionaries' structure depends on the type of task. Keys defined below: todos keys: attribute, checklist, group, collapseChecklist, tags, text, challenge, userId, value, id, priority, completed, notes, updatedAt, _id, type, reminders, createdAt dailys keys: streak, startDate, isDue, attribute, userId, frequency, updatedAt, id, createdAt, daysOfMonth, group, collapseChecklist, priority, text, type, repeat, tags, checklist, completed, nextDue, weeksOfMonth, yesterDaily, challenge, reminders, everyX, value, _id, notes, history habits keys: attribute, counterUp, group, tags, down, text, challenge, counterDown, userId, up, value, id, priority, frequency, notes, updatedAt, _id, type, reminders, createdAt, history rewards keys: attribute, group, tags, text, challenge, userId, value, id, priority, notes, updatedAt, _id, type, reminders, createdAt completedTodos keys: attribute, dateCompleted, checklist, group, collapseChecklist, tags, text, challenge, userId, value, id, priority, completed, notes, updatedAt, _id, type, reminders, createdAt """ if taskType == None: url = "https://habitica.com/api/v3/tasks/user" else: url = "https://habitica.com/api/v3/tasks/user?type=" + taskType return (getUrl(url, creds))
def getGroupPlans(credentials): """ Group - Get group plans for a user credentials: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} """ url = 'https://habitica.com/api/v3/group-plans' return (getUrl(url, credentials))
def togglePinnedItem(self, key): """ Toggle an item to be pinned key: The key of the item """ url = "https://habitica.com/user/toggle-pinned-item/" + key return(getUrl(url, self.credentials))
def exportDataXML(credentials): """ Data Export - Export user data in XML format username: The new username """ url = "https://habitica.com/export/history.csv" return (getUrl(url, credentials))
def getChallenges(creds): """ Get challenges the user has access to. Includes public challenges, challenges belonging to the user's group, and challenges the user has already joined. creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} """ url = "https://habitica.com/api/v3/challenges/user" return (getUrl(url, creds))
def getGroup(credentials, groupId): """ Group - Get group credentials: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} groupId: The group _id ('party' for the user party and 'habitrpg' for tavern are accepted) """ url = 'https://habitica.com/api/v3/groups/' + groupId return (getUrl(url, credentials))
def getTask(creds, taskId): """ Task - Get a task creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} taskId: The task _id or alias """ url = "https://habitica.com/api/v3/tasks/" + taskId return (getUrl(url, creds))
def getAPIStatus(): """ Get Habitica's API status. Returns -- status: string. 'up' if everything is ok. """ url = "https://habitica.com/api/v3/status" return (getUrl(url))
def getChallenge(creds, challengeId): """ Get a single challenge given its id. creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} challengeId: The challenge _id. Type: UUID """ url = "https://habitica.com/api/v3/challenges/" + challengeId return (getUrl(url, creds))
def getGroupChallenges(creds, groupId): """ Get all challenges for a group creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} groupId: The id of the group to which the challenge belongs. Type: UUID """ url = "https://habitica.com/api/v3/challenges/groups/" + groupId return (getUrl(url, creds))
def getGroupApprovals(creds, groupId): """ Task - Get a group's approvals creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} groupId: The id of the group from which to retrieve the approvals """ url = "https://habitica.com/api/v3/approvals/group/" + groupId return (getUrl(url, creds))
def getAnonymizedUserData(self): """ User - Get anonymized user data Returns the user's data without: Authentication information NewMessages/Invitations/Inbox Profile Purchased information Contributor information Special items Webhooks Notifications """ url = "https://habitica.com/api/v3/user/anonymized" return(getUrl(url, self.credentials))
def exportChallenge(creds, challengeId): """ Export a challenge in CSV creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} challengeId: The challenge _id. Type: UUID Returns a csv file. """ url = "https://habitica.com/api/v3/challenges/" + challengeId + "/export/csv" return (getUrl(url, creds))
def getAPIStatus(): """Get Habitica's API status. Args: No arguments. Returns: Status string: 'up' if everything is ok. """ url = "https://habitica.com/api/v3/status" return (getUrl(url))
def getChat(creds, groupId='party'): """ Chat - Get chat messages from a group. Fetches an array of messages from a group. creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} groupId: The group _id (or 'party'). Type: UUID return keys: userV, notifications, data, appVersion, success """ url = 'https://habitica.com/api/v3/groups/' + groupId + '/chat' return (getUrl(url, creds))
def getGroupPlans(credentials): """Get group plans for a user Args: credentials (dict): Formatted dictionary of user id and api key. If a user object has already been created, use user.credentials. format: {'x-api-user': "******", 'x-api-key': "api_key_here"} Returns: A JSON response object. Keys: userV, notifications, data, appVersion, success. """ url = 'https://habitica.com/api/v3/group-plans' return (getUrl(url, credentials))
def getGroups(credentials, groupType, paginate, page): """ Group - Get groups for a user credentials: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} groupType: The type of groups to retrieve. Must be a query string representing a list of values like 'tavern,party'. Possible values are party, guilds, privateGuilds, publicGuilds, tavern paginate: Public guilds support pagination. When true guilds are returned in groups of 30 Allowed values: "true", "false" page: When pagination is enabled for public guilds this parameter can be used to specify the page number (the initial page is number 0 and not required) """ url = 'https://habitica.com/api/v3/groups/' return (getUrl(url, credentials))
def getGroupTasks(creds, groupId, taskType=None): """ Task - Get a group's tasks creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} groupId: The id of the group from which to retrieve the approvals taskType(optional): Query parameter to return just a type of tasks Allowed values: "habits", "dailys", "todos", "rewards" """ if taskType == None: url = "https://habitica.com/api/v3/tasks/group/" + groupId else: url = "https://habitica.com/api/v3/tasks/group/" + groupId + "?type=" + taskType return (getUrl(url, creds))
def getTags(credentials): """Gets user's tags. Returns a list of dictionaries of tag names and IDs. Args: credentials (dict): Formatted dictionary of user id and api key. If a user object has already been created, use user.credentials. format: {'x-api-user': "******", 'x-api-key': "api_key_here"} Returns: A JSON response object. Keys: userV, notifications, data, appVersion, success. """ url = "https://habitica.com/api/v3/tags/" return(getUrl(url, credentials))
def getChallengeTasks(creds, challengeId, taskType=None): """ Task - Get a challenge's tasks creds: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} challengeId: The id of the challenge from which to retrieve the tasks taskType (optional) Query parameter to return just a type of tasks Allowed values: "habits", "dailys", "todos", "rewards" """ if taskType == None: url = "https://habitica.com/api/v3/tasks/challenge/" + challengeId else: url = "https://habitica.com/api/v3/tasks/challenge/" + challengeId + "?type=" + taskType return (getUrl(url, creds))
def getTag(credentials, tagId): """Get a tag given its ID. Returns a dictionary with the tag's name and ID. Args: credentials (dict): Formatted dictionary of user id and api key. If a user object has already been created, use user.credentials. format: {'x-api-user': "******", 'x-api-key': "api_key_here"} tagId (str): the tag's ID. Returns: A JSON response object. Keys: userV, notifications, data, appVersion, success. """ url = "https://habitica.com/api/v3/tags/" + tagId return(getUrl(url, credentials))
def getChat(creds, groupId='party'): """Get chat messages from a group. Fetches an array of messages from a group. Args: creds (dict): Formatted dictionary of user id and api key. If a user object has already been created, use user.credentials. format: {'x-api-user': "******", 'x-api-key': "api_key_here"} groupId (str): The group id (or 'party'). Default: 'party'. Returns: A JSON response object. Keys: userV, notifications, data, appVersion, success. """ url = 'https://habitica.com/api/v3/groups/' + groupId + '/chat' return (getUrl(url, creds))
def getGroup(credentials, groupId): """Get the data of a group. credentials: a dictionary of user credentials formatted as: {'x-api-user': '******', 'x-api-key': 'your_api_key'} Args: credentials (dict): Formatted dictionary of user id and api key. If a user object has already been created, use user.credentials. format: {'x-api-user': "******", 'x-api-key': "api_key_here"} groupId (str): The group id. 'party' for the user's party and 'habitrpg' for the tavern are accepted. Returns: A JSON response object. Keys: userV, notifications, data, appVersion, success. """ url = 'https://habitica.com/api/v3/groups/' + groupId return (getUrl(url, credentials))
def getGroups(credentials, groupType, paginate, page): """Get groups for a user. Args: credentials (dict): Formatted dictionary of user id and api key. If a user object has already been created, use user.credentials. format: {'x-api-user': "******", 'x-api-key': "api_key_here"} groupType (str): The type of groups to retrieve. Must be a query string. representing a list of values like 'tavern,party'. Possible values: party, guilds, privateGuilds, publicGuilds, tavern. paginate: Public guilds support pagination. When true, guilds are returned in groups of 30. Allowed values: "true", "false" page: When pagination is enabled for public guilds, this parameter can be used to specify the page number (the initial page is number 0 and not required). Returns: A JSON response object. Keys: userV, notifications, data, appVersion, success. """ url = 'https://habitica.com/api/v3/groups/' return (getUrl(url, credentials))
def getContent(contentType=None, language=None): """Get all contents or specified contents on Habitica. Args: language (str): Language code used for the items' strings. If the authenticated user makes the request, the content will return with the user's configured language. Default value: en Allowed values: "bg", "cs", "da", "de", "en", "en@pirate", "en_GB", "es", "es_419", "fr", "he", "hu", "id", "it", "ja", "nl", "pl", "pt", "pt_BR", "ro", "ru", "sk", "sr", "sv", "uk", "zh", "zh_TW" contentType (str): Various data about the content of Habitica. The content route contains many keys, but the data listed under "Attributes" are the recomended data to use. Attributes: mystery: The mystery sets awarded to paying subscribers. gear: The gear that can be equipped. tree: Detailed information about the gear, organized by type. flat: The full key of each equipment. spells: The skills organized by class. Includes cards and visual buffs. potion: Data about the health potion. armoire: Data about the armoire. classes: The available classes. eggs: All available eggs. timeTravelStable: The animals available in the Time Traveler's stable, separated into pets and mounts. hatchingPotions: All the hatching potions. petInfo: All the pets with extra info. mountInfo: All the mounts with extra info. food: All the food. userCanOwnQuestCategories: The types of quests that a user can own. quests: Data about the quests. appearances: Data about the apperance properties. hair: Data about available hair options. shirt: Data about available shirt options. size: Data about available body size options. skin: Data about available skin options. chair: Data about available chair options. background: Data about available background options. backgrounds: Data about the background sets. subscriptionBlocks: Data about the various subscirption blocks. A list of all content types (as of December 21, 2019): achievements, questSeriesAchievements, animalColorAchievements, quests, questsByLevel, userCanOwnQuestCategories, itemList, gear, spells, subscriptionBlocks, audioThemes, mystery, officialPinnedItems, bundles, potion, armoire, classes, gearTypes, cardTypes, special, dropEggs, questEggs, eggs, timeTravelStable, dropHatchingPotions, premiumHatchingPotions, wackyHatchingPotions, hatchingPotions, pets, premiumPets, questPets, specialPets, wackyPets, petInfo, mounts, questMounts, premiumMounts, specialMounts, mountInfo, food, appearances, backgrounds, backgroundsFlat, userDefaults, tasksByCategory, userDefaultsMobile, faq, loginIncentives Returns: A dictionary of the specified content objects or a dictionary of all content objects if contentType is not specified. """ # Get language. Add to URL as query parameter if specified. if language == None: url = 'https://habitica.com/api/v3/content' else: url = 'https://habitica.com/api/v3/content?language=' + language # Return only specified content. If none specified, return all content. if contentType == None: return (getUrl(url)['data']) else: return (getUrl(url)['data'][contentType])
def exportChallenge(self): """ Export a challenge in CSV """ url = "https://habitica.com/api/v3/challenges/" + self.id + "/export/csv" return (getUrl(url, self.credentials))