Desk Data Viewer > Display company timelog totals based on current ticket recepient

Aim: Utilise the Desk data viewer feature to display a company's total time loggedfor the current monthbased on the ticket recepient.

Feature:

API endpoint:

  • Time tracking activity - undocumented

  • https://{siteName}.teamwork.com/desk/api/v2/reports/timetracking/activity.json

Caveats:

  • The StartDate and EndDate values require manual alteration each month ot based on the cadence you want timelogs to be captured

  • If the ticket recipient does not belong to a company an error will appear. 

Step one:

  • Click on your profile picture in the bottom left

  • Select Settings from the menu

  • Click on Integrations

  • Select Desk Data Viewer

  • Click on install

This will enable the feature on your installation.

Step two:

Under the request form add the following

  • Method: GET

  • URL: https://{siteName}.teamwork.com/desk/api/v2/reports/timetracking/activity.json

  • Authentication: Bearer

  • Token: Follow the steps on this guide to get a valid ApiKey.

    • ie: tkn.v1_NTc4ZTUyNBlAHbLAhBLaH

  • Query: StartDate=2024-04-01&EndDate=2024-04-30&Companies=${ticket.company.id}

For this scenario you can leave the body section blank

Make sure you save the URL, Token and Query fields of the form

Step three:

Move over to the Desk Data tab and leave the dropdown item on ticket. This will display a sample payload for a ticket.

While testing, the sample Desk data will more than likely not include a company object. For this scenario please change:

  • "company": null,

with

  • "company": {"id": 123,"name": "Company Name" },

This is only for testing so this will change back as soon as you leave the Desk data viewer setup page.

Step Four:

Move over to the Responses tab and click on the Fetch button. This, if successful will show a payload related to the time for the specified company based on the dates specified in the Query.

Step Five:

Next move over to the Template tab. select Adaptive Cards from the dropdown and click on save.

Copy the json code on the right and paste this into the Template modal. Make sure you save any updates.

Template Modal

Adaptive card.json

{
  "type": "AdaptiveCard",
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.5",
  "body": [
    {
      "type": "TextBlock",
      "horizontalAlignment": "Center",
      "text": "**Company time logged this Month**"
    },
    {
      "type": "Container",
      "fontType": "Open Sans",
      "style": "emphasis",
      "items": [
        {
          "type": "ColumnSet",
          "width": "stretch",
          "columns": [
            {
              "type": "Column",
              "$when": "${desk.ticket.company == null}",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "horizontalAlignment": "Left",
                  "text": "**Company:** No Company set for customer",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "$when": "${response.timelogActivity.timelogs == null && $desk.ticket.company != null}",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "horizontalAlignment": "Left",
                  "text": "**Company:** ${if(desk.ticket.company.name == '', 'No Company Name',desk.ticket.company.name)}",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "$data": "${response.timelogActivity}",
                  "horizontalAlignment": "Left",
                  "text": "**Time Used:** ${totalTimeLogged/60} minutes",
                  "spacing": "none",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "$data": "${response.timelogActivity}",
                  "horizontalAlignment": "Left",
                  "text": "**Tickets with timelogs:** ${tickets}",
                  "spacing": "none",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "$data": "${response.timelogActivity}",
                  "horizontalAlignment": "Left",
                  "text": "**Total agents:** ${agents}",
                  "spacing": "none",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "$data": "${response.timelogActivity}",
                  "horizontalAlignment": "Left",
                  "text": "**Average time per day:** ${string(formatNumber(averageTimePerDay/60,2))} minutes",
                  "spacing": "none",
                  "wrap": true
                }
              ]
            },
            {
              "type": "Column",
              "$when": "${response.timelogActivity.timelogs != null && desk.ticket.company != null}",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "horizontalAlignment": "Left",
                  "text": "**Company:** ${if(desk.ticket.company.name != '', desk.ticket.company.name, 'No Company Name')}",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "$data": "${response.timelogActivity}",
                  "horizontalAlignment": "Left",
                  "text": "**Time Used:** ${totalTimeLogged/60} minutes",
                  "spacing": "none",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "$data": "${response.timelogActivity}",
                  "horizontalAlignment": "Left",
                  "text": "**Tickets with timelogs:** ${tickets}",
                  "spacing": "none",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "$data": "${response.timelogActivity}",
                  "horizontalAlignment": "Left",
                  "text": "**Total agents:** ${agents}",
                  "spacing": "none",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "$data": "${response.timelogActivity}",
                  "horizontalAlignment": "Left",
                  "text": "**Average time per day:** ${string(formatNumber(averageTimePerDay/60,2))} minutes",
                  "spacing": "none",
                  "wrap": true
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Step Six:

Move over to the Display tab. Here you will be able to see how the information will look based on the sample data in the Response tab.

Depending on how you want the data to be displayed on your ticket sidebar check the "Should the data be displayed in a modal?" box to make a button appear in app.

For this scenario, we only have a few lines to display so you can leave this unchecked for now.

Display setting page
Button that appears when checkbox is checked
Display of data in App when checkbox is unchecked

Feedback

If you have any feedback or suggestions, feel free to contact us at api@teamwork.com.