How To Use Adaptive Cards In SharePoint Using SPFx

Ahamed Fazil Buhari
Senior Developer
March 25, 2019
Rate this article
[Total: 0    Average: 0/5]


In the below article we will go through – what adaptive card and how it can be used in SharePoint using React. Adaptive cards – are used to interchange content in a collective and constant way and it is open framework also it supports multiple platform. In simple words, it is a collection of JSON and array of JSON objects which will render and gives output with all the data and actions.

In the below example, We will demonstrate how to include Adaptive card in our SharePoint Framework, for this example I am getting current User Information and populating it in Adaptive Card.

Here I created simple SPFx webpart with React, which get user properties through pnp js and put those values in Adaptive card payload,

Installing adaptivecards, pnp js and office ui fabric package, updated typescript version (not necessary),

npm i @pnp/sp @pnp/pnpjs react-adaptivecards office-ui-fabric-core@9.0.0 office-ui-fabric-react@5.69.0 typescript@2.8.4


In the code, I create a component called UserAdaptiveCard which will retrieve user information on ComponentDidMount method and based on the response it shows the data.

 import * as React from "react";
 import AdaptiveCard from "react-adaptivecards";
 import styles from "./UserAdaptiveCard.module.scss";
 import {
 } from "../models/IUserAdaptiveCardState";
 import { Loader } from "./Loader";
 import { getCurrentUser, InitialState } from "../services/UserProfileService";
 export class UserAdaptiveCard extends React.Component<
 > {
   constructor(props: {}) {
     this.state = InitialState;
   public componentDidMount() {
     // get CurrentUserInfo
       (user: ICurrentUser) => {
         this.setState({ currentUser: user, isCurrentUserFetched: true });
       (error: string) => {
         this.setState({ isError: true });
   public render(): JSX.Element {
     return (
       <div className={`${styles.userAdaptive}`}>
         {!this.state.isCurrentUserFetched ? (
         ) : (
                 $schema: "",
                 type: "AdaptiveCard",
                 version: "1.0",
                 body: [
                     type: "Container",
                     items: [
                         type: "Image",
                         horizontalAlignment: "Center",
                         spacing: "Large",
                         style: "Person",
                         url: `${
                             ? this.state.currentUser.imageURL
                             : ""
                         size: "Large"
                         type: "TextBlock",
                         size: "Large",
                         horizontalAlignment: "Center",
                         weight: "Lighter",
                         text: `${this.state.currentUser.fullName}`
                         type: "TextBlock",
                         horizontalAlignment: "Center",
                         weight: "Bolder",
                         text: `Email: ${}`,
                         wrap: true



Loader component is just to show spinner while we make api call (in my O365 Dev tenant I do not have Exchange server enabled for my account – that’s the reason I couldn’t set my profile picture. Instead I hardcoded profile picture URL if PictureURL from SharePoint is null)


To deploy, run

gulp bundle –ship


Once bundling is completed successfully run below command to package the solution

gulp package-solution –ship

The sppkg file will be available in :\yourproject\sharepoint\solution\yourproject.sppkg

Upload solution to App Catalog site

This app is not available for all the site collection, only the site collection which adds this app will consume it.

Before searching for this app in modern page, include this app in your site.

In the modern page add the webpart as shown below,


The SPFx web part will be rendered as follows,


The whole code for this solution is available here in github –

Please checkout to the branch feature/user-info to get solution related to this demo explained above.


Happy Coding



Author Info

Ahamed Fazil Buhari
Senior Developer
Rate this article
[Total: 0    Average: 0/5]
Ahamed is a Senior Developer and he has very good experience in the field of Microsoft Technologies, especially SharePoint 2013, 2016 and O365, Azure, ASP.NET, SQL Server, IIS and client more

Leave a comment