### Chained Promise Example Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Provides an example of chaining promises with the TeamSnap SDK to perform sequential asynchronous operations, such as loading a team and then its members. ```javascript function loadTeamMembers(team) { return teamsnap.loadMembers(team.id).then(function(members) { team.members = members; return team; } } teamsnap.loadTeam(1234).then(loadTeamMembers).then(displayTeam).fail(showError); ``` -------------------------------- ### Start TeamSnap.js Browser OAuth Flow Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Quick-Start Initiates the OAuth browser flow for user authorization when no session is available. Requires a redirect URL (must be same-domain) and an array of scopes. After successful authentication, it loads collections and then teams. ```javascript var redirect = ''; // One of the redirect URLs entered when creating your application, must be same-domain var scopes = ['read', 'write']; teamsnap.startBrowserAuth(redirect, scopes, function(err) { if (err) { alert('Error loading TeamSnap SDK'); return; } teamsnap.loadCollections(function(err) { teamsnap.loadTeams(onTeamsLoad); }); }); ``` -------------------------------- ### Load All Opponent Results (JavaScript) Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/opponents_results.md Loads all opponents results for a given team ID. This method requires a team ID as input and does not explicitly define callback parameters in the provided example. ```javascript teamsnap.loadOpponentsResults(1); ``` -------------------------------- ### Links, Queries, and Commands Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Explains how links in collections and items can be used to navigate and load related data. ```APIDOC ## Links, Queries, and Commands ### Description Both collections and items contain links. Item links are particularly useful for loading or linking related items. For example, to retrieve all availabilities for a member, you can use the `member.links.availabilities.href` or programmatically call `member.loadItems('availabilities').then(...)`. ``` -------------------------------- ### Load Teams with Promises Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Illustrates loading teams using the TeamSnap SDK with promises, showing how to handle successful results and errors using .then(). ```javascript teamsnap.loadTeams().then(function(teams) { console.log(teams); }, function(err) { console.error(err); }); ``` -------------------------------- ### GET /api/members/sort Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/members.md Sorts an array of members by their names. Can sort in reverse order. ```APIDOC ## GET /api/members/sort ### Description Sorts an array of members by their names. Can sort in reverse order. ### Method GET ### Endpoint /api/members/sort ### Parameters #### Query Parameters - **reverse** (bool) - Optional - Sort in reverse order. ### Request Example ```json { "reverse": false } ``` ### Response #### Success Response (200) (No specific response body details provided in the source text, implies a sort function) #### Response Example (No example response provided in the source text) ``` -------------------------------- ### Get Event Sort API Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/events.md Provides a function to sort arrays of events, typically by date. ```APIDOC ## `getEventSort()` ### Description Sorts an array of events. ### Method GET ### Endpoint _N/A (Utility function) ### Parameters _none_ ### Request Example ```javascript // Assuming eventArray is an array of event objects var sortedEvents = eventArray.sort(teamsnap.getEventSort()); ``` ### Response #### Success Response (N/A) - **compareFunction** (function) - A comparison function suitable for use with `Array.prototype.sort()`. #### Response Example _none_ ``` -------------------------------- ### Load Availabilities Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/availabilities.md Loads availabilities from the collection based on provided parameters. ```APIDOC ## GET /availabilities ### Description Loads items from the `availabilities` collection based on given params. ### Method GET ### Endpoint /availabilities ### Parameters #### Query Parameters - **teamId** (int) - Optional - The ID of the team. - **memberId** (int) - Optional - The ID of the member. - **params** (object) - Optional - An object with additional query parameters. Use `teamsnap.collections.availabilities.queries.search.params` to see available search parameters. ### Request Example ```javascript // Loads all availabilities for `teamId: 1`. teamsnap.loadAvailabilities(1); // Loads all availabilities for `memberId: 1`. teamsnap.loadAvailabilities({memberId: 1}); ``` ### Response #### Success Response (200) - **availabilities** (array) - An array of availability objects. #### Response Example ```json { "availabilities": [ { "memberId": 1, "status": 1, "notes": "Available" } ] } ``` ``` -------------------------------- ### GET /api/items/{itemId}/permissions/write Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/members.md Determines if a member has write permissions for a specific item within a team. ```APIDOC ## GET /api/items/{itemId}/permissions/write ### Description Determines if a member has write permissions for a specific item within a team. ### Method GET ### Endpoint /api/items/{itemId}/permissions/write ### Parameters #### Query Parameters - **member** (object) - Required - The member item to test. - **team** (object) - Required - The team item to test against. - **item** (object) - Required - The item item to test against. ### Request Example ```json { "member": { /* member object */ }, "team": { /* team object */ }, "item": { /* item object */ } } ``` ### Response #### Success Response (200) - **canEditItem** (bool) - True if the member has write permissions for the item, false otherwise. #### Response Example ```json { "canEditItem": true } ``` ``` -------------------------------- ### Load Teams with Callback Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Demonstrates how to load teams using the TeamSnap SDK with a Node.js-style callback function to handle the response or errors. ```javascript teamsnap.loadTeams(function(err, teams) { if (err) console.error(err); else console.log(teams); }); ``` -------------------------------- ### GET /api/teams/{teamId}/permissions/edit Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/members.md Checks if a member has permission to manage a specific team (owner or manager). ```APIDOC ## GET /api/teams/{teamId}/permissions/edit ### Description Checks if a member has permission to manage a specific team (owner or manager). ### Method GET ### Endpoint /api/teams/{teamId}/permissions/edit ### Parameters #### Query Parameters - **member** (object) - Required - The member item to test. - **team** (object) - Required - The team item to test against. ### Request Example ```json { "member": { /* member object */ }, "team": { /* team object */ } } ``` ### Response #### Success Response (200) - **canEdit** (bool) - True if the member can edit the team, false otherwise. #### Response Example ```json { "canEdit": true } ``` ``` -------------------------------- ### GET /api/divisions/{divisionId}/members Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/members.md Searches for members within a specific division. Supports filtering by active status. ```APIDOC ## GET /api/divisions/{divisionId}/members ### Description Searches for members within a specific division. Supports filtering by active status. ### Method GET ### Endpoint /api/divisions/{divisionId}/members ### Parameters #### Path Parameters - **divisionId** (id) - Required - The ID of the division to search within. #### Query Parameters - **isActive** (bool) - Optional - Filter for active members. Defaults to all members. ### Request Example ```json { "divisionId": 1, "isActive": true } ``` ### Response #### Success Response (200) - **members** (array) - An array of member objects matching the search criteria. #### Response Example ```json { "members": [ { /* member object */ } ] } ``` ``` -------------------------------- ### Create Forum Topic Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/forum_topics.md Creates a new forum topic item. Accepts an optional data object to initialize the new topic with specific properties. ```javascript var forumTopic = teamsnap.createForumTopic(); var forumTopic = teamsnap.createForumTopic({teamId: 1, title: 'Example!'}); ``` -------------------------------- ### GET /api/members/{memberId}/name Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/members.md Retrieves the full name of a member. Supports different name formats (e.g., 'Last, First') and sorting. ```APIDOC ## GET /api/members/{memberId}/name ### Description Retrieves the full name of a member. Supports different name formats (e.g., 'Last, First') and sorting. ### Method GET ### Endpoint /api/members/{memberId}/name ### Parameters #### Path Parameters - **member** (object) - Required - The member whose name should be returned. #### Query Parameters - **reverse** (bool) - Optional - If true, uses "Last, First" format. - **forSort** (bool) - Optional - Use if sorting names. ### Request Example ```json { "member": { /* member object */ } } ``` ### Response #### Success Response (200) - **memberName** (string) - The full name of the member. #### Response Example ```json { "memberName": "John Doe" } ``` ``` -------------------------------- ### Core SDK Methods: Load, Create, Save, Delete Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Outlines the primary methods provided by the TeamSnap.js SDK for interacting with API resources like assignments. These methods abstract common CRUD operations. ```javascript teamsnap.loadAssignments(params) teamsnap.loadAssignments(teamId) teamsnap.createAssignment() teamsnap.saveAssignment(assignment) teamsnap.deleteAssignment(href) teamsnap.deleteAssignment(assignment) ``` -------------------------------- ### Collections and Items Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Explains how TeamSnap.js interacts with the Collection+JSON format, including collections, items, queries, and commands. ```APIDOC ## Collections and Items The TeamSnap API follows the [Collection+JSON](http://amundsen.com/media-types/collection/) format adding an extention for [Commands](https://gist.github.com/semmons99/6280650). This allows the API to be self-documenting and reduce breaking changes. Because of this, TeamSnap.js works in Collections and Items, though you don't need to know how it works to use the TeamSnap.js. ### Collections There is a collection for each data type (e.g. teams, members, and trackedItems). You can think of them as database tables. Each collection will have a template if it allows items to be saved to it. This template provides all the fields which are allowed when saving an item to the collection. The collections will have links to other collections or resources related to it. The collections may also provide queries and commands. Queries are ways to search the data within the collection, and commands are actions which can be triggered to run, such as sending an email reminder. There is a collection at the root of the API with links to all other collections. After TeamSnap.js is authorized, it loads each of the collections linked off the root collection. This provides TeamSnap.js all the templates, links, queries, and commands that it will need to load and save data. You may access all loaded collections at `teamsnap.collections[collectionName]`. Collections provide the following methods: ***Collection*** * `save(item)` Saves an item to the collection (will create a new item if it has no href) * `loadItems(linkName)` Loads an array of items using the link `linkName` * `loadItem(linkName)` Loads an item using the link `linkName` * `queryItems(queryName, params)` Loads an array of items using the query `queryName` and the provided parameters * `queryItem(queryName, params)` Loads an item using the query `queryName` and the provided parameters * `exec(commandName, params)` Executes a command using the command `commandName` and returns an array of items if the command returns any ``` -------------------------------- ### GET /api/users/{userId}/importableMembers Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/members.md Retrieves a list of members that can be imported, based on the current member's userId. Can include members from archived teams. ```APIDOC ## GET /api/users/{userId}/importableMembers ### Description Retrieves a list of members that can be imported, based on the current member's userId. Can include members from archived teams. ### Method GET ### Endpoint /api/users/{userId}/importableMembers ### Parameters #### Path Parameters - **userId**: [id] - `userId` of current member. #### Query Parameters - **includeArchivedTeams**: [bool] - Include or exclude members from archived teams (optional). ### Request Example ```json { "userId": 8, "includeArchivedTeams": true } ``` ### Response #### Success Response (200) - **importableMembers** (array) - A list of importable members. #### Response Example ```json { "importableMembers": [ { /* member object */ } ] } ``` ``` -------------------------------- ### Create Opponent Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/opponents.md Creates a new opponent item within the SDK. ```APIDOC ## POST /api/opponents ### Description Creates a new opponent item. ### Method POST ### Endpoint /api/opponents ### Parameters #### Request Body - **data** (object | null) - Optional - Data object to apply to the newly created object. ### Request Example ```javascript // Creates a new opponent item. var opponent = teamsnap.createOpponent(); // Creates a new opponent item with `name: 'Example Opponent'`. var opponent = teamsnap.createOpponent({name: 'Example Opponent'}); ``` ### Response #### Success Response (201) - **opponent** (object) - The newly created opponent object. #### Response Example ```json { "opponent": { "id": 1, "name": "Example Opponent" } } ``` ``` -------------------------------- ### Get Member Name Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/members.md Retrieves the full name of a member. It accepts a member object and optional boolean flags to format the name for display or sorting. ```javascript var memberName = teamsnap.memberName(member); ``` -------------------------------- ### Create Forum Topic Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/forum_topics.md Creates a new forum topic item. You can optionally provide data to pre-populate the new topic. ```APIDOC ## POST /forumTopics ### Description Creates a new `forumTopic` item. ### Method POST ### Endpoint /forumTopics ### Parameters #### Request Body - **data** (object, null) - Optional - Data object to apply to the newly created object. ### Request Example ```javascript // Creates a new forumTopic item. var forumTopic = teamsnap.createForumTopic(); // Creates a new forumTopic item with `teamId: 1` and `title: 'Example!'`. var forumTopic = teamsnap.createForumTopic({teamId: 1, title: 'Example!'}); ``` ### Response #### Success Response (201) - **forumTopic** (object) - The newly created forum topic object. #### Response Example ```json { "forumTopic": { "id": 10, "teamId": 1, "title": "Example!", "createdAt": "2023-10-27T10:05:00Z" } } ``` ``` -------------------------------- ### Delete Tracked Item Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/tracked_items.md Deletes a specified 'trackedItem'. This operation requires the 'trackedItem' object to be deleted and accepts an optional 'callback'. The example demonstrates creating, saving, and then deleting an item. ```javascript teamsnap.deleteTrackedItem(trackedItem); ``` ```javascript var trackedItem = teamsnap.createTrackedItem({ teamId: 1, name: 'Example Tracked Item' }); teamsnap.saveTrackedItem(trackedItem).then(function(){ // Save complete, now delete. teamsnap.deleteTrackedItem(trackedItem).then(function(){ // Poof! It's gone! }); }); ``` -------------------------------- ### Load Availabilities using teamsnap-javascript-sdk Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/availabilities.md Loads availability records from the 'availabilities' collection. It accepts a teamId or an object with query parameters, and executes a callback upon completion. The available search parameters can be found via `teamsnap.collections.availabilities.queries.search.params`. ```javascript teamsnap.loadAvailabilities(1); ``` ```javascript teamsnap.loadAvailabilities({memberId: 1}); ``` -------------------------------- ### Load Forum Topics Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/forum_topics.md Loads forum topics based on provided parameters. Accepts a team ID or a query object. Supports callbacks for operation completion. ```javascript teamsnap.loadForumTopics(1); teamsnap.loadForumTopics({id: 1}); ``` -------------------------------- ### Delete Member Email Address - TeamSnap SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/member_email_addresses.md Deletes a specified member email address item. The example demonstrates creating, saving, and then deleting an item, utilizing promise-based callbacks for sequential operations. ```javascript teamsnap.deleteMemberEmailAddress(memberEmailAddress); var memberEmailAddress = teamsnap.createMemberEmailAddress({ memberId: 1, email: 'member@example.com', receivesTeamEmails: true }); teamsnap.saveMemberEmailAddress(memberEmailAddress).then(function(){ // Save complete, now delete. teamsnap.deleteMemberEmailAddress(memberEmailAddress).then(function(){ // Poof! It's gone! }); }); ``` -------------------------------- ### JavaScript Test Initialization Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/lib/test/index.html Initializes the testing environment for TeamSnap.js. This snippet includes a common pattern for requiring test initialization files, which likely sets up the testing framework and dependencies. ```javascript require('test/init') ``` -------------------------------- ### Load Forum Topics Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/forum_topics.md Loads forum topics from the 'forumTopics' collection based on provided parameters. Accepts either a teamId or an object with query parameters. ```APIDOC ## GET /forumTopics ### Description Loads forum topics from the `forumTopics` collection based on given params. ### Method GET ### Endpoint /forumTopics ### Parameters #### Query Parameters - **params** (int, object) - Required - Can be either a `teamId` or an object with query parameters. To see a list of all available search params you can run: `teamsnap.collections.forumTopics.queries.search.params` ### Request Example ```javascript // Loads all forumTopics for `teamId: 1`. teamsnap.loadForumTopics(1); // Loads forumTopic for `id: 1`. teamsnap.loadForumTopics({id: 1}); ``` ### Response #### Success Response (200) - **forumTopics** (array) - An array of forum topic objects. #### Response Example ```json { "forumTopics": [ { "id": 1, "teamId": 1, "title": "Example Topic", "createdAt": "2023-10-27T10:00:00Z" } ] } ``` ``` -------------------------------- ### Get User Payload with Teamsnap Javascript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/users.md Retrieves payload data for a specific user based on memberId. Optional parameters like zone and kuid can be included. The endpoint omits null values and returns all data as strings. ```javascript teamsnap.dspPayload(1); teamsnap.dspPayload({memberId: 1}); teamsnap.dspPayload({memberId: 1, kuid: 123, zone: 1}); ``` -------------------------------- ### Load Forum Posts using Teamsnap JavaScript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/forum_posts.md Loads forum posts from the `forumPosts` collection. It accepts either a teamId or an object with query parameters. The function executes a callback upon completion. Available search parameters can be found via `teamsnap.collections.forumPosts.queries.search.params`. ```javascript teamsnap.loadForumPosts(1); ``` ```javascript teamsnap.loadForumPosts({forumTopicId: 1}); ``` -------------------------------- ### Invite Contact Email Addresses using Teamsnap JavaScript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/contact_email_addresses.md Invites contact email addresses to a team. It requires a params object containing `contactEmailAddressIds`, `teamId`, and `memberId`. The example shows creating a new contact email address and then inviting it. ```javascript teamsnap.inviteContactEmailAddresses(params); ``` ```javascript var contactEmailAddress = teamsnap.createContactEmailAddress({ contactId: 1, email: 'contact@example.com', receivesTeamEmails: true }); var params = { contactEmailAddressIds: [1, 2, 3] teamId: 1, memberId: 2 }; teamsnap.inviteContactEmailAddresses(params).then(function() { // contactEmailAddress has been invited! }); ``` -------------------------------- ### Create Opponent using Teamsnap JavaScript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/opponents.md Creates a new opponent item in the collection. This function accepts an optional data object which can be used to set initial properties for the new opponent. If no data object is provided, an empty opponent record is created. ```javascript var opponent = teamsnap.createOpponent(); var opponent = teamsnap.createOpponent({name: 'Example Opponent'}); ``` -------------------------------- ### Create Team Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/teams.md Creates a new 'team' item. You can optionally provide data to populate the new team. ```APIDOC ## POST /api/teams ### Description Creates a new 'team' item. Optionally accepts a data object to populate the new team. ### Method POST ### Endpoint /api/teams ### Parameters #### Request Body - **data** (object) - Optional - Data object to apply to the newly created team. - **teamId** (int) - Optional - The ID for the new team. - **name** (string) - Optional - The name for the new team. ### Request Example ```javascript // Creates a new team item. var team = teamsnap.createTeam(); // Creates a new team item with `teamId: 1`. var team = teamsnap.createTeam({teamId: 1}); ``` ### Response #### Success Response (201) - **team** (object) - The newly created team object. #### Response Example ```json { "team": { "id": 1, "name": "New Team" } } ``` ``` -------------------------------- ### Persistence Concepts Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Persistence Explains key concepts of the Persistence feature, including linking, single instance enforcement, and rollback. ```APIDOC ## Persistence Concepts ### Description Details the core principles behind the Persistence feature, focusing on how it manages data relationships and integrity. ### Linking Persistence automatically links related items together when loaded. For example, loading a `team` can also load its `members`, `events`, and `availabilities`, creating accessible arrays like `team.members` and `event.availabilities`. This allows for easy traversal of related data, such as `member.team.name` or `availability.member.firstName`. **Note:** Linking is most effective when data is loaded comprehensively. Loading a parent item before its child items (e.g., loading a `team` before its `members`) ensures that links are correctly established. Persistence is optimized for handling entire datasets, such as all data for a team. ### Single Instance Enforcement To prevent data duplication in memory, Persistence ensures that only one instance of an item per `href` is maintained. If you attempt to create or load an item that already exists in memory, the existing instance will be returned or updated. For example, `teamsnap.createEvent({ href: '...' })` will return the existing event if one with that `href` is already loaded. Subsequent loads will update the data on existing items, allowing for data refreshes without creating duplicates. ``` -------------------------------- ### Create Member File Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/member_files.md Creates a new member file item. You can provide an object with initial data for the new member file. ```APIDOC ## POST /memberFiles ### Description Creates a new `memberFile` item. ### Method POST ### Endpoint `/memberFiles` ### Parameters #### Request Body - **data** (object, null) - Optional - Data object to apply to the newly created object. ### Request Example ```javascript // Creates a new memberFile item. var memberFile = teamsnap.createMemberFile(); // Creates a new memberFile item with `memberId: 1` and `phoneNumber: 1`. var memberFile = teamsnap.createMemberFile({memberId: 1}); ``` ### Response #### Success Response (200) - **memberFile** (object) - The newly created member file object. #### Response Example ```json { "memberFile": { "id": 1, "memberId": 1, "fileName": null, "fileSize": 0, "createdAt": "2023-01-01T12:00:00Z" } } ``` ``` -------------------------------- ### Load Opponents using Teamsnap JavaScript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/opponents.md Loads opponents from the collection based on provided parameters. Supports loading by teamId or using query parameters for more specific searches. The function takes either an integer teamId or an object of query parameters, and an optional callback function. ```javascript teamsnap.loadOpponents(1); temansnap.loadOpponents({contactId: 1}); ``` -------------------------------- ### Load Invoices with Teamsnap Javascript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/invoices.md Loads invoice items from the 'invoices' collection using specified parameters. Requires the teamsnap SDK to be initialized. ```javascript teamsnap.loadInvoices({id: 1}); ``` -------------------------------- ### Create Forum Post Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/forum_posts.md Creates a new forum post item. ```APIDOC ## createForumPost(data) ### Description Creates a new `forumPost` item. ### Method POST ### Endpoint `/api/forumPosts` ### Parameters #### Request Body - **data** (object) - Optional - Data object to apply to the newly created object. - **forumTopicId** (int) - Optional - The ID of the forum topic. - **memberId** (int) - Optional - The ID of the member who created the post. - **message** (string) - Optional - The content of the forum post. ### Request Example ```javascript // Creates a new forumPost item. var forumPost = teamsnap.createForumPost(); // Creates a new forumPost item with `forumTopicId: 1` and `memberId: 1`. var forumPost = teamsnap.createForumPost({forumTopicId: 1, memberId: 1}); ``` ### Response #### Success Response (201) - **forumPost** (object) - The newly created forum post object. #### Response Example ```json { "id": 2, "forumTopicId": 1, "memberId": 1, "message": null } ``` ``` -------------------------------- ### Create Sponsor Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/sponsors.md Creates a new sponsor item in the system. ```APIDOC ## `createSponsor(data)` ### Description Creates a new sponsor item. ### Method POST (implied, SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **data** (object, null) - Optional - Data object to apply to the newly created object. ### Request Example ```javascript // Creates a new sponsor item. var sponsor = teamsnap.createSponsor(); // Creates a new sponsor item with `name: 'Example Sponsor'`. var sponsor = teamsnap.createSponsor({name: 'Example Sponsor'}); ``` ### Response #### Success Response (200) Details of the newly created sponsor object. #### Response Example (Not provided in source text, depends on SDK implementation) ``` -------------------------------- ### Load Partners Preferences Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/partners_preferences.md Loads items from the `partnersPreferences` collection based on given params. ```APIDOC ## `loadPartnersPreferences(params, callback)` ### Description Loads items from the `partnersPreferences` collection based on given params. ### Method POST ### Endpoint /partnersPreferences ### Parameters #### Query Parameters - **params** (object) - Required - An object with query parameters. - **callback** (function) - Optional - Callback to be executed when the operation completes. ### Request Example ```javascript // Loads `partnerPreferences` for `teamId: 1, userId: 1`. teamsnap.loadPartnersPreferences({teamId: 1, memberId: 1}); ``` ### Response #### Success Response (200) - **[response structure]** (object) - The loaded partner preferences. #### Response Example ```json { "partnerPreferences": [ { "id": 1, "teamId": 1, "memberId": 1, "preference1": "value1", "preference2": "value2" } ] } ``` ``` -------------------------------- ### Create Forum Post using Teamsnap JavaScript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/forum_posts.md Creates a new forum post item. The `data` parameter is an optional object containing properties for the new post. The method returns the newly created forum post object. ```javascript var forumPost = teamsnap.createForumPost(); ``` ```javascript var forumPost = teamsnap.createForumPost({forumTopicId: 1, memberId: 1}); ``` -------------------------------- ### Create Team - Teamsnap JavaScript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/teams.md Creates a new team item. Accepts an optional data object to pre-populate the new team's properties. ```javascript var team = teamsnap.createTeam(); var team = teamsnap.createTeam({teamId: 1}); ``` -------------------------------- ### Load Team Media Groups using TeamSnap Javascript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/team_media_groups.md Loads team media groups from the collection based on provided parameters. Accepts either a team ID or an object with query parameters. Callback function is executed upon completion. Queryable parameters can be explored using `teamsnap.collections.teamMediaGroups.queries.search.params`. ```javascript teamsnap.loadTeamMediaGroups(1); ``` ```javascript teamsnap.loadTeamMediaGroups({id: 1}); ``` -------------------------------- ### Load Team Stores - JavaScript Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/teamStores.md Loads items from the 'teamStores' collection using provided parameters. Accepts a team ID or an object with query parameters, and a callback function for completion. ```javascript teamsnap.loadTeamStores(1); ``` ```javascript teamsnap.loadAvailabilities({"id": 1}); ``` -------------------------------- ### Create Payment Note Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/payment_notes.md Creates a new payment note item with optional initial data. ```APIDOC ## POST /api/paymentNotes ### Description Creates a new `paymentNote` item. ### Method POST ### Endpoint /api/paymentNotes ### Parameters #### Request Body - **data** (object) - Optional - Data object to apply to the newly created object. Can include fields like `teamId`, `memberPaymentId`, `noteAuthorUserId`, `note`. ### Request Example ```javascript // Creates a new paymentNote item. var paymentNote = teamsnap.createPaymentNote(); // Creates a new paymentNote item with `teamId: 1`. var paymentNote = teamsnap.createPaymentNote({teamId: 1}); ``` ### Response #### Success Response (201) - **paymentNote** (object) - The newly created payment note object. #### Response Example ```json { "paymentNote": { "id": 1, "teamId": 1, "memberPaymentId": null, "noteAuthorUserId": null, "note": null, "createdAt": "2023-10-27T10:00:00Z", "updatedAt": "2023-10-27T10:00:00Z" } } ``` ``` -------------------------------- ### Bulk Load Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/teams.md Queries and returns multiple types of items for a given team based on provided parameters. Supports basic and advanced filtering. ```APIDOC ## POST /api/bulk_load ### Description Queries and returns multiple types of items for a given team based on provided parameters. Supports basic and advanced filtering ('Smart Load'). _Note: Some items, like `availability`, are not available for `bulkLoad` for performance reasons. Loading many types without narrowing the scope may result in suboptimal responses or timeouts._ ### Method POST ### Endpoint /api/bulk_load ### Parameters #### Option 1: Simple Load - **teamId** (int) - Required - The ID of the team to load items for. - **types** (array) - Required - An array of item types to load (e.g., ['member', 'event']). #### Option 2: Smart Load (Advanced Filtering) - **params** (object) - Required - An object containing the following parameters: - **teamId** (int) - Required - The ID of the team to load items for. - **types** (array) - Required - An array of item types to load. - **scopeTo** (string) - Optional - The item type to scope other items to. - **[itemType__queryParam]** (string) - Optional - Additional filters using item type and available search parameters (e.g., `event__id: '1,2,3'`). ### Request Example ```javascript // Bulk loads several types at once for teamId 1. teamsnap.bulkLoad(1, ['member', 'event', 'assignment']); // Bulk loads events and assignments related to eventIds 1-6 for teamId 1. var bulkLoadParams = { teamId: 1, types: ['event', 'assignment'], scopeTo: 'event', event__id: '1,2,3,4,5,6' }; teamsnap.bulkLoad(bulkLoadParams); ``` ### Response #### Success Response (200) - **data** (object) - An object containing the requested item types and their data. #### Response Example ```json { "data": { "members": [...], "events": [...], "assignments": [...] } } ``` ``` -------------------------------- ### Load Team Paypal Preferences Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/teams_paypal_preferences.md Loads a singular teamPaypalPreferences item based on given parameters. ```APIDOC ## GET /teamsPaypalPreferences/{id} ### Description Loads a singular `teamPaypalPreferences` item based on given params. ### Method GET ### Endpoint /teamsPaypalPreferences/{id} ### Parameters #### Query Parameters - **params** (int, object) - Required - Can be either a `teamId` or an object with query parameters. Use `teamsnap.collections.teamsPaypalPreferences.queries.search.params` to see available search parameters. #### Path Parameters - **id** (int) - Required - The ID of the teamPaypalPreferences item to load. ### Request Example ```javascript // Loads a teamPublicSite for `id: 1`. teamsnap.loadTeamPaypalPreferences({id: 1}); ``` ### Response #### Success Response (200) - **teamPaypalPreferences** (object) - A single teamsPaypalPreferences item. #### Response Example ```json { "teamPaypalPreferences": { "id": 1, "teamId": 1, "paypalEmail": "test@example.com" } } ``` ``` -------------------------------- ### Load a Specific Plan by ID using Teamsnap Javascript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/plans.md Loads a specific plan by its ID or other query parameters. It accepts either a teamId or an object with query parameters, along with a callback function. ```javascript teamsnap.loadPlans({id: 1}); ``` -------------------------------- ### Load Team Public Sites Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/team_public_sites.md Loads team public sites based on provided parameters. Supports filtering by teamId or query parameters. Retrieves a list of team public sites. ```javascript teamsnap.loadTeamPublicSites(1); teamsnap.loadTeamPublicSites({id: 1}); ``` -------------------------------- ### Asynchronous Operations: Callbacks and Promises Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Details how to handle asynchronous operations in TeamSnap.js using either Node.js-style callbacks or promises. ```APIDOC ## Callbacks and promises TeamSnap.js asynchronous methods support both the Node.js callback style or the jQuery (and other) promises style of handling asynchronous methods. ### Callbacks TeamSnap.js asynchronous methods all take `callback` as the last argument in regular Node.js style. This is a callback function with the signature `function (err, result) { ... }` which will be called when the operation is complete. ```javascript teamsnap.loadTeams(function(err, teams) { if (err) console.error(err); else console.log(teams); }); ``` ### Promises In addition to accepting a `callback` argument, asynchronous methods also return a promise in order for your code to use promises instead of callbacks. A promise is an object with methods on it that allow you to respond to certain outcomes of the code. For mor information about promises in general, see http://davidwalsh.name/write-javascript-promises and http://www.mattgreer.org/articles/promises-in-wicked-detail/. Once nice thing about promises is they can be chained, and the results of previous handlers are passed on to the next handlers. And if a handler returns another promise, this "pauses" the chain until it is finished, allowing for much more readable chains of asynchronous actions. ```javascript teamsnap.loadTeams().then(function(teams) { console.log(teams); }, function(err) { console.error(err); }); // chained example function loadTeamMembers(team) { return teamsnap.loadMembers(team.id).then(function(members) { team.members = members; return team; } } teamsnap.loadTeam(1234).then(loadTeamMembers).then(displayTeam).fail(showError); ``` ``` -------------------------------- ### Create Batch Invoice Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/batch_invoices.md Creates a new batch invoice item. Allows for initial data to be provided during creation. ```APIDOC ## POST /batchInvoices ### Description Creates a new `batchInvoice` item. ### Method POST ### Endpoint /batchInvoices ### Parameters #### Request Body - **data** (object, null) - Optional - Data object to apply to the newly created object. ### Request Example ```javascript // Creates a new batchInvoice item. var batchInvoice = teamsnap.createBatchInvoice(); // Creates a new batchInvoice item with `divisionId: 1` and `description: 'Tourney Fees'`. var batchInvoice = teamsnap.createBatchInvoice({divisionId: 1, description: 'Tourney Fees'}); ``` ### Response #### Success Response (201) - **batchInvoice** (object) - The newly created batch invoice object. #### Response Example ```json { "batchInvoice": { "id": 10, "divisionId": 1, "description": "Tourney Fees" } } ``` ``` -------------------------------- ### Create Forum Subscription - JavaScript Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/forum_subscriptions.md Creates a new forum subscription item. Accepts an optional data object to pre-populate the new subscription with specific details like `forumTopicId` and `memberId`. ```javascript var forumSubscription = teamsnap.createForumSubscription(); ``` ```javascript var forumSubscription = teamsnap.createForumSubscription({forumTopicId: 1, memberId: 1}); ``` -------------------------------- ### Load Opponents Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/opponents.md Loads opponents from the 'opponents' collection based on provided parameters. Can accept a teamId or an object with query parameters. ```APIDOC ## GET /api/opponents ### Description Loads opponents from the 'opponents' collection based on provided parameters. Can accept a teamId or an object with query parameters. ### Method GET ### Endpoint /api/opponents ### Parameters #### Query Parameters - **params** (integer | object) - Required - Can be either a `teamId` or an object with query parameters (e.g., `{contactId: 1}`). - **callback** (function) - Optional - Callback to be executed when the operation completes. ### Request Example ```javascript // Loads all opponents for `teamId: 1`. teamsnap.loadOpponents(1); // Loads all opponents for `contactId: 1`. teamsnap.loadOpponents({contactId: 1}); ``` ### Response #### Success Response (200) - **opponents** (array) - An array of opponent objects. #### Response Example ```json { "opponents": [ { "id": 1, "name": "Example Opponent", "teamId": 1 } ] } ``` ``` -------------------------------- ### Load All Plans for a Team using Teamsnap Javascript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/plans.md Loads all plans associated with a specific team ID. It takes the team ID as a parameter and optionally a callback function. ```javascript teamsnap.loadPlans(1); ``` -------------------------------- ### Core CRUD Operations (load, create, save, delete) Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Details on the primary methods provided by the TeamSnap.js SDK for managing assignments and other item types. ```APIDOC ## Core CRUD Operations ### Description TeamSnap.js offers methods for every action available via the API, abstracting direct use of collection and item methods. The following examples use 'assignments' but apply broadly. ### `teamsnap` Methods * `loadAssignments(params)`: Loads items by provided parameters (e.g., `{ memberId: 123 }`). * `loadAssignments(teamId)`: Loads items belonging to a specific team. This is a shortcut for `loadAssignments({ teamId: teamId })` and does not apply to items not associated with teams (like `timeZone`). * `createAssignment()`: Returns a new, unsaved item of the specified type immediately (synchronous). * `saveAssignment(assignment)`: Saves an item. Handles validation errors, which can be checked via `err instanceof TSValidationError` or by inspecting the `err.field` property. * `deleteAssignment(href)` or `deleteAssignment(assignment)`: Deletes an item using its `href` or the item object itself. ### Notes on Specific Types * `create*`, `save*`, and `delete*` methods are not available for read-only collections like `timeZone`, `plan`, and `sport`. * Some types, such as `availability`, `trackedItemStatus`, and `customDatum`, are managed automatically by the system and only support `save*` operations. * Custom methods exist for specific commands, like `teamsnap.deleteEvent(event, include)` for deleting repeating events. Detailed documentation for each method is available separately. ``` -------------------------------- ### Create Repeating Assignments with Teamsnap JavaScript SDK Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/assignments.md Demonstrates how to create repeating assignments using the `createBulkAssignments` method. This function takes parameters such as the assignment type, description, and recurrence intervals. Ensure the SDK is properly initialized before use. ```javascript // ~~~~~ // Creates repeating assignments. teamsnap.createBulkAssignments("future_games", "test description" , 1, 2); ``` -------------------------------- ### Load Teams Paypal Preferences Source: https://github.com/teamsnap/teamsnap-javascript-sdk/blob/main/docs/collections/teams_paypal_preferences.md Loads items from the teamsPaypalPreferences collection based on given parameters. ```APIDOC ## GET /teamsPaypalPreferences ### Description Loads items from the `teamsPaypalPreferences` collection based on given params. ### Method GET ### Endpoint /teamsPaypalPreferences ### Parameters #### Query Parameters - **params** (int, object) - Required - Can be either a `teamId` or an object with query parameters. Use `teamsnap.collections.teamsPaypalPreferences.queries.search.params` to see available search parameters. ### Request Example ```javascript // Loads all teamsPaypalPreferences for `teamId: 1`. teamsnap.loadTeamsPaypalPreferences(1); // Loads all teamsPaypalPreferences for `id: 1`. teamsnap.loadTeamsPaypalPreferences({id: 1}); ``` ### Response #### Success Response (200) - **teamsPaypalPreferences** (array) - A list of teamsPaypalPreferences items. #### Response Example ```json { "teamsPaypalPreferences": [ { "id": 1, "teamId": 1, "paypalEmail": "test@example.com" } ] } ``` ``` -------------------------------- ### TeamSnap.js Conventions Source: https://github.com/teamsnap/teamsnap-javascript-sdk/wiki/Overview Explains the internal casing conventions used by the TeamSnap.js SDK, which converts API snake_case to JavaScript camelCase. ```APIDOC ## Conventions ### Camelcasing Although TeamSnap's API uses snake-casing (e.g. tracked_item_status), TeamSnap.js converts everything into camelcase (trackedItemStatus) to follow general JavaScript conventions. You will never see any snake-cased methods, types, commands, etc. as it gets converted on load and send. ```