Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Zerg00s/6e239aabd54ea6346d6db8133e99be2d to your computer and use it in GitHub Desktop.
Save Zerg00s/6e239aabd54ea6346d6db8133e99be2d to your computer and use it in GitHub Desktop.
Cognitive Search API - SharePoint Data Source - Reusable Postman collection

Reusable Postman collection that configures SharePoint Data source for Cognitive Search

Postman Collection Variables

First, download the Cognitive Search API - SharePoint Data Source.json file and import it into your Postman. Then, in the Variables section of your imported collection, setup the following variables:

  • AZURE_SEARCH_SERVICE_NAME - Your Azure Cognitive Search Service Name. You can retreive it from the URL. It goes between https:// and .search.windows.net: https://clever-cognitive-search.search.windows.net
  • AZURE_SEARCH_ADMIN_KEY - Cognitive Search Admin key
  • AZURE_APPLICATION_ID - Azure App Registration ID. Note: The app must have read access to your SharePoint tenant
  • AZURE_APPLICATION_SECRET - Azure App Registration Secret.
  • AZURE_TENANT_ID - Azure Active Directory Tenant ID. The same that hosts Cognitive Search and SharePoint.
  • SHAREPOINT_SITE_URL - Full URL of a SharePoint site. For example, https://gocleverpointcom.sharepoint.com/sites/Teailspin-Records-CognitiveSearchDemo
  • SHAREPOINT_LIBRARY_URL - Full URL of a document library. For example, https://gocleverpointcom.sharepoint.com/sites/Teailspin-Records-CognitiveSearchDemo/Shared Documents/Forms/AllItems.aspx
  • SHAREPOINT_ADDITIONAL_COLUMNS - Custom SharePoint columns that you want to index. For example: Title,Year,DocumentType,Critical,LastReviewed,DocumentOwner,AnnualCosts,FullFilePath

Important resources

Video tutorial

https://youtu.be/GiSwKJ7xkZA?si=2nEK3vrSDnJY3DV8&t=431

{
"info": {
"_postman_id": "7f9a258e-feee-40a7-827f-760caa441e43",
"name": "Cognitive Search API Reusable",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "641744"
},
"item": [
{
"name": "Create SharePoint Data Source",
"request": {
"method": "POST",
"header": [
{
"key": "api-key",
"value": "{{AZURE_SEARCH_ADMIN_KEY}}",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"name\": \"sharepoint-datasource\",\r\n \"type\": \"sharepoint\",\r\n \"credentials\": {\r\n \"connectionString\": \"SharePointOnlineEndpoint={{SHAREPOINT_SITE_URL}};ApplicationId={{AZURE_APPLICATION_ID}};ApplicationSecret={{AZURE_APPLICATION_SECRET}};TenantId={{AZURE_TENANT_ID}}\"\r\n },\r\n \"container\": {\r\n \"name\": \"defaultSiteLibrary\",\r\n \"query\":\"includeLibrary={{SHAREPOINT_LIBRARY_URL}};additionalColumns={{SHAREPOINT_ADDITIONAL_COLUMNS}}\"\r\n\r\n }\r\n}"
},
"url": {
"raw": "https://{{AZURE_SEARCH_SERVICE_NAME}}.search.windows.net/datasources?api-version=2021-04-30-Preview",
"protocol": "https",
"host": [
"{{AZURE_SEARCH_SERVICE_NAME}}",
"search",
"windows",
"net"
],
"path": [
"datasources"
],
"query": [
{
"key": "api-version",
"value": "2021-04-30-Preview"
}
]
}
},
"response": []
},
{
"name": "Create an index",
"request": {
"method": "POST",
"header": [
{
"key": "api-key",
"value": "{{AZURE_SEARCH_ADMIN_KEY}}",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"name\" : \"sharepoint-index\",\r\n \"fields\": [\r\n { \"name\": \"id\", \"type\": \"Edm.String\", \"key\": true, \"searchable\": false },\r\n { \"name\": \"metadata_spo_item_name\", \"type\": \"Edm.String\", \"key\": false, \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"metadata_spo_item_path\", \"type\": \"Edm.String\", \"key\": false, \"searchable\": false, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"metadata_spo_item_content_type\", \"type\": \"Edm.String\", \"key\": false, \"searchable\": false, \"filterable\": true, \"sortable\": false, \"facetable\": true },\r\n { \"name\": \"metadata_spo_item_last_modified\", \"type\": \"Edm.DateTimeOffset\", \"key\": false, \"searchable\": false, \"filterable\": false, \"sortable\": true, \"facetable\": false },\r\n { \"name\": \"metadata_spo_item_size\", \"type\": \"Edm.Int64\", \"key\": false, \"searchable\": false, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"content\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n\r\n\r\n { \"name\": \"Title\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"Year\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"DocumentType\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"Critical\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"LastReviewed\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"DocumentOwner\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"AnnualCosts\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false },\r\n { \"name\": \"FullFilePath\", \"type\": \"Edm.String\", \"searchable\": true, \"filterable\": false, \"sortable\": false, \"facetable\": false }\r\n\r\n \r\n ]\r\n}"
},
"url": {
"raw": "https://{{AZURE_SEARCH_SERVICE_NAME}}.search.windows.net/indexes/?api-version=2021-04-30-Preview",
"protocol": "https",
"host": [
"{{AZURE_SEARCH_SERVICE_NAME}}",
"search",
"windows",
"net"
],
"path": [
"indexes",
""
],
"query": [
{
"key": "api-version",
"value": "2021-04-30-Preview"
}
]
}
},
"response": []
},
{
"name": "Create Indexer",
"request": {
"method": "POST",
"header": [
{
"key": "api-key",
"value": "{{AZURE_SEARCH_ADMIN_KEY}}",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"name\" : \"sharepoint-indexer\",\r\n \"dataSourceName\" : \"sharepoint-datasource\",\r\n \"targetIndexName\" : \"sharepoint-index\",\r\n \"parameters\": {\r\n \"batchSize\": null,\r\n \"maxFailedItems\": null,\r\n \"maxFailedItemsPerBatch\": null,\r\n \"base64EncodeKeys\": null,\r\n \"configuration\": {\r\n \"indexedFileNameExtensions\" : \".pdf, .docx\",\r\n \"excludedFileNameExtensions\" : \".png, .jpg\",\r\n \"dataToExtract\": \"contentAndMetadata\"\r\n }\r\n },\r\n \"schedule\" : { },\r\n \"fieldMappings\" : [\r\n { \r\n \"sourceFieldName\" : \"metadata_spo_site_library_item_id\", \r\n \"targetFieldName\" : \"id\", \r\n \"mappingFunction\" : { \r\n \"name\" : \"base64Encode\" \r\n } \r\n }\r\n ]\r\n}"
},
"url": {
"raw": "https://{{AZURE_SEARCH_SERVICE_NAME}}.search.windows.net/indexers?api-version=2021-04-30-Preview",
"protocol": "https",
"host": [
"{{AZURE_SEARCH_SERVICE_NAME}}",
"search",
"windows",
"net"
],
"path": [
"indexers"
],
"query": [
{
"key": "api-version",
"value": "2021-04-30-Preview"
}
]
}
},
"response": []
},
{
"name": "Get Indexer Status",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "api-key",
"value": "{{AZURE_SEARCH_ADMIN_KEY}}",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"name\" : \"sharepoint-indexer\",\r\n \"dataSourceName\" : \"sharepoint-datasource\",\r\n \"targetIndexName\" : \"sharepoint-index\",\r\n \"parameters\": {\r\n \"batchSize\": null,\r\n \"maxFailedItems\": null,\r\n \"maxFailedItemsPerBatch\": null,\r\n \"base64EncodeKeys\": null,\r\n \"configuration\": {\r\n \"indexedFileNameExtensions\" : \".pdf, .docx\",\r\n \"excludedFileNameExtensions\" : \".png, .jpg\",\r\n \"dataToExtract\": \"contentAndMetadata\"\r\n }\r\n },\r\n \"schedule\" : { },\r\n \"fieldMappings\" : [\r\n { \r\n \"sourceFieldName\" : \"metadata_spo_site_library_item_id\", \r\n \"targetFieldName\" : \"id\", \r\n \"mappingFunction\" : { \r\n \"name\" : \"base64Encode\" \r\n } \r\n }\r\n ]\r\n}"
},
"url": {
"raw": "https://{{AZURE_SEARCH_SERVICE_NAME}}.search.windows.net/indexers/sharepoint-indexer/status?api-version=2021-04-30-Preview",
"protocol": "https",
"host": [
"{{AZURE_SEARCH_SERVICE_NAME}}",
"search",
"windows",
"net"
],
"path": [
"indexers",
"sharepoint-indexer",
"status"
],
"query": [
{
"key": "api-version",
"value": "2021-04-30-Preview"
}
]
}
},
"response": []
},
{
"name": "Run Indexer",
"request": {
"method": "POST",
"header": [
{
"key": "api-key",
"value": "{{AZURE_SEARCH_ADMIN_KEY}}",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"name\" : \"sharepoint-indexer\",\r\n \"dataSourceName\" : \"sharepoint-datasource\",\r\n \"targetIndexName\" : \"sharepoint-index\",\r\n \"parameters\": {\r\n \"batchSize\": null,\r\n \"maxFailedItems\": null,\r\n \"maxFailedItemsPerBatch\": null,\r\n \"base64EncodeKeys\": null,\r\n \"configuration\": {\r\n \"indexedFileNameExtensions\" : \".pdf, .docx\",\r\n \"excludedFileNameExtensions\" : \".png, .jpg\",\r\n \"dataToExtract\": \"contentAndMetadata\"\r\n }\r\n },\r\n \"schedule\" : { },\r\n \"fieldMappings\" : [\r\n { \r\n \"sourceFieldName\" : \"metadata_spo_site_library_item_id\", \r\n \"targetFieldName\" : \"id\", \r\n \"mappingFunction\" : { \r\n \"name\" : \"base64Encode\" \r\n } \r\n }\r\n ]\r\n}"
},
"url": {
"raw": "https://{{AZURE_SEARCH_SERVICE_NAME}}.search.windows.net/indexers/sharepoint-indexer/run?api-version=2021-04-30-Preview",
"protocol": "https",
"host": [
"{{AZURE_SEARCH_SERVICE_NAME}}",
"search",
"windows",
"net"
],
"path": [
"indexers",
"sharepoint-indexer",
"run"
],
"query": [
{
"key": "api-version",
"value": "2021-04-30-Preview"
}
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "AZURE_SEARCH_SERVICE_NAME",
"value": "your_company-cognitive-search",
"type": "string"
},
{
"key": "AZURE_SEARCH_ADMIN_KEY",
"value": "00Md1Lt1iWRiGOabz0cRNaJemnxq1cvnpQu0PReBUDAzSeAnDieq",
"type": "string"
},
{
"key": "AZURE_APPLICATION_ID",
"value": "aaf72f62-20bf-4d5c-a181-4e4e4b1032a9",
"type": "string"
},
{
"key": "AZURE_APPLICATION_SECRET",
"value": "Qak8Q~y367wCsvDCUv21gLoxzZO_NO-t_mMSicWy",
"type": "string"
},
{
"key": "AZURE_TENANT_ID",
"value": "23bcd981-eaa6-475f-aac3-3afca0c35261",
"type": "string"
},
{
"key": "SHAREPOINT_SITE_URL",
"value": "https://contoso.sharepoint.com/sites/Teailspin-Records-CognitiveSearchDemo",
"type": "string"
},
{
"key": "SHAREPOINT_LIBRARY_URL",
"value": "https://contoso.sharepoint.com/sites/Teailspin-Records-CognitiveSearchDemo/Shared Documents/Forms/AllItems.aspx",
"type": "string"
},
{
"key": "SHAREPOINT_ADDITIONAL_COLUMNS",
"value": "Title,Year,DocumentType,Critical,LastReviewed,DocumentOwner,AnnualCosts,FullFilePath",
"type": "string"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment