page_type | description | products | languages | |||
---|---|---|---|---|---|---|
sample |
This sample demonstrates how to use the Microsoft Graph .NET SDK to implement a custom search connector. |
|
|
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.
- .NET 7.x
- Entity Framework Core Tools (
dotnet tool install --global dotnet-ef
) - Some way to update a SQLite database. For example, the DB Browser for SQLite.
In this step you will register an application that supports app-only authentication using client credentials flow.
-
Open a browser and navigate to the Azure Active Directory admin center and login using a Global administrator account.
-
Select Azure Active Directory in the left-hand navigation, then select App registrations under Manage.
-
Select New registration. Enter a name for your application, for example,
Parts Inventory Connector
. -
Set Supported account types to Accounts in this organizational directory only.
-
Leave Redirect URI empty.
-
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.
-
Select API permissions under Manage.
-
Remove the default User.Read permission under Configured permissions by selecting the ellipses (...) in its row and selecting Remove permission.
-
Select Add a permission, then Microsoft Graph.
-
Select Application permissions.
-
Select ExternalConnection.ReadWrite.OwnedBy and ExternalItem.ReadWrite.OwnedBy, then select Add permissions.
-
Select Grant admin consent for..., then select Yes to provide admin consent for the selected permission.
-
Select Certificates and secrets under Manage, then select New client secret.
-
Enter a description, choose a duration, and select Add.
-
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.
-
Open your command line interface (CLI) in the directory where PartsInventoryConnector.csproj is located.
-
Run the following command to initialize user secrets for the project.
dotnet user-secrets init
-
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>
dotnet ef database update
dotnet ef database drop
dotnet ef database update
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.
-
Open your command-line interface (CLI) in the PartsInventoryConnector directory.
-
Use the
dotnet build
command to build the sample. -
Use the
dotnet run
command to run the sample. -
Select the 1. Create a connection option. Enter a unique identifier, name, and description for the connection.
-
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.
-
Select the 6. Push updated items to current connection option.
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 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
In this step you'll search for parts in SharePoint.
- Go to your root SharePoint site for your tenant.
- Using the search box at the top of the page, search for
hinge
. - When the search completes with 0 results, select the Appliance Parts tab.
- Results from the connector are displayed.
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.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
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.