Chilkat Online Tools

DataFlex / Microsoft Graph / Put item

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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."
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "acl[0].type" "everyone" To iSuccess
    Get ComUpdateString Of hoJson "acl[0].value" "c5f19b2d-0a77-454a-9b43-abf298c3b34e" To iSuccess
    Get ComUpdateString Of hoJson "acl[0].accessType" "grant" To iSuccess
    Get ComUpdateString Of hoJson "properties.title" "Sample item title" To iSuccess
    Get ComUpdateString Of hoJson "properties.extension" "docx" To iSuccess
    Get ComUpdateString Of hoJson "properties.createdBy" "John Doe" To iSuccess
    Get ComUpdateString Of hoJson "properties.createdDateTime" "2021-04-27T11:04:00Z" To iSuccess
    Get ComUpdateString Of hoJson "properties.iconUrl" "https://contentdepot.blob.core.windows.net/filedepot/sampleIconUrl.png" To iSuccess
    Get ComUpdateString Of hoJson "properties.authors[0]" "John Doe" To iSuccess
    Get ComUpdateString Of hoJson 'properties."authors@odata.type"' "Collection(String)" To iSuccess
    Get ComUpdateString Of hoJson "properties.lastModifiedDate" "2021-04-27T11:04:00Z" To iSuccess
    Get ComUpdateString Of hoJson "properties.url" "https://sampleItemUrl.com" To iSuccess
    Get ComUpdateString Of hoJson "properties.containerName" "Sample container name" To iSuccess
    Get ComUpdateString Of hoJson "properties.containerUrl" "https://sampleContainerUrl.com" To iSuccess
    Get ComUpdateString Of hoJson "content.type" "text" To iSuccess
    Get ComUpdateString Of hoJson "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." To iSuccess

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess

    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComPTextSb Of hoHttp "PUT" "https://graph.microsoft.com/v1.0/external/connections/sampleConnectionId/items/sampleItemId" vSbRequestBody "utf-8" "application/json" False False To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

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": [
  ]
}