Chilkat Online Tools

unicodeC / Microsoft Graph / Register schema

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "baseType": "microsoft.graph.externalItem",
    //   "properties": [
    //     {
    //       "name": "id",
    //       "type": "string",
    //       "isSearchable": false,
    //       "isRetrievable": true,
    //       "isQueryable": false,
    //       "labels": [
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "title",
    //       "type": "string",
    //       "isSearchable": true,
    //       "isRetrievable": true,
    //       "isQueryable": true,
    //       "labels": [
    //         "title"
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "extension",
    //       "type": "string",
    //       "isSearchable": true,
    //       "isRetrievable": true,
    //       "isQueryable": true,
    //       "labels": [
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "createdBy",
    //       "type": "string",
    //       "isSearchable": true,
    //       "isRetrievable": true,
    //       "isQueryable": true,
    //       "labels": [
    //         "createdBy"
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "createdDateTime",
    //       "type": "dateTime",
    //       "isSearchable": false,
    //       "isRetrievable": true,
    //       "isQueryable": true,
    //       "labels": [
    //         "createdDateTime"
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "lastModifiedBy",
    //       "type": "string",
    //       "isSearchable": false,
    //       "isRetrievable": true,
    //       "isQueryable": true,
    //       "labels": [
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "lastModifiedDate",
    //       "type": "dateTime",
    //       "isSearchable": false,
    //       "isRetrievable": true,
    //       "isQueryable": true,
    //       "labels": [
    //         "lastModifiedDateTime"
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "url",
    //       "type": "string",
    //       "isSearchable": false,
    //       "isRetrievable": true,
    //       "isQueryable": false,
    //       "labels": [
    //         "url"
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "description",
    //       "type": "string",
    //       "isSearchable": false,
    //       "isRetrievable": true,
    //       "isQueryable": false,
    //       "labels": [
    //       ],
    //       "aliases": [
    //       ]
    //     },
    //     {
    //       "name": "authors",
    //       "type": "stringCollection",
    //       "isSearchable": false,
    //       "isRetrievable": true,
    //       "isQueryable": false,
    //       "labels": [
    //         "authors"
    //       ],
    //       "aliases": [
    //       ]
    //     }
    //   ]
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"baseType",L"microsoft.graph.externalItem");
    CkJsonObjectW_UpdateString(json,L"properties[0].name",L"id");
    CkJsonObjectW_UpdateString(json,L"properties[0].type",L"string");
    CkJsonObjectW_UpdateBool(json,L"properties[0].isSearchable",FALSE);
    CkJsonObjectW_UpdateBool(json,L"properties[0].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[0].isQueryable",FALSE);
    CkJsonObjectW_UpdateNewArray(json,L"properties[0].labels");
    CkJsonObjectW_UpdateNewArray(json,L"properties[0].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[1].name",L"title");
    CkJsonObjectW_UpdateString(json,L"properties[1].type",L"string");
    CkJsonObjectW_UpdateBool(json,L"properties[1].isSearchable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[1].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[1].isQueryable",TRUE);
    CkJsonObjectW_UpdateString(json,L"properties[1].labels[0]",L"title");
    CkJsonObjectW_UpdateNewArray(json,L"properties[1].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[2].name",L"extension");
    CkJsonObjectW_UpdateString(json,L"properties[2].type",L"string");
    CkJsonObjectW_UpdateBool(json,L"properties[2].isSearchable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[2].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[2].isQueryable",TRUE);
    CkJsonObjectW_UpdateNewArray(json,L"properties[2].labels");
    CkJsonObjectW_UpdateNewArray(json,L"properties[2].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[3].name",L"createdBy");
    CkJsonObjectW_UpdateString(json,L"properties[3].type",L"string");
    CkJsonObjectW_UpdateBool(json,L"properties[3].isSearchable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[3].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[3].isQueryable",TRUE);
    CkJsonObjectW_UpdateString(json,L"properties[3].labels[0]",L"createdBy");
    CkJsonObjectW_UpdateNewArray(json,L"properties[3].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[4].name",L"createdDateTime");
    CkJsonObjectW_UpdateString(json,L"properties[4].type",L"dateTime");
    CkJsonObjectW_UpdateBool(json,L"properties[4].isSearchable",FALSE);
    CkJsonObjectW_UpdateBool(json,L"properties[4].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[4].isQueryable",TRUE);
    CkJsonObjectW_UpdateString(json,L"properties[4].labels[0]",L"createdDateTime");
    CkJsonObjectW_UpdateNewArray(json,L"properties[4].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[5].name",L"lastModifiedBy");
    CkJsonObjectW_UpdateString(json,L"properties[5].type",L"string");
    CkJsonObjectW_UpdateBool(json,L"properties[5].isSearchable",FALSE);
    CkJsonObjectW_UpdateBool(json,L"properties[5].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[5].isQueryable",TRUE);
    CkJsonObjectW_UpdateNewArray(json,L"properties[5].labels");
    CkJsonObjectW_UpdateNewArray(json,L"properties[5].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[6].name",L"lastModifiedDate");
    CkJsonObjectW_UpdateString(json,L"properties[6].type",L"dateTime");
    CkJsonObjectW_UpdateBool(json,L"properties[6].isSearchable",FALSE);
    CkJsonObjectW_UpdateBool(json,L"properties[6].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[6].isQueryable",TRUE);
    CkJsonObjectW_UpdateString(json,L"properties[6].labels[0]",L"lastModifiedDateTime");
    CkJsonObjectW_UpdateNewArray(json,L"properties[6].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[7].name",L"url");
    CkJsonObjectW_UpdateString(json,L"properties[7].type",L"string");
    CkJsonObjectW_UpdateBool(json,L"properties[7].isSearchable",FALSE);
    CkJsonObjectW_UpdateBool(json,L"properties[7].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[7].isQueryable",FALSE);
    CkJsonObjectW_UpdateString(json,L"properties[7].labels[0]",L"url");
    CkJsonObjectW_UpdateNewArray(json,L"properties[7].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[8].name",L"description");
    CkJsonObjectW_UpdateString(json,L"properties[8].type",L"string");
    CkJsonObjectW_UpdateBool(json,L"properties[8].isSearchable",FALSE);
    CkJsonObjectW_UpdateBool(json,L"properties[8].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[8].isQueryable",FALSE);
    CkJsonObjectW_UpdateNewArray(json,L"properties[8].labels");
    CkJsonObjectW_UpdateNewArray(json,L"properties[8].aliases");
    CkJsonObjectW_UpdateString(json,L"properties[9].name",L"authors");
    CkJsonObjectW_UpdateString(json,L"properties[9].type",L"stringCollection");
    CkJsonObjectW_UpdateBool(json,L"properties[9].isSearchable",FALSE);
    CkJsonObjectW_UpdateBool(json,L"properties[9].isRetrievable",TRUE);
    CkJsonObjectW_UpdateBool(json,L"properties[9].isQueryable",FALSE);
    CkJsonObjectW_UpdateString(json,L"properties[9].labels[0]",L"authors");
    CkJsonObjectW_UpdateNewArray(json,L"properties[9].aliases");

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");
    CkHttpW_SetRequestHeader(http,L"prefer",L"respond-async");

    resp = CkHttpW_PostJson3(http,L"https://graph.microsoft.com/v1.0/external/connections/sampleConnectionId/schema",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "prefer: respond-async"
	-d '{
    "baseType": "microsoft.graph.externalItem",
    "properties": [
        {
            "name": "id",
            "type": "string",
            "isSearchable": false,
            "isRetrievable": true,
            "isQueryable": false,
            "labels": [],
            "aliases": []
        },
        {
            "name": "title",
            "type": "string",
            "isSearchable": true,
            "isRetrievable": true,
            "isQueryable": true,
            "labels": [
                "title"
            ],
            "aliases": []
        },
        {
            "name": "extension",
            "type": "string",
            "isSearchable": true,
            "isRetrievable": true,
            "isQueryable": true,
            "labels": [],
            "aliases": []
        },
        {
            "name": "createdBy",
            "type": "string",
            "isSearchable": true,
            "isRetrievable": true,
            "isQueryable": true,
            "labels": [
                "createdBy"
            ],
            "aliases": []
        },
        {
            "name": "createdDateTime",
            "type": "dateTime",
            "isSearchable": false,
            "isRetrievable": true,
            "isQueryable": true,
            "labels": [
                "createdDateTime"
            ],
            "aliases": []
        },
        {
            "name": "lastModifiedBy",
            "type": "string",
            "isSearchable": false,
            "isRetrievable": true,
            "isQueryable": true,
            "labels": [],
            "aliases": []
        },
        {
            "name": "lastModifiedDate",
            "type": "dateTime",
            "isSearchable": false,
            "isRetrievable": true,
            "isQueryable": true,
            "labels": [
                "lastModifiedDateTime"
            ],
            "aliases": []
        },
        {
            "name": "url",
            "type": "string",
            "isSearchable": false,
            "isRetrievable": true,
            "isQueryable": false,
            "labels": [
                "url"
            ],
            "aliases": []
        },
        {
            "name": "description",
            "type": "string",
            "isSearchable": false,
            "isRetrievable": true,
            "isQueryable": false,
            "labels": [],
            "aliases": []
        },
        {
            "name": "authors",
            "type": "stringCollection",
            "isSearchable": false,
            "isRetrievable": true,
            "isQueryable": false,
            "labels": [
                "authors"
            ],
            "aliases": []
        }
    ]
}'
https://graph.microsoft.com/v1.0/external/connections/sampleConnectionId/schema

Postman Collection Item JSON

{
  "name": "Register schema",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "postman.setEnvironmentVariable(\"OperationUrl\", pm.response.headers.get(\"Location\"));"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      },
      {
        "key": "prefer",
        "type": "text",
        "value": "respond-async"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"baseType\": \"microsoft.graph.externalItem\",\r\n    \"properties\": [\r\n        {\r\n            \"name\": \"id\",\r\n            \"type\": \"string\",\r\n            \"isSearchable\": false,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": false,\r\n            \"labels\": [],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"title\",\r\n            \"type\": \"string\",\r\n            \"isSearchable\": true,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": true,\r\n            \"labels\": [\r\n                \"title\"\r\n            ],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"extension\",\r\n            \"type\": \"string\",\r\n            \"isSearchable\": true,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": true,\r\n            \"labels\": [],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"createdBy\",\r\n            \"type\": \"string\",\r\n            \"isSearchable\": true,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": true,\r\n            \"labels\": [\r\n                \"createdBy\"\r\n            ],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"createdDateTime\",\r\n            \"type\": \"dateTime\",\r\n            \"isSearchable\": false,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": true,\r\n            \"labels\": [\r\n                \"createdDateTime\"\r\n            ],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"lastModifiedBy\",\r\n            \"type\": \"string\",\r\n            \"isSearchable\": false,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": true,\r\n            \"labels\": [],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"lastModifiedDate\",\r\n            \"type\": \"dateTime\",\r\n            \"isSearchable\": false,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": true,\r\n            \"labels\": [\r\n                \"lastModifiedDateTime\"\r\n            ],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"url\",\r\n            \"type\": \"string\",\r\n            \"isSearchable\": false,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": false,\r\n            \"labels\": [\r\n                \"url\"\r\n            ],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"description\",\r\n            \"type\": \"string\",\r\n            \"isSearchable\": false,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": false,\r\n            \"labels\": [],\r\n            \"aliases\": []\r\n        },\r\n        {\r\n            \"name\": \"authors\",\r\n            \"type\": \"stringCollection\",\r\n            \"isSearchable\": false,\r\n            \"isRetrievable\": true,\r\n            \"isQueryable\": false,\r\n            \"labels\": [\r\n                \"authors\"\r\n            ],\r\n            \"aliases\": []\r\n        }\r\n    ]\r\n}"
    },
    "url": {
      "raw": "https://graph.microsoft.com/v1.0/external/connections/sampleConnectionId/schema",
      "protocol": "https",
      "host": [
        "graph",
        "microsoft",
        "com"
      ],
      "path": [
        "v1.0",
        "external",
        "connections",
        "sampleConnectionId",
        "schema"
      ]
    }
  },
  "response": [
  ]
}