### Setup User Request (HTTP) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/setup-user-method This snippet shows the HTTP GET request format for the setup user method in TeamDesk API v2. It requires the application ID and specifies the desired response format (JSON or XML). ```http GET https://www.teamdesk.net/secure/api/v2/{appid}/setup/user.{json|xml}?parameters ``` -------------------------------- ### GET /secure/api/v2/{appid}/setup/user.{json|xml} Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/setup-user-method Allows adding or modifying a user in your database. The user must have 'ManageUsers' privilege. It supports both JSON and XML responses. ```APIDOC ## GET /secure/api/v2/{appid}/setup/user.{json|xml} ### Description Allows adding or modifying a user in your database. Authorized users must have _ManageUsers_ privilege to call this method. If the user account does not exist, it is created. ### Method GET ### Endpoint `https://www.teamdesk.net/secure/api/v2/{appid}/setup/user.{json|xml}` ### Parameters #### Query Parameters - **email** (string) - Required - The user's email. Can be in the format 'Name' . If the user does not exist, they will be created, and their first and last names will be pre-filled from the name part if present. - **role** (string) - Optional - The role to assign. Pass an empty string (e.g., `role=`) to disable the user. - **defaultSet** (integer) - Optional - `1` to include the user in the default user set, `0` otherwise. - **external** (integer) - Optional - `1` if the user is an external user, `0` otherwise. - **invite** (integer) - Optional - `1` to send a default invitation letter, `0` to skip sending. Defaults to `0`. ### Request Example ``` GET https://www.teamdesk.net/secure/api/v2/YOUR_APP_ID/setup/user.json?email=%22John%20Doe%22%20%3Cjohn.doe%40example.com%3E&role=Admin&defaultSet=1&external=0&invite=1 ``` ### Response #### Success Response (200 or 201) - **status** (integer) - The status code (201 for created, 200 for updated). - **ticket** (string) - Authorization ticket for the invitation email (if applicable). #### Response Example (JSON) ```json { "status": 201, "ticket": "5c98ad47-c6ca-437d-8c2f-cb2f929c54b8" } ``` #### Response Example (XML) ```xml 201 5c98ad47-c6ca-437d-8c2f-cb2f929c54b8 ``` ``` -------------------------------- ### Example Formula Column Syntax Source: https://www.teamdesk.net/help/columns/default-calculate-vs-formula-column Demonstrates the syntax for creating a Formula-Numeric column in TeamDesk. This example uses a conditional logic to determine the output value based on the 'Delivery Type' column. ```TeamDesk Formula If ([Delivery Type] = "Express", 5, 10) ``` -------------------------------- ### Setup User Response (XML) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/setup-user-method This snippet shows the expected XML response when successfully adding or updating a user via the TeamDesk API v2 setup user method. It includes a status code and an authorization ticket if an invitation is sent. ```xml 201 5c98ad47-c6ca-437d-8c2f-cb2f929c54b8 ``` -------------------------------- ### Example User Information Retrieval Request (TeamDesk API) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/user-method An example of a specific HTTP GET request to retrieve user information in JSON format for a given application ID (21995) from the TeamDesk API. ```HTTP GET https://www.teamdesk.net/secure/api/v2/21995/user.json ``` -------------------------------- ### Setup User Response (JSON) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/setup-user-method This snippet illustrates the expected JSON response when successfully adding or updating a user via the TeamDesk API v2 setup user method. It includes a status code and an authorization ticket if an invitation is sent. ```json { // 201 - created, 200 - updated "status": 201, // authorization ticket for invitation email "ticket": "5c98ad47-c6ca-437d-8c2f-cb2f929c54b8" } ``` -------------------------------- ### Example: Random Color Generation Source: https://www.teamdesk.net/help/working-with-formulas/formula-building-blocks/functions/numeric-functions/random An example demonstrating how to use the Random(from, to) function in conjunction with Floor and Case to generate a random color from a predefined list. This showcases a practical application of the random number generation within a specific range. ```TeamDesk Case(Floor(Random(0,6)), 0, "red", 1, "orange", 2, "yellow", 3, "green", 4, "blue", 5, "indigo") ``` -------------------------------- ### Example User Information Response (TeamDesk API) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/user-method This is an example JSON response returned by the TeamDesk API when requesting user information. It includes details such as user ID, email, name, role, culture, timezone, and administrative permissions. ```JSON { "id": 12345, "email": "test@test.com", "firstName": "Test", "lastName": "User", "role": "Default Role", "culture": "en-US", "timezone": "America/Chicago", "admin": "CustomizeApplication, ManageUsers, ManageData" } ``` -------------------------------- ### Table Structure Response Example (JSON) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/describe-table-method This is an example of the JSON response returned by the Describe (Table) method. It includes metadata about the table, such as its record names, aliases, and display settings, as well as detailed descriptors for its columns and views. Note that the structure may be extended in the future. ```JSON { "id": 115442, "recordName": "Test", "recordsName": "Tests", "alias": "t_115442", "showTab": true, "color": "#0061B0", "allowAdd": true, "key": "Id", "columns": [ { "id": 2445930, "name": "Text", "alias": "f_2445930", "type": "Text", "dataOptions": "AllowAddSimilar, AllowFind", "displayOptions": "ShowInViews", "width": 40 } ], "views": [ { "id": 730247, "type": "Table", "name": "Default View", "alias": "v_730247", "showInMenu": true, "actions": "Add, Edit, View, Delete" } ] } ``` -------------------------------- ### URL to Generate QR Code Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Creates a URL that generates a QR code image for given content, with specified dimensions. ```APIDOC ## URL to Generate QR Code as an Image ### Description Returns a URL to an image with a QR Code. ### Method GET ### Endpoint /barcode/qrcode.png ### Parameters #### Query Parameters - **s** (string) - Required - The content to encode in the QR code. - **w** (string) - Optional - The width of the QR code image (e.g., '5cm', '100px'). - **h** (string) - Optional - The height of the QR code image (e.g., '5cm', '100px'). ### Request Example ``` Left(URLRoot(),"/db/") & "/barcode/qrcode.png?s=" & URLEncode("QR Code content") & "&w=5cm" & "&h=5cm" ``` ### Response This function returns a URL that, when accessed, displays a QR code image. ``` -------------------------------- ### Attachment Method - Using GUID Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/attachment-method Retrieves file metadata or content using a GUID. Supports HEAD for metadata and GET for content. ```APIDOC ## HEAD /secure/api/v2/{appid}/{table}/{column}/attachment/{guid} ### Description Retrieves the file metadata identified by GUID from the specified column in a table. ### Method HEAD ### Endpoint `/secure/api/v2/{appid}/{table}/{column}/attachment/{guid}` ### Parameters #### Path Parameters - **appid** (string) - Required - The application ID. - **table** (string) - Required - The singular name of the table or its alias. - **column** (string) - Required - The name or alias of the column to query. - **guid** (string) - Required - The globally unique identifier of the file. ### Response #### Success Response (200) - **Cache-Control** (string) - Cache control headers. - **Content-Disposition** (string) - Attachment details including filename. - **X-Revision** (string) - The revision number of the file. - **Content-Type** (string) - The MIME type of the file. - **Content-Length** (string) - The size of the file in bytes. - **Last-Modified** (string) - The last modified date of the file. - **X-Author** (string) - The author of the file. #### Response Example ``` HTTP/1.1 200 OK Cache-Control: no-cache Content-Disposition: attachment; filename=DSC02688.JPG; filename*=utf-8''DSC02688.JPG X-Revision: 2 Content-Type: image/jpeg Content-Length: 326133 Last-Modified: Wed, 03 Dec 2014 16:02:31 GMT X-Author: test user ``` ## GET /secure/api/v2/{appid}/{table}/{column}/attachment/{guid} ### Description Retrieves the file content identified by GUID from the specified column in a table. ### Method GET ### Endpoint `/secure/api/v2/{appid}/{table}/{column}/attachment/{guid}` ### Parameters #### Path Parameters - **appid** (string) - Required - The application ID. - **table** (string) - Required - The singular name of the table or its alias. - **column** (string) - Required - The name or alias of the column to query. - **guid** (string) - Required - The globally unique identifier of the file. ### Response #### Success Response (200) - **Cache-Control** (string) - Cache control headers. - **Content-Disposition** (string) - Attachment details including filename. - **X-Revision** (string) - The revision number of the file. - **Content-Type** (string) - The MIME type of the file. - **Content-Length** (string) - The size of the file in bytes. - **Last-Modified** (string) - The last modified date of the file. - **X-Author** (string) - The author of the file. - **... binary data ...** - The actual file content. #### Response Example ``` HTTP/1.1 200 OK Cache-Control: private, must-revalidate, max-age=0 ETag: "1234567890.1234567890" Content-Disposition: attachment; filename=DSC02688.JPG; filename*=utf-8''DSC02688.JPG X-Revision: 2 Content-Type: image/jpeg Content-Length: 326133 Last-Modified: Wed, 03 Dec 2014 16:02:31 GMT X-Author: test user ... binary data ... ``` ``` -------------------------------- ### URL to Record Preview Screen Formula Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Returns a URL to the current record's preview screen, including table and record IDs, and back URL. ```APIDOC ## URL to the record preview screen ### Description Returns a URL to the current record preview screen. ### Method Formula - URL ### Endpoint N/A (Formula) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` URLRoot() & "/preview.aspx?t=" & TableId() & "&id=" & RecordId() & "&back=" & BackURL() ``` ### Response #### Success Response (200) - **URL**: A URL to the record preview screen. #### Response Example ```json { "result": "https://yourdomain.teamdesk.com/preview.aspx?t=45&id=123&back=http://example.com" } ``` ``` -------------------------------- ### TeamDesk API Delete Request Example (JSON) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/delete-method Example of an HTTP GET request to the TeamDesk API to delete records with specific keys. This format is used for JSON responses. ```HTTP GET https://www.teamdesk.net/secure/api/v2/21995/Test/delete.json?key=56&key=57 ``` -------------------------------- ### Querying All Columns (HTTP) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/select-table-method This example shows how to query all updateable columns from the first 500 records in a table named 'Test'. It uses the default 'json' format and omits specific column or filter parameters. ```HTTP GET https://www.teamdesk.net/secure/api/v2/21995/Test/select.json ``` -------------------------------- ### Retrieve Attachments - Example Request (HTTP) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/attachments-method An example HTTP GET request to retrieve a list of attachments from the 'File' column in the 'Test' table for a record with ID 56. The response format is specified as JSON. ```HTTP GET https://www.teamdesk.net/secure/api/v2/21995/Test/File/attachments.json?id=56 ``` -------------------------------- ### TeamDesk API Delete Request Example (XML) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/delete-method Example of an HTTP GET request to the TeamDesk API to delete records with specific IDs, suppressing workflow rules. This format is used for XML responses. ```HTTP GET https://www.teamdesk.net/secure/api/v2/21995/Test/delete.xml?id=56&id=57&workflow=0 ``` -------------------------------- ### Example: Get First Wednesday After Specific Date (TeamDesk) Source: https://www.teamdesk.net/help/working-with-formulas/formula-building-blocks/functions/date-functions/nextdayofweek Illustrates using NextDayOfWeek with a hardcoded date. This example finds the first Wednesday after March 22, 2013. The date is specified in the format #YYYY-MM-DD#, and Wednesday is represented by the numeric value 3. ```TeamDesk NextDayOfWeek(#2013-03-22#, 3) ``` -------------------------------- ### URL to Export View Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Provides URLs to export view data in various formats including XLSX, CSV, and HTML. ```APIDOC ## URL to Export View ### Description Use the following formulas to export a view in different formats. ### Method GET ### Endpoint /exportview.aspx/ ### Parameters #### Path Parameters - **Your File Name** (string) - Required - The desired name for the exported file. #### Query Parameters - **format** (integer) - Required - The export format: - `2`: Microsoft Excel (XLSX) - `0`: Comma-Separated Values (CSV) - `1`: Hypertext Markup Language (HTML) - **id** (integer) - Required - The ID of the view to export. - **filter** (string) - Optional - A URL-encoded TeamDesk formula to apply additional filters to the view data. ### Request Example (XLSX) ``` URLRoot() & "/exportview.aspx/" & URLEncode("Your File Name") & ".xlsx?format=2&id=" ``` ### Request Example (CSV) ``` URLRoot() & "/exportview.aspx/" & URLEncode("Your File Name") & ".csv?format=0&id=" ``` ### Request Example (HTML) ``` URLRoot() & "/exportview.aspx/" & URLEncode("Your File Name") & ".html?format=1&id=" ``` ### Response This function returns a URL that initiates the download of the view data in the specified format. ``` -------------------------------- ### Example: Get First Monday After Date Received (TeamDesk) Source: https://www.teamdesk.net/help/working-with-formulas/formula-building-blocks/functions/date-functions/nextdayofweek Demonstrates how to use the NextDayOfWeek function to find the first Monday following the date in the 'Date Received' column. This example adds one day to the 'Date Received' and then specifies Monday (1) as the target weekday. ```TeamDesk NextDayOfWeek([Date Received] + 1d, 1) ``` -------------------------------- ### Generate URL for QR Code Image Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Creates a URL that generates a QR code as an image. It takes content to be encoded and specifies image dimensions. Dependencies include URLRoot() and URLEncode(). ```TeamDesk Formula Left(URLRoot(),"/db/") & "/barcode/qrcode.png?s=" & URLEncode("QR Code content") & "&w=5cm" & "&h=5cm" ``` -------------------------------- ### Describe Test API Database Example Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/describe-database-method This snippet provides a concrete example of a GET request to the Describe API endpoint for a specific application ID (21995), requesting the response in JSON format. This is used to fetch the description of the 'API Test' database. ```HTTP GET https://www.teamdesk.net/secure/api/v2/21995/describe.json ``` -------------------------------- ### Format Link Placeholders in Email Body (Markdown) Source: https://www.teamdesk.net/help/tips-and-tricks This markdown example shows how to display user-friendly clickable names for link placeholders like %AppLink%, %RecLink%, and %ViewLink% in email bodies, instead of raw URLs. ```markdown [Click to Application](%AppLink%) [Click to Record](%RecLink%) [Click to View](%ViewLink%) ``` -------------------------------- ### Construct Time Values using Literals and Functions Source: https://www.teamdesk.net/help/working-with-formulas/tips-and-tricks Demonstrates creating time values using literals in HH:MM or HH:MM:SS format, and using the Time() function with numeric hour, minute, and second arguments. It also shows conversion from text using ToTimeOfDay(). ```TeamDesk Formula Time value literal: #23:30# or #09:15:30# Time function: Time(22, 15) returns #22:15# Time function with seconds: Time(22, 15, 5) returns #22:15:05# Time function from numeric: Time(246) returns #00:04:06# Text to Time: ToTimeOfDay("3:04 pm") returns #15:04# Timestamp to Time: ToTimeOfDay([Timestamp Column]) ``` -------------------------------- ### Get Last Day of Year using LastDayOfYear Source: https://www.teamdesk.net/help/working-with-formulas/formula-building-blocks/functions/date-functions/lastdayofyear This example demonstrates how to use the LastDayOfYear function with the Today() function to retrieve the last day of the current year. It takes no external dependencies beyond the built-in TeamDesk date functions. ```TeamDesk LastDayOfYear(Today()) ``` -------------------------------- ### Get URL to File Attachment Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Returns a URL to a file stored in a File Attachment column. This formula constructs the URL using the file's ID and GUID, requiring 'Allow Public Access' to be enabled for the column. ```TeamDesk Formula URLRoot() & "/attachment.aspx?fid=" & ColumnId([File Attachment Column]) & "&guid=" & Right([File Attachment Column], ";") ``` -------------------------------- ### Any() Function Example Source: https://www.teamdesk.net/help/working-with-formulas/formula-building-blocks/functions/text-functions/any Illustrates the basic usage of the Any() function with sample inputs. The function checks for the presence of elements from the second list within the first list. ```TeamDesk Formula Any("A,B,C,D", "D,A") Any("A,B,C,D", "D,E") ``` -------------------------------- ### Get URL to File Attachment with Custom Filename Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Returns a URL to a file stored in a File Attachment column, allowing for a custom filename. This formula constructs the URL using the file's ID and GUID, and allows specifying a filename after attachment.aspx. ```TeamDesk Formula URLRoot() & "/attachment.aspx/" & URLEncode("yourfilename" & "." & Right(Left([File Attachment Column], ";"), ".")) & "?fid=" & ColumnId([File Attachment Column]) & "&guid=" & Right([File Attachment Column], ";") ``` -------------------------------- ### Get Response Status Code with If Statement - TeamDesk Formula Source: https://www.teamdesk.net/help/working-with-formulas/formula-building-blocks/functions/special-functions/responsestatus This example demonstrates how to use the ResponseStatus() function within a TeamDesk formula to check if the response status code is 200 (OK) and return an appropriate message. It's useful for handling the results of Call-URL actions. ```TeamDesk Formula If(ResponseStatus() = 200, "OK", "FAILED!") ``` -------------------------------- ### Querying Specific Columns with Sorting and Pagination (HTTP) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/select-table-method This example demonstrates querying specific 'Text' and 'Date' columns from a 'Test' table, sorting the results by 'Date' in descending order, and retrieving records 5 through 10. It utilizes the 'skip' and 'top' parameters for pagination. ```HTTP GET https://www.teamdesk.net/secure/api/v2/21995/Test/select.json?column=Text&column=Date&sort=Date//DESC&skip=5&top=5 ``` -------------------------------- ### Get URL to Image from File Attachment Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Returns a URL to an image file stored in a File Attachment column, with options to control image size. This formula constructs the URL using the file's ID and GUID, and allows specifying width (w) and height (h) parameters. ```TeamDesk Formula URLRoot() & "/image.aspx?fid=" & ColumnId([File Attachment Column]) & "&w=240&guid=" & Right([File Attachment Column], ";") ``` -------------------------------- ### Using Variables in TeamDesk Formulas Source: https://www.teamdesk.net/help/database/variables/using-variables-in-formulas This snippet provides examples of using variables within TeamDesk formulas, emphasizing the need for type conversion. It showcases practical applications like calculating daily earnings and the duration since a project's start date, demonstrating the integration of variables into calculations. ```TeamDesk Formula ToNumber(Var[hourly rate])*8 ``` ```TeamDesk Formula Today() - ToDate(Var[start date]) ``` -------------------------------- ### Get URL to Resized Image with Custom Filename Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Returns a URL to a resized image file stored in a File Attachment column, with a custom filename. The system resizes images to JPEG format, so a .jpg extension is required. This formula constructs the URL using the file's ID and GUID. ```TeamDesk Formula URLRoot() & "/attachment.aspx/" & URLEncode("yourfilename" & ".jpg") & "?fid=" & ColumnId([File Attachment Column]) & "&guid=" & Right([File Attachment Column], ";") ``` -------------------------------- ### URL to Record Edit Screen Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Generates a URL to the current record's edit screen, including table and record IDs, and a back URL. ```APIDOC ## URL to Record Edit Screen ### Description Returns a URL to the current record edit screen. ### Method GET ### Endpoint /edit.aspx ### Parameters #### Query Parameters - **t** (integer) - Required - The ID of the table. - **id** (integer) - Required - The ID of the record. - **back** (string) - Optional - The URL to return to after editing. ### Request Example ``` URLRoot() & "/edit.aspx?t=" & TableId() & "&id=" & RecordId() & "&back=" & BackURL() ``` ### Response This function returns a string representing the URL. ``` -------------------------------- ### XHTML PDF Preview Source: https://www.teamdesk.net/help/working-with-formulas/sample-formulas Embeds a PDF file preview within an XHTML document using a file attachment column. ```APIDOC ## XHTML PDF Preview ### Description PDF file preview from the file attachment column. ### Method GET (for the embedded resource) ### Endpoint /attachment.aspx ### Parameters #### Query Parameters (for the embedded resource) - **fid** (integer) - Required - The ID of the file attachment column. - **id** (integer) - Required (if not using GUID) - The ID of the record. - **guid** (string) - Required (if using Public Access) - The GUID of the attachment. ### Request Example (Standard) ```html ``` ### Request Example (Public Access) ```html " width="100%" height="800" type='application/pdf'> ``` ### Response This code snippet generates an HTML embed tag to display a PDF preview. ``` -------------------------------- ### Get First Day of Year - TeamDesk Formula Source: https://www.teamdesk.net/help/working-with-formulas/formula-building-blocks/functions/date-functions/firstdayofyear Returns the first day of the year for a given date. The function takes a single parameter, 'date', which is the date to evaluate. It returns a Date object representing January 1st of that year. Example: FirstDayOfYear(Today()) returns the first day of the current year. ```TeamDesk Formula FirstDayOfYear(date) ``` -------------------------------- ### TeamDesk API Document Method Example Request (HTTP) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/document-method This example demonstrates how to render a document for specific records using the Document Method. It specifies the application ID, table, document, and provides multiple 'id' parameters for the desired records. The API supports rendering documents for up to 500 records at once. ```HTTP GET https://www.teamdesk.net/secure/api/v2/21995/Test/SampleDoc/document?id=156&id=157 ``` -------------------------------- ### Convert Variable to Date in TeamDesk Formula Source: https://www.teamdesk.net/help/database/variables/using-variables-in-formulas This snippet illustrates converting a variable stored as text into a date format. The `ToDate()` function is used for this purpose, enabling date-based calculations such as finding the difference between two dates. The example calculates the number of days passed since a project's start date. ```TeamDesk Formula ToDate(Var[start date]) ``` -------------------------------- ### Constructing a Select Query (HTTP) Source: https://www.teamdesk.net/help/rest-api/rest-api-methods/select-table-method This snippet demonstrates the base structure for constructing a GET request to the TeamDesk API's Select method. It specifies the application ID, table name, and the desired output format (JSON or XML). ```HTTP GET https://www.teamdesk.net/secure/api/v2/{appid}/{table}/select.{json|xml}?parameters ``` -------------------------------- ### Generate Unique Random Identifiers with Guid Function Source: https://www.teamdesk.net/help/working-with-formulas/tips-and-tricks This snippet demonstrates how to create unique random identifiers using the Guid function in TeamDesk. It shows how to generate a standard GUID, remove hyphens, and extract a specific number of characters from the end of the GUID. ```TeamDesk Script Guid() Replace(Guid(), "-", "") Right(Guid(), 10) ```