Chilkat Online Tools

SQL Server / Microsoft Graph / Put item

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

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

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

    -- {
    --   "acl": [
    --     {
    --       "type": "everyone",
    --       "value": "c5f19b2d-0a77-454a-9b43-abf298c3b34e",
    --       "accessType": "grant"
    --     }
    --   ],
    --   "properties": {
    --     "title": "Sample item title",
    --     "extension": "docx",
    --     "createdBy": "John Doe",
    --     "createdDateTime": "2021-04-27T11:04:00Z",
    --     "iconUrl": "https://contentdepot.blob.core.windows.net/filedepot/sampleIconUrl.png",
    --     "authors": [
    --       "John Doe"
    --     ],
    --     "authors@odata.type": "Collection(String)",
    --     "lastModifiedDate": "2021-04-27T11:04:00Z",
    --     "url": "https://sampleItemUrl.com",
    --     "containerName": "Sample container name",
    --     "containerUrl": "https://sampleContainerUrl.com"
    --   },
    --   "content": {
    --     "type": "text",
    --     "value": "Empower customers and partners to be more productive by enabling them to bring content and activity information and allow external content to participate in Microsoft Search and OfficeHub experiences so that they find relevant and actionable information across all their applications."
    --   }
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'acl[0].type', 'everyone'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'acl[0].value', 'c5f19b2d-0a77-454a-9b43-abf298c3b34e'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'acl[0].accessType', 'grant'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.title', 'Sample item title'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.extension', 'docx'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.createdBy', 'John Doe'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.createdDateTime', '2021-04-27T11:04:00Z'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.iconUrl', 'https://contentdepot.blob.core.windows.net/filedepot/sampleIconUrl.png'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.authors[0]', 'John Doe'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties."authors@odata.type"', 'Collection(String)'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.lastModifiedDate', '2021-04-27T11:04:00Z'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.url', 'https://sampleItemUrl.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.containerName', 'Sample container name'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'properties.containerUrl', 'https://sampleContainerUrl.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content.type', 'text'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content.value', 'Empower customers and partners to be more productive by enabling them to bring content and activity information and allow external content to participate in Microsoft Search and OfficeHub experiences so that they find relevant and actionable information across all their applications.'

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://graph.microsoft.com/v1.0/external/connections/sampleConnectionId/items/sampleItemId', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "acl": [
        {
            "type": "everyone",
            "value": "c5f19b2d-0a77-454a-9b43-abf298c3b34e",
            "accessType": "grant"
        }
    ],
    "properties": {
        "title": "Sample item title",
        "extension": "docx",
        "createdBy": "John Doe",
        "createdDateTime": "2021-04-27T11:04:00Z",
        "iconUrl": "https://contentdepot.blob.core.windows.net/filedepot/sampleIconUrl.png",
        "authors": [
            "John Doe"
        ],
        "authors@odata.type": "Collection(String)",
        "lastModifiedDate": "2021-04-27T11:04:00Z",
        "url": "https://sampleItemUrl.com",
        "containerName": "Sample container name",
        "containerUrl": "https://sampleContainerUrl.com"
    },
    "content": {
        "type": "text",
        "value": "Empower customers and partners to be more productive by enabling them to bring content and activity information and allow external content to participate in Microsoft Search and OfficeHub experiences so that they find relevant and actionable information across all their applications."
    }
}'
https://graph.microsoft.com/v1.0/external/connections/sampleConnectionId/items/sampleItemId

Postman Collection Item JSON

{
  "name": "Put item",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"acl\": [\r\n        {\r\n            \"type\": \"everyone\",\r\n            \"value\": \"c5f19b2d-0a77-454a-9b43-abf298c3b34e\",\r\n            \"accessType\": \"grant\"\r\n        }\r\n    ],\r\n    \"properties\": {\r\n        \"title\": \"Sample item title\",\r\n        \"extension\": \"docx\",\r\n        \"createdBy\": \"John Doe\",\r\n        \"createdDateTime\": \"2021-04-27T11:04:00Z\",\r\n        \"iconUrl\": \"https://contentdepot.blob.core.windows.net/filedepot/sampleIconUrl.png\",\r\n        \"authors\": [\r\n            \"John Doe\"\r\n        ],\r\n        \"authors@odata.type\": \"Collection(String)\",\r\n        \"lastModifiedDate\": \"2021-04-27T11:04:00Z\",\r\n        \"url\": \"https://sampleItemUrl.com\",\r\n        \"containerName\": \"Sample container name\",\r\n        \"containerUrl\": \"https://sampleContainerUrl.com\"\r\n    },\r\n    \"content\": {\r\n        \"type\": \"text\",\r\n        \"value\": \"Empower customers and partners to be more productive by enabling them to bring content and activity information and allow external content to participate in Microsoft Search and OfficeHub experiences so that they find relevant and actionable information across all their applications.\"\r\n    }\r\n}"
    },
    "url": {
      "raw": "https://graph.microsoft.com/v1.0/external/connections/sampleConnectionId/items/sampleItemId",
      "protocol": "https",
      "host": [
        "graph",
        "microsoft",
        "com"
      ],
      "path": [
        "v1.0",
        "external",
        "connections",
        "sampleConnectionId",
        "items",
        "sampleItemId"
      ]
    }
  },
  "response": [
  ]
}