Chilkat Online Tools

SQL Server / Zoom API / Assign a role

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
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @req int
    -- Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT

    EXEC sp_OASetProperty @req, 'HttpVerb', 'POST'
    EXEC sp_OASetProperty @req, 'Path', '/v2/roles/:roleId/members'
    EXEC sp_OASetProperty @req, 'ContentType', 'multipart/form-data'

    DECLARE @jsonFormData1 int
    -- Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @jsonFormData1 OUT

    EXEC sp_OAMethod @jsonFormData1, 'AddObjectAt', @success OUT, -1
    DECLARE @jsonObj_1 int
    EXEC sp_OAGetProperty @jsonFormData1, 'Size', @iTmp0 OUT
    EXEC sp_OAMethod @jsonFormData1, 'ObjectAt', @jsonObj_1 OUT, @iTmp0 - 1
    EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'id', 'laboris mollit do quis anim'
    EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'email', '9t7JYT@NQHyqsJCrzyPoITCOEvXbTD.tcx'
    EXEC @hr = sp_OADestroy @jsonObj_1

    EXEC sp_OAMethod @jsonFormData1, 'AddObjectAt', @success OUT, -1
    EXEC sp_OAGetProperty @jsonFormData1, 'Size', @iTmp0 OUT
    EXEC sp_OAMethod @jsonFormData1, 'ObjectAt', @jsonObj_1 OUT, @iTmp0 - 1
    EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'id', 'Ut consectetur pariatur commodo'
    EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'email', 'cul@eZgh.bjh'
    EXEC @hr = sp_OADestroy @jsonObj_1

    EXEC sp_OAMethod @req, 'AddStringForUpload2', @success OUT, 'members', '', @jsonFormData1, 'utf-8', 'application/json'

    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'Authorization', 'Bearer <access_token>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'SynchronousRequest', @resp OUT, 'api.zoom.us', 443, 1, @req
    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 @req
        EXEC @hr = sp_OADestroy @jsonFormData1
        RETURN
      END

    DECLARE @sbResponseBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @req
        EXEC @hr = sp_OADestroy @jsonFormData1
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "ids": "elit enim",
    --   "add_at": "1986-11-30T15:13:03.662Z"
    -- }

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @ids nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @ids OUT, 'ids'
    DECLARE @add_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @add_at OUT, 'add_at'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @req
    EXEC @hr = sp_OADestroy @jsonFormData1
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: multipart/form-data"
	--form 'members=[{"id":"laboris mollit do quis anim","email":"9t7JYT@NQHyqsJCrzyPoITCOEvXbTD.tcx"},{"id":"Ut consectetur pariatur commodo","email":"cul@eZgh.bjh"}]'
https://api.zoom.us/v2/roles/:roleId/members

Postman Collection Item JSON

{
  "name": "Assign a role",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "multipart/form-data"
      }
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "members",
          "value": "[{\"id\":\"laboris mollit do quis anim\",\"email\":\"9t7JYT@NQHyqsJCrzyPoITCOEvXbTD.tcx\"},{\"id\":\"Ut consectetur pariatur commodo\",\"email\":\"cul@eZgh.bjh\"}]",
          "description": "Array of userId/user email of users to whom you would like to assign this role. Upto 30 users can be assigned a role at once.",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "{{baseUrl}}/roles/:roleId/members",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "roles",
        ":roleId",
        "members"
      ],
      "variable": [
        {
          "key": "roleId",
          "value": "quis officia in reprehenderit",
          "description": "(Required) The role ID"
        }
      ]
    },
    "description": "User [roles](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control) can have a set of permissions that allows access only to the pages a user needs to view or edit. Use this API to [assign a role](https://support.zoom.us/hc/en-us/articles/115001078646-Role-Based-Access-Control#h_748b6fd8-5057-4cf4-bbfd-787909c09db0) to members.\n\n**Scopes:** `role:write:admin`<br>\n \n **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`<br>\n**Prerequisites:**<br>\n* A Pro or a higher plan."
  },
  "response": [
    {
      "name": "**HTTP Status Code:** `201`<br>Members Added",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "members",
              "value": "[{\"id\":\"laboris mollit do quis anim\",\"email\":\"9t7JYT@NQHyqsJCrzyPoITCOEvXbTD.tcx\"},{\"id\":\"Ut consectetur pariatur commodo\",\"email\":\"cul@eZgh.bjh\"}]",
              "description": "Array of userId/user email of users to whom you would like to assign this role. Upto 30 users can be assigned a role at once.",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{baseUrl}}/roles/:roleId/members",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "roles",
            ":roleId",
            "members"
          ],
          "variable": [
            {
              "key": "roleId",
              "value": "quis officia in reprehenderit",
              "description": "(Required) The role ID"
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Location",
          "value": "quis officia in reprehenderit",
          "description": "Location of created members"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"ids\": \"elit enim\",\n \"add_at\": \"1986-11-30T15:13:03.662Z\"\n}"
    },
    {
      "name": "**HTTP Status Code:** `400`<br>\n\n**Error Code:** `1034`\nRole does not exist.<br><br>\n**Error Code:** `300`<br>\nRoleId required.<br>\nCan’t delete or add members for Normal/Owner roles.<br><br>",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "members",
              "value": "[{\"id\":\"laboris mollit do quis anim\",\"email\":\"9t7JYT@NQHyqsJCrzyPoITCOEvXbTD.tcx\"},{\"id\":\"Ut consectetur pariatur commodo\",\"email\":\"cul@eZgh.bjh\"}]",
              "description": "Array of userId/user email of users to whom you would like to assign this role. Upto 30 users can be assigned a role at once.",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{baseUrl}}/roles/:roleId/members",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "roles",
            ":roleId",
            "members"
          ],
          "variable": [
            {
              "key": "roleId",
              "value": "quis officia in reprehenderit",
              "description": "(Required) The role ID"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}