# Search and Filter Files — Sharepoint

> Search and filter SharePoint files based on metadata and custom columns. This action allows you to query files using SharePoint's custom properties, managed metadata, and other column values. See the documentation

- Key: `sharepoint-search-and-filter-files`
- Type: Action (Read-only)
- Version: 0.1.3
- App: Sharepoint (`sharepoint`) — https://pipedream.com/apps/sharepoint.md
- This page (HTML): https://pipedream.com/apps/sharepoint/actions/search-and-filter-files
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/sharepoint/actions/search-and-filter-files/search-and-filter-files.mjs

## Description

Search and filter SharePoint files based on metadata and custom columns. This action allows you to query files using SharePoint's custom properties, managed metadata, and other column values. [See the documentation](https://learn.microsoft.com/en-us/graph/api/listitem-list)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `siteId` | `string` | Yes | Identifier of a site. This is either the composite ID (e.g. contoso.sharepoint.com,<guid>,<guid> or a server-relative path in the form {hostname}:/{server-relative-path} (e.g. contoso.sharepoint.com:/sites/site-name) Options are loaded from the connected account. |
| `listId` | `string` | Yes | Select the document library or list to search in Options are loaded from the connected account. |
| `filter` | `string` | No | Filter items using OData syntax. To filter by custom columns, use fields/ColumnInternalName. Example: fields/Title eq 'My File' or fields/Status eq 'Approved'. See OData filter documentation |
| `select` | `string[]` | No | Select the specific metadata fields to return in the response. If none are selected, all fields will be returned. Options are loaded from the connected account. |
| `orderBy` | `string` | No | Specify the sort order of the results using OData syntax. Example: fields/Created desc or fields/Title asc. |
| `expandFields` | `boolean` | No | Set to true to retrieve custom metadata and column values. Defaults to true. |
| `maxResults` | `integer` | No | The maximum number of results to return. Defaults to 100. |
| `honorNonIndexedQueries` | `boolean` | No | Enable filtering on non-indexed columns (e.g. fields/FileLeafRef, fields/DocIcon). By default, SharePoint rejects $filter against non-indexed columns on lists above the list view threshold (5,000 items). Setting this to true sends the Prefer: HonorNonIndexedQueriesWarningMayFailRandomly header, which permits the query — but per Microsoft, these requests may fail randomly, especially on large lists. Leave off unless you've hit the error. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "sharepoint",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "sharepoint-search-and-filter-files",
  arguments: {
    siteId: "Site",
    listId: "List / Document Library",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "sharepoint-search-and-filter-files",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    sharepoint: { authProvisionId: "apn_xxxxxxx" },
    siteId: "Site",
    listId: "List / Document Library",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "sharepoint-search-and-filter-files",
    "configured_props": {
      "sharepoint": { "authProvisionId": "apn_xxxxxxx" },
      "siteId": "Site",
      "listId": "List / Document Library"
    }
  }'
```

---

- App: https://pipedream.com/apps/sharepoint.md · All apps: https://pipedream.com/apps
