Giter Club home page Giter Club logo

msgraph-search-connector-sample's Introduction

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 [email protected] 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.

msgraph-search-connector-sample's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

msgraph-search-connector-sample's Issues

Unable Push ALL items to current connection

@jasonjoh

May be you can help/suggest. I download and followed the instructions.

Able to create a new connection and schema. But when i try to push items(option 7), i get the below error. Any hints what could be wrong here.

image

-Ravi

Unauthorized error creating new connection

I am getting below error even though I granted all the needed permission. Any help would be appreciated

Code: generalException
Message: {
"error": {
"code": "UnknownError",
"message": "{"code":"UnauthorizedAccess","message":"Tenant unauthorized to access this API"}",
"innerError": {
"request-id": "93729ccd-cad3-4725-8c49-c8fc6936bedf",
"date": "2019-11-14T06:30:36"
}
}
}

Thanks

Error while creating externalItem

AddorUpdateItem function is failing with below error message. This was working as expected and now it is failing with this message.

Code: generalException
Message: {
"error": {
"code": "BadRequest",
"message": "Property content in payload has a value that does not match schema.",
"innerError": {
"request-id": "62cd9e15-feb3-48a3-bed7-a0a67f3e9661",
"date": "2020-04-17T01:55:49"
}
}
}

The `property` object from microsoft.graph has updated `type` property for collection types

The property object from microsoft.graph has updated type property for collection types.

They have changed to StringCollection, Int64Collection, DoubleCollection, DateTimeCollection

I get the following error when trying to Register the schema:

Message: {
  "error": {
    "code": "InvalidRequest",
    "message": "The request is malformed or incorrect.",
    "innerError": {
      "code": "DeserializationError",
      "message": "Requested value 'Collection(String)' was not found.",
    }
  }
}

Creating a connection throws an error.

When attempting to run the app, I've opened my command-line interface (CLI) in the PartsInventoryConnector directory, and I've successfully ran "dotnet build."
However, when I attempt to use and "dotnet run" and I select "Create the connection," I receive the following error:

"Code: generalException
Message: An error occurred sending the request."

image

How To Connect-To/Update the Database

Fantastic sample! Thank-you so much for your time and effort on this. I have more of a question than an issue.

The last instruction in the ReadMe file suggests updating values manually via the database. Can you provide additional details on where to find the database and how to connect?

image

Maximum search results?

I am setting the From parameter in my search to go through all results, but when I get to 1000 results I get an error that "BadRequestThe maximum allowed page size is 1000"

How do I page past 1000 items?

Deleting items

This is Great, and I plan to use the Graph helper library, but it appears to be missing the ability to delete items from the index.

Looking at the notes on the link below, my assumption is that it is the same code as "AddOrUpdateItem" without a body but with the PATCH method rather than PUT, however the HttpMethod does not support PATCH as outlined here , so there is a bit more to it ?

not tested yet but something like

    public async Task DeleteItem(string connectionId, ExternalItem item)
    {
        var payload = JsonConvert.SerializeObject(item, _serializerSettings);

        var response = await PatchAsync(_graphClient, $"external/connections/{connectionId}/items/{item.Id}", null);
        return;

    }

    public static Task<HttpResponseMessage> PatchAsync(this HttpClient client, string requestUri, HttpContent content)
    {
        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = new HttpMethod("PATCH"),
            RequestUri = new Uri(client.BaseAddress + requestUri),
            Content = content,
        };

        return client.SendAsync(request);
    }

Add PatchAsync to a separate class

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.