Skip to content

This .NET Core application shows how to use the Microsoft Graph indexing API to create a connection to the Microsoft Search service and index custom items.

License

Notifications You must be signed in to change notification settings

microsoftgraph/msgraph-search-connector-sample

Repository files navigation

page_type description products languages
sample
This sample demonstrates how to use the Microsoft Graph .NET SDK to implement a custom search connector.
ms-graph
microsoft-search
csharp

Microsoft Graph search connector sample

dotnet build License.

This .NET sample application demonstrates how to build a custom Microsoft Graph connector using Microsoft Graph APIs to index items from a sample appliance parts inventory, and have that data appear in Microsoft Search results.

Prerequisites

Register an app in Azure portal

In this step you will register an application that supports app-only authentication using client credentials flow.

  1. Open a browser and navigate to the Azure Active Directory admin center and login using a Global administrator account.

  2. Select Azure Active Directory in the left-hand navigation, then select App registrations under Manage.

  3. Select New registration. Enter a name for your application, for example, Parts Inventory Connector.

  4. Set Supported account types to Accounts in this organizational directory only.

  5. Leave Redirect URI empty.

  6. Select Register. On the application's Overview page, copy the value of the Application (client) ID and Directory (tenant) ID and save them, you will need these values in the next step.

  7. Select API permissions under Manage.

  8. Remove the default User.Read permission under Configured permissions by selecting the ellipses (...) in its row and selecting Remove permission.

  9. Select Add a permission, then Microsoft Graph.

  10. Select Application permissions.

  11. Select ExternalConnection.ReadWrite.OwnedBy and ExternalItem.ReadWrite.OwnedBy, then select Add permissions.

  12. Select Grant admin consent for..., then select Yes to provide admin consent for the selected permission.

  13. Select Certificates and secrets under Manage, then select New client secret.

  14. Enter a description, choose a duration, and select Add.

  15. Copy the secret from the Value column, you will need it in the next steps.

    IMPORTANT This client secret is never shown again, so make sure you copy it now.

Configure the app

  1. Open your command line interface (CLI) in the directory where PartsInventoryConnector.csproj is located.

  2. Run the following command to initialize user secrets for the project.

    dotnet user-secrets init
    
  3. Run the following commands to store your app ID, app secret, and tenant ID in the user secret store.

    dotnet user-secrets set settings:clientId <client-id>
    dotnet user-secrets set settings:tenantId <tenant-id>
    dotnet user-secrets set settings:clientSecret <client-secret>
    

Initialize the database

dotnet ef database update

Delete and reset database

dotnet ef database drop
dotnet ef database update

Run the app

In this step you'll build and run the sample. This will create a new connection, register the schema, then push items from the ApplianceParts.csv file into the connection.

  1. Open your command-line interface (CLI) in the PartsInventoryConnector directory.

  2. Use the dotnet build command to build the sample.

  3. Use the dotnet run command to run the sample.

  4. Select the 1. Create a connection option. Enter a unique identifier, name, and description for the connection.

  5. Select the 4. Register schema for current connection option. Wait for the operation to complete.

    Note: If this steps results in an error, wait a few minutes and then select the 5. View schema for current connection option. If a schema is returned, the operation completed successfully. If no schema is returned, you may need to try registering the schema again.

  6. Select the 6. Push updated items to current connection option.

Create a vertical

Create and enable a search vertical at the organization level following the instructions in Manage Verticals.

  • Name: Appliance Parts
  • Content source: the connector created with the app
  • Add a query: leave blank
  • Filter: none

Create a result type

Create a result type at the organization level following the instructions in Manage Result Types.

  • Name: Appliance Part
  • Content source: the connector created with the app
  • Rules: None
  • Paste contents of result-type.json into layout

Search for results

In this step you'll search for parts in SharePoint.

  1. Go to your root SharePoint site for your tenant.
  2. Using the search box at the top of the page, search for hinge.
  3. When the search completes with 0 results, select the Appliance Parts tab.
  4. Results from the connector are displayed.

Updating records in the database

Use your favorite tool to update records in the database. The Push updated items menu choice will only push the items you update.

NOTE Do not delete records from the database. To "delete" an item, set the IsDeleted property to 1.

DB Browser

Code of conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

About

This .NET Core application shows how to use the Microsoft Graph indexing API to create a connection to the Microsoft Search service and index custom items.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages