Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@frdmn
Last active January 16, 2019 14:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frdmn/fec5e5865cb7e794809143db61991c64 to your computer and use it in GitHub Desktop.
Save frdmn/fec5e5865cb7e794809143db61991c64 to your computer and use it in GitHub Desktop.
Rocket.Chat REST API setType channel/group
  1. Obtain authentication token

    XHOST=rocketchat.dev.company.com:3000
    
    curl -H "Content-type:application/json" \
    	http://${XHOST}/api/v1/login \
    	-d '{ "username": "test", "password": "test" }'
  2. Store tokens in variable

    XUID=mvkPzDTnebrnCuwPa
    XAT=ZCev4fFxUbJTEYknDZCyrIvh5htuBQEQH9JAxyjBwy7
  3. Call channel.create to create (public) channel

    curl -H "X-Auth-Token: ${XAT}" \
         -H "X-User-Id: ${XUID}" \
         -H "Content-type: application/json" \
         http://${XHOST}/api/v1/channels.create \
         -d '{ "name": "Test_1" }'
    
    {
    	"channel": {
    		"_id": "yAHBiDsRchnhj4NXf",
    		"name": "Test_1",
    		"fname": "Test_1",
    		"t": "c",
    		"msgs": 0,
    		"u": {
    			"_id": "mvkPzDTnebrnCuwPa",
    			"username": "test"
    		},
    		"customFields": {},
    		"ts": "2018-04-17T07:46:25.025Z",
    		"ro": false,
    		"sysMes": true,
    		"_updatedAt": "2018-04-17T07:46:25.025Z"
    	},
    	"success": true,
    	"developerWarning": "[WARNING]: The \"usernames\" field has been removed for performance reasons. Please use the \"*.members\" endpoint to get a list of members/users in a room."
    }
  4. Change type to p (rivate group) using channels.setType

    curl -H "X-Auth-Token: ${XAT}" \
         -H "X-User-Id: ${XUID}" \
         -H "Content-type: application/json" \
         http://${XHOST}/api/v1/channels.setType \
         -d '{ "roomId": "yAHBiDsRchnhj4NXf", "type": "p" }'
    {
    	"channel": {
    		"_id": "yAHBiDsRchnhj4NXf",
    		"name": "Test_1",
    		"fname": "Test_1",
    		"t": "p",
    		"msgs": 1,
    		"u": {
    			"_id": "mvkPzDTnebrnCuwPa",
    			"username": "test"
    		},
    		"customFields": {},
    		"ts": "2018-04-17T07:46:25.025Z",
    		"ro": false,
    		"sysMes": true,
    		"_updatedAt": "2018-04-17T07:46:55.296Z"
    	},
    	"success": true,
    	"developerWarning": "[WARNING]: The \"usernames\" field has been removed for performance reasons. Please use the \"*.members\" endpoint to get a list of members/users in a room."
    }
  5. Change type back to c (hannel) using groups.setType

    curl -H "X-Auth-Token: ${XAT}" \
         -H "X-User-Id: ${XUID}" \
         -H "Content-type: application/json" \
         http://${XHOST}/api/v1/groups.setType \
         -d '{ "roomId": "yAHBiDsRchnhj4NXf", "type": "c" }'
    {
    	"group": {
    		"_id": "yAHBiDsRchnhj4NXf",
    		"name": "Test_1",
    		"fname": "Test_1",
    		"t": "c",
    		"msgs": 2,
    		"u": {
    			"_id": "mvkPzDTnebrnCuwPa",
    			"username": "test"
    		},
    		"customFields": {},
    		"ts": "2018-04-17T07:46:25.025Z",
    		"ro": false,
    		"sysMes": true,
    		"_updatedAt": "2018-04-17T07:48:02.123Z"
    	},
    	"success": true,
    	"developerWarning": "[WARNING]: The \"usernames\" field has been removed for performance reasons. Please use the \"*.members\" endpoint to get a list of members/users in a room."
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment