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. The sample indexes appliance parts inventory for Contoso Appliance Repair.
- .NET 3.1 SDK
- 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'll register an application in the Azure AD admin center. This is necessary to authenticate the application to make calls to the Microsoft Graph indexing API.
-
Go to the Azure Active Directory admin center and sign in with an administrator account.
-
Select Azure Active Directory in the left-hand pane, then select App registrations under Manage.
-
Select New registration.
-
Complete the Register an application form with the following values, then select Register.
- Name:
Parts Inventory Connector
- Supported account types:
Accounts in this organizational directory only (Microsoft only - Single tenant)
- Redirect URI: Leave blank
- Name:
-
On the Parts Inventory Connector page, copy the value of Application (client) ID, you'll need it in the next section.
-
Copy the value of Directory (tenant) ID, you'll need it in the next section.
-
Select API Permissions under Manage.
-
Select Add a permission, then select Microsoft Graph.
-
Select Application permissions, then select the ExternalItem.ReadWrite.All permission. Select Add permissions.
-
Select Grant admin consent for {TENANT}, then select Yes when prompted.
-
Select Certificates & secrets under Manage, then select New client secret.
-
Enter a description and choose an expiration time for the secret, then select Add.
-
Copy the new secret, you'll need it in the next section.
-
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 appId "YOUR_APP_ID_HERE" dotnet user-secrets set appSecret "YOUR_APP_SECRET_HERE" dotnet user-secrets set tenantId "YOUR_TENANT_ID_HERE"
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 Customize the Microsoft Search page.
- Name: Appliance Parts
- Content source: the connector created with the app
- Add a query: leave blank
Create a result type at the organization level following the instructions in Customize the Microsoft Search page.
- 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.