Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

Monday, 10 June 2024

Microsoft Graph API - Open Type Extension

In this blog, we will be learning about Microsoft Graph Extensibility - Open Type Extension.


What are Microsoft Graph Extensions?

Microsoft Graph provides a single API endpoint to access rich people-centric data and insights through resources such as user and message. You can also extend Microsoft Graph by adding custom properties to resource instances without requiring an external data store.

Microsoft Graph offers four types of extensions for adding custom data.

  • Extension attributes
  • Directory (Microsoft Entra ID) extensions
  • Schema extensions
  • Open extensions


Open Extensions

Here we will be discussing Open extensions.

  • It allows us to add untyped properties to resources in Graph.
  • Each extension has a key/value property.
  • The name of the extensions should include a reverse domain name system (DNS) format that is dependent on our own domain; for example, the DNS name com.mydomain.UserInfo
  • Can be added, updated, and deleted.

⊛ Note

Do not use extensions to store sensitive personally identifiable information, such as account credentials, government identification numbers, cardholder data, financial account data, healthcare information, or sensitive background information.


The following resources support open extension:
Resource Status Permission
Administrative unit Preview Only Directory.AccessAsUser.All
Calendar event GA Calendars.ReadWrite
Group calendar event GA Group.ReadWrite.All
Group conversation thread post GA Group.ReadWrite.All
Device GA Device.ReadWrite.All
Group GA Group.ReadWrite.All
Message GA Mail.ReadWrite
Organization GA Directory.AccessAsUser.All
Personal contact GA Contacts.ReadWrite
User GA Directory.AccessAsUser.All

We will be working around User resource in the Graph

Open Microsoft Graph Explorer - aka.ms/ge

The first thing is to provide permissions (refer to the above table) to use the Microsoft Graph API endpoint.



Get an Extension

Enter the below table details and press the 'Run query' button. We will get OK-200 status and blank/empty array as we currently don't have any extensions available. (we'll get extensions again further in the blog).

Verb GET
URL https://graph.microsoft.com/v1.0/me?
$select=id,displayName,mail,mobilePhone&$expand=extensions



Create an Extension

Enter the below table details and press the 'Run query' button. The new open extension will be created, and we will get Created-201 status.

Verb POST
URL https://graph.microsoft.com/v1.0/me/extensions
Body
{
  "@odata.type": "microsoft.graph.openTypeExtension",
  "extensionName": "com.vikasbansal.userSettings",
  "costCenter": "Engineering-007",
  "myFavouriteApps": [
    {
      "name": "SSP",
      "description": "Self Service Portal",
      "Url": "https://aks.ms/sspr",
      "iconName": "EmployeeSelfService"
    },
    {
      "name": "Open AI",
      "description": "Open Artificial Intelligence",
      "Url": "https://openai.com",
      "iconName": "GiftboxOpen"
    },
    {
      "name": "My IT Support",
      "description": "Access IT updated and support materials",
      "Url": "https://www.myitsupport.com",
      "iconName": "AnalyticsView"
    },
    {
      "name": "Policies Hub",
      "description": "Get latest updates on company policies",
      "Url": "https://www.policyhub.com",
      "iconName": "EntitlementPolicy"
    },
    {
      "name": "Office 365",
      "description": "My Office 365",
      "Url": "https://office.com",
      "iconName": "OfficeLogo"
    }
  ]
}





Update an Extension

Enter the below table details and press the 'Run query' button. The open extension value will be updated, and we will get a No Content-204 status.
{Extension-Id} is the name of the extension previously created.

Verb PATCH
URL https://graph.microsoft.com/v1.0/me/extensions/{extension-id}
https://graph.microsoft.com/v1.0/me/extensions/com.vikasbansal.userSettings
Body
{
  "@odata.type": "microsoft.graph.openTypeExtension",
  "extensionName": "com.vikasbansal.userSettings",
  "costCenter": "Engineering-005",
  "myFavouriteApps": [
    {
      "name": "ESP",
      "description": "Employee Service Portal",
      "Url": "https://aks.ms/sspr",
      "iconName": "EmployeeSelfService"
    },
    {
      "name": "Open AI",
      "description": "Open Artificial Intelligence",
      "Url": "https://openai.com",
      "iconName": "GiftboxOpen"
    },
    {
      "name": "My IT Support",
      "description": "Access IT updated and support materials",
      "Url": "https://www.myitsupport.com",
      "iconName": "AnalyticsView"
    },
    {
      "name": "Policies Hub",
      "description": "Get latest updates on company policies",
      "Url": "https://www.policyhub.com",
      "iconName": "EntitlementPolicy"
    },
    {
      "name": "Office 365",
      "description": "My Office 365",
      "Url": "https://office.com",
      "iconName": "OfficeLogo"
    }
  ]
}





Again, enter the Get extension table details and press the 'Run query' button. We will get OK-200 status, and the extensions array will contain available extension details against the user resource in Graph.



Delete an Extension

Enter the below table details and press the 'Run query' button. The open extension will be deleted, and we will get a No Content-204 status.
{Extension-Id} is the name of the extension previously created or updated.

Open Extension once deleted, cannot be restored but can be created again with the same name.

Verb DELETE
URL https://graph.microsoft.com/v1.0/me/extensions/{extension-id}
https://graph.microsoft.com/v1.0/me/extensions/com.vikasbansal.userSettings




Open Extensions: Limitations and Useful Information

  • Resources cannot be filtered based on open extensions.
  • Each open extension can have up to 2 KB of data (including the extension definition).
  • An application can add up to two open extensions per resource instance.
  • There is no transaction context while working on extensions.


I hope this will help all of you! 🧲
Feel free to provide feedback.


πŸš€ "Happy Coding" πŸš€

Wednesday, 6 December 2023

Create List templates using Site template and Site script

In this blog, we will be learning how to create list templates under the tab From your organization.

When people in the organization create new lists, they need a template that can be used each time a new list is created.

Site Script

A site script is a collection of actions that SharePoint runs when creating a new site or list. Actions describe changes to apply to the new list, such as creating new columns, adding views, or content types. The actions are specified in a JSON script, which is a list of all actions to apply. When a script runs, SharePoint completes each action in the order listed.

Site Template (previously known as Site Design)

Site templates can be used each time a new site is created to apply a consistent set of actions. Site templates created using custom site scripts will display in the From your organization tab.

A site script is a JSON string that contains the actions to be taken on a site. A site template, on the other hand, is like a container for the site script. You can attach one or more site scripts to a site template, and when you apply the site template, you execute the actions defined in all of the site scripts. It's like the site template is the visible surface part that can group several site scripts together, and the site scripts are all the action underneath.

Currently, no list template is available From your organization tab.


  • A site template can run multiple scripts. The script IDs are passed in an array, and they run in the order listed.
  • The former term for site templates may still appear in certain cmdlets and script labels as "site design".
  • The schema is case-sensitive.

Create a Site script in JSON

Create the script in JSON that describes the action to be executed on the list. You can view and reference the latest JSON schema file here: https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json

In addition to constructing the JSON by hand, you can also use third-party tools with graphical user interfaces that generate the site scripts for you, such as sitedesigner.io by Mikko PunamΓ€ki or Site Template Studio by Yannick Plenevaux.

Exporting an existing list as a site script

In our scenario, we will be exporting an existing list configuration as a site script.
First, connect to the SPO admin site using the Connect-SPOService cmdlet. It can be achieved with the following script. The Get-SPOSiteScriptFromList cmdlet prints out the site script to the console. It can be saved into a variable, or you can copy and save it in a JSON file.


Deploy Site Script and Site Template

To use our site script, we need to deploy it to our tenant. We also need to create a site template where we can attach the deployed site script.

1) Add the site script

Each site script must be registered in SharePoint so that it is available to use. Add a new site script by using the Add-SPOSiteScript cmdlet.


After running the cmdlet, you get a result that lists the site script ID of the added script. Keep track of this ID, as it will be needed later when you create the site template.

2) Create the site template

Next, we will create the site template. Run the Add-SPOListDesign cmdlet to add a new site template. Use the script ID saved above when you added the site script. It can run one or more scripts that have already been added.


The JSON response displays the ID of the new site template. It can be used later on to update or modify the site template.

Get the existing Site Script and Site Template

After we have deployed our site script and site template to our tenant, we can see their properties and information about all other deployed site scripts and templates using the Get-SPOSiteScript and Get-SPOListDesign cmdlet.



Use the new site template

Now that we've added a site script and site template, we can use them to create a new list.



I hope this will help all of you! 🧲
Feel free to provide feedback.


πŸš€ "Happy Coding" πŸš€