SharePoint · Viva Connections

Viva Connections Card Designer – Advance API features (part 2)

This blog post is the second part of Viva Connections Card Designer – Advance API features (part 1).

It will focus on using the Microsoft Graph API and the Card Designer advance API features to display dynamic data within a Viva Connections dashboard card without code.

Content

  1. Prerequisites
    1. SharePoint Online Client Extensibility Web Application Principal
    2. Add required permissions
  2. Get data using Microsoft Graph API
  3. Display data
  4. Conclusion
  5. References

Prerequisites

The same prerequisites described in the part 1 should be met. In addition, the use of the Microsoft Graph API requires the following prerequisites.

SharePoint Online Client Extensibility Web Application Principal

On the Card Designer card settings, if you try to execute a Graph API request (using the “Test” button), you will have the following error message: Cannot make any requests to Microsoft Graph as the SharePoint Online Client Extensibility Web Application Principal is not configured or consented to.

It means that the SharePoint Online Client Extensibility Web Application Principal might not be created. This app is used to manage permissions that your Graph API requests require. This app is also the one managing permissions for SPFx solutions.

To check if this app has already been created, you can go to the Microsoft Entra admin center and check the “App registration” list:

To create this app, access the “API access” page from your tenant’s SharePoint admin center. :

If you check again the “App registration” page, the app is listed:

Add required permissions

Now that the SharePoint Online Client Extensibility Web Application Principal is created, we need to add permissions that are required for the API call we want to perform from the Card Designer.

In our example we want to get current user’s direct reports. So we will need at least the User.Read and User.ReadBasic.All permissions:

  1. On the SharePoint Online Client Extensibility Web Application Principal page, click on “API permissions”
  2. Click on “Add a permission”
  3. Select “Microsoft Graph” then “Delegated permissions”
  4. Select the “User.Read” and “User.ReadBasic.All” permissions then click on “Add permissions”

Finally, as an admin you must grant consent for the newly added permissions:

Get data using Microsoft Graph API

Once all the prerequisites are met, you can start using the Microsoft Graph API to get data from the Card Designer.

First, add a new Card Designer card to the Viva Connections Dashboard and select Call a Microsoft Graph API in the Data source dropdown:

Then you can write your request URL in the input field that appeared below. As an example, we want to get current user’s direct reports: v1.0/me/directReports

You can click on “Test” to preview the response of the request.

Display data

To display the data that you get using the API call in the quick view of the card, use an adaptive card JSON template. To display current user’s direct reports, you can you the template below:

{
  "type": "AdaptiveCard",
  "body": [
    {
      "type": "Container",
      "$data": "${value}",
      "style": "default",
      "bleed": true,
      "items": [
        {
          "type": "TextBlock",
          "text": "${displayName}",
          "wrap": true,
          "weight": "Bolder",
          "size": "Medium"
        },
        {
          "type": "TextBlock",
          "text": "Email: ${userPrincipalName}",
          "isSubtle": true,
          "wrap": true,
          "spacing": "Small",
          "maxLines": 2
        }
      ]
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.2"
}

Click on “Apply”, then “Republish” and you can now access dynamic data from the quick view of your Card Designer card:

Conclusion

In this blog post, we covered how to use Viva Connections Card Designer advance API features to get data using Microsoft Graph API and display retrieved data on the card quick view.

References

SharePoint · Viva Connections

Viva Connections Card Designer – Advance API features (part 1)

The Card Designer is a type of card that you can add to your Viva Connection dashboard. You could customize the design of this card using Adaptive Cards templating and choose predefined actions for the card primary and secondary buttons (e.g.: show the quick view, go to a link).

In December 2023, Microsoft introduced a set new advance API features that enable the use of API to get specific data without code and then display it in the quick view using templates.

This blog post demonstrates, using these new features, how to get specific data using the SharePoint API.

Content

  1. Prerequisites
    1. Enable features
    2. Create the tenant App catalog
  2. Get data using SharePoint API
  3. Display data
  4. Conclusion
  5. References

Prerequisites

This section describes the prerequisites to use the advance API features to get data with the SharePoint API.

You will need SharePoint admin permissions to perform the actions described below.

Enable features

If you add a new Card Designer card to you Viva Connections dashboard, you will notice the following warning message in the “Quick view layout and data section”:

To use the new advance API features of the Card Designer, you have to enable it. To do so, use the SharePoint Online PowerShell. Make sure you have the latest version installed and execute the following cmdlets:

Connect-SPOService -Url "https://yourtenant-admin.sharepoint.com/"
Set-SPOTenant -IsDataAccessInCardDesignerEnabled $true

You can now execute Get-SPOTenant to make sure that the property is successfully enabled:

Create the tenant App catalog

Now, if you access a Card Designer card settings and see the following warning message, it means that your tenant does not already have a tenant App catalog:

If your tenant does not already have an App catalog, you will have to create it. To do so, access the SharePoint admin center and then go to “More features” and click on “Open” in the “Apps” section. It will automatically create the app catalog:

Get data using SharePoint API

Once all the prerequisites are met, you can start using the new advance API features of the Card Designer.

Let’s see how to get data using the SharePoint REST API:

First, add a new Card Designer card to the Viva Connections Dashboard and select Call a SharePoint API in the Data source dropdown:

Then you can write your request URL in the input field that appeared below. As an example, we want to get files of the Documents library: /GetFolderByServerRelativeUrl('Shared%20Documents')/Files

You can click on “Test” to preview the response of the request.

Display data

To display the data that you get using the API call in the quick view of the card, use an adaptive card JSON template. To display the files from the Documents library, you can you the template below:

{
  "type": "AdaptiveCard",
  "body": [
    {
      "type": "Container",
      "$data": "${value}",
      "style": "default",
      "bleed": true,
      "items": [
        {
          "type": "TextBlock",
          "text": "${Name}",
          "wrap": true,
          "weight": "Bolder",
          "size": "Medium"
        },
        {
          "type": "TextBlock",
          "text": "Last modified on {{DATE(${TimeLastModified}, COMPACT)}}",
          "isSubtle": true,
          "wrap": true,
          "spacing": "Small",
          "maxLines": 2
        }
      ]
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.2"
}

Click on “Apply”, then “Republish” and you can now access dynamic data from the quick view of your Card Designer card:

Conclusion

In this blog post, we covered how to use Viva Connections Card Designer advance API features to get data using SharePoint API and display retrieved data on the card quick view.

In the next part, we will see how to do the same using the Microsoft Graph API.

References

M365 Development · SharePoint · Viva Connections

How to use text input in Adaptive Card Extensions’ card views

To use an input field on an Adaptive Card Extension (ACE), you could only do it on a quick view of the card. Since SPFx v1.18, it is possible to use a text input component directly on an Adaptive Card Extension’s card views.

For instance, if your adaptive card main purpose is to get a simple input from users, you could really benefit from this new feature.

This blog post demonstrates how to implement this feature.

Content

  1. Requirements
    1. New adaptive card
    2. Existing adaptive card
  2. Use the new default class for card views
  3. From the card footer
  4. From the card body
  5. References

Requirements

New adaptive card

If you want to implement the feature on a new adaptive card extension, perform the following steps:

  1. Make sur you have the latest version of the SharePoint Framework installed : npm install @microsoft/generator-sharepoint@latest --global
  2. Run yo @microsoft/sharepoint
  3. Select Generic Card Template in the generator

Existing adaptive card

You can also implement this feature on an already existing ACE created with an on older SPFx version. To do so, you need to migrate your Adaptive Card Extension to SharePoint Framework v1.18.

Since SPFx v1.18 new classes and other architectural changes, migration to this version requires additional steps. You can find more details here: Migrate Adaptive Card Extensions to SharePoint Framework v1.18

Use the new default class for card views

SPFx v1.18 introduce BaseComponentsCardView as the new default class for Adaptive Card Extensions card views. You can use this new class to specify components that you want to display in a card view:

The first option that you have, is to use a text input component in the footer of your card view.

In the BaseComponentsCardView class, define the BasicCardView as follows:

As you can see, the componentName property of the footer is defined as textInput. You also have the following properties:

PropertyDescription
idId of the component
placeholderPlaceholder of the text input component
button/iconDefine the icon of the button
button/actionAction to perform when the button is clicked

From the card body

The second option is to use an text input component in the body of your card view.

In the BaseComponentsCardView class, define the TextInputCardView as follows:

Here the textInput component is defined in the body. You can set the following properties:

PropertyDescription
idId of the component
placeholderPlaceholder of the text input component
iconBeforeDefine the icon on the left-hand side of the input component.

Note that in this case the button is still defined on the footer part of the Adaptive Card Extension.

References