---
title: "Integration with Microsoft Teams"
canonical: "https://docs.getxray.app/space/XRAYCLOUD/44580155/Integration%20with%20Microsoft%20Teams"
format: markdown
---
> Macro (toc)

# Overview

Microsoft Teams, or "Teams," is a popular communication platform many development and non-development teams adopt.

Teams use it daily to collaborate, make calls, share information, ask for help, and be notified of certain events to increase visibility of the status of the projects they're working on.

In this article, we'll see an everyday use case: sharing test results with the team in their collaboration tool (i.e., "MS Teams"). However, Xray and Jira's built-in automation capabilities can implement many more use cases.

![image](media://f07daea1-4d2d-4bec-b5d8-00daa128b8a4)

# Prerequisites

To integrate with Teams, we can set up an incoming webhook in a channel and use it to send notifications (i.e., "messages").

1. In Teams, select the channel and the "Connectors" option
  
2. Select the "Incoming Webhook"
3. Configure the "Incoming Webhook", giving it a name and uploading an image to be associated with it. Copy the unique URL and keep it safe.  
        > Macro (inline-media-image)

# Use cases

## Share test results to a channel

This common use-case is about sharing information about test results, usually from test automation, to a Teams channel so the team can be aware of testing progress and analyze the results if needed.

> ℹ️ At high-level, we will:
> ℹ️ 
> ℹ️ 1. make an authentication request to Xray's API to get an authentication token to be used on the GraphQL query
> ℹ️ 2. make a GraphQL query to obtain the Test Execution details, including recorded test results
> ℹ️ 3. process the response, storing relevant information on some variables
> ℹ️ 4. build an HTTP request to send a notification with the test results summary by invoking a webhook on MS Teams

### Step-by-step implementation with Jira automation

1. .In Jira's project settings, under Automation, create the Jira automation rule
  1. define the trigger; we can have a manual trigger that will provide an action from the issue screen or a trigger based on creating a specific issue type. In this case, it would probably make the most sense to have a trigger based on the transition to some status (e.g., "Done"). We can also restrict this to the issue types "Test Execution" and "Sub-Test Execution" using an IF condition.
  2. Create an action using the "Send web request" template to make the [authentication request ](https://getxraydocs.atlassian.net/wiki/display/XRAYCLOUD/Authentication+-+REST+v2)and obtain a token to be used on the GraphQL queries; we need a *client_id* and a *client_secret *(please see [how to create API keys](https://getxraydocs.atlassian.net/wiki/display/XRAYCLOUD/Global+Settings%3A+API+Keys)).
  3. Save the response on a variable (e.g., "token")
  4. Make a GraphQL query to obtain the details of the Test Execution and its results
    1. <span style="color: #0e101a">Use the GraphQL API, namely the </span> [ ](https://xray.cloud.getxray.app/doc/graphql/gettestexecution.doc.html)<span style="color: #4a6ee0">[getTestExecution function](https://xray.cloud.getxray.app/doc/graphql/gettestexecution.doc.html)</span>[ ](https://xray.cloud.getxray.app/doc/graphql/gettestexecution.doc.html) <span style="color: #0e101a">. We'll need the issue id of the Test Execution that was triggered; we can use the smart values feature from Jira automation to obtain it. We need to also obtain the custom field id of the "Revision" custom field under the "Issue Fields" section of your Jira administration. </span>
      
      **sample GraphQL query**
      
    2. Escape the GraphQL query (e.g., using the online [GraphQL to JSON Body Converter](https://datafetcher.com/graphql-json-body-converter) tool)
    
2. Get the total tests and store it in a variable(note that this is an approximate value as GraphQL results can be limited and paginated)  
     > Macro (inline-media-image)
  
3. Get the total tests passing and store it in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)  
     > Macro (inline-media-image)
  
4. Get the total failed tests and store it in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)
  
5. Get the total tests in TO DO and store it in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)
  
6. Get the total tests in other statuses and store it in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)  
       > Macro (inline-media-image)
  
7. Get the linked Test Plan and store it in a variable  
        > Macro (inline-media-image)
  
8. Use a "IF" block to store the URL of the linked Test Plan, if any
9. Get the associated Test Environments and store it in a variable  
        > Macro (inline-media-image)
  
10. Get the list of distinct statuses reported and store it in a temporary variable  
       > Macro (inline-media-image)
  
11. Make a IF THEN ELSE block to adjust the text message and image of the notification, to tailor our notification for successful and unsuccessful testing cases
  1. As a mere example, for the "failure" image we can use the following one.
  1. As a mere example, for the "success" image we can use the following one.
12. Send the notification by using a "Send web request" to invoke the webhook on Teams  
       > Macro (inline-media-image)
  

### Example of the output

![image](media://68df0eb4-e1a7-449f-abb8-08b4b034958f)

### Further ideas to try out

- Send the notification only if there are test failures
- Send the notification only if there is a specific label or custom field on the Test Execution
- Add comments and/or logs of the failed tests to the notification

# References

- Teams
  - [Teams: Types of cards](https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference)
  - [Create and send messages](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL)
  - [Adaptive Cards: Samples and Templates](https://adaptivecards.io/samples/)
- [GraphQL to JSON Body Converter](https://datafetcher.com/graphql-json-body-converter)
- [Jira Automation in Jira Cloud](https://support.atlassian.com/cloud-automation/docs/jira-cloud-automation/)
  - [Jira smart values - issues](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/)
  - [Jira smart values - lists](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/)
  - [Jira smart values - text fields](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/)
  - <span style="color: #003366"> </span><span style="color: #003366">[Jira smart values - users](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-users/)</span><span style="color: #003366"> </span>
  - [Jira smart values - conditional logic](https://getxraydocs.atlassian.net/wiki/spaces/XRAYCLOUD/pages/44580155)
  - [Jira smart values - JSON functions](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-json-functions/)