> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # Create room token POST https://%7BYour_Space_Name%7D.signalwire.com/api/video/room_tokens Content-Type: application/json Creates a Room Token that a client consumes to join a named Video Room with the supplied identity, permissions, join window, and media settings. Call this operation from your server when granting a user access to an SDK-based room; never expose the project API token used to create it. Managed Video Conferences use their own [Conference Tokens](/docs/apis/rest/video/conference-tokens/list-conference-tokens). #### Permissions The API token used to authenticate must have the following scope(s) enabled to make a successful request: _Video_. [Learn more about API scopes](/docs/platform/your-signalwire-api-space). Reference: https://signalwire.com/docs/apis/rest/video/room-tokens/create-room-token ## Authentication - `Authorization` header (basic auth, required) — SignalWire Basic Authentication using Project ID and API Token. The client sends HTTP requests with the Authorization header containing the word Basic followed by a space and a base64-encoded string of project_id:token. The project ID will be used as the username and the API token as the password. Example: ``` Authorization: Basic base64(project_id:token) ``` ## Request ### Body (application/json) This endpoint expects a Video.CreateRoomTokenRequest. - `room_name` (string, required) — Room's unique named identifier. Allowed characters: A-Za-z0-9_-. Up to 100 characters. The room does not have to exist when the token is created, but must exist prior to joining, or ensure auto_create_room is set to true. - `user_name` (string, optional) — A display name to use for the user. Up to 100 characters. (If not supplied, a random alphanumeric string will be returned for each authorization with this token.) - `permissions` (list of enum, optional, default: ["room.self.audio_mute","room.self.audio_unmute","room.self.video_mute","room.self.video_unmute","room.self.deaf","room.self.undeaf","room.self.set_input_volume","room.self.set_output_volume","room.self.set_input_sensitivity","room.self.screenshare","room.self.additional_source"]) — A list of permissions, which define what user can do once they join the room. If `join_as` is `audience`, permissions are set to an empty array regardless of the value provided. - Allowed values: `room.member.audio_mute`, `room.member.audio_unmute`, `room.member.video_mute`, `room.member.video_unmute`, `room.member.deaf`, `room.member.undeaf`, `room.member.set_input_volume`, `room.member.set_output_volume`, `room.member.set_input_sensitivity`, `room.member.set_position`, `room.member.set_meta`, `room.member.raisehand`, `room.member.lowerhand`, `room.member.remove`, `room.member.promote`, `room.member.demote`, `room.hide_video_muted`, `room.list_available_layouts`, `room.lock`, `room.playback`, `room.playback_seek`, `room.prioritize_handraise`, `room.recording`, `room.set_layout`, `room.set_position`, `room.set_meta`, `room.show_video_muted`, `room.stream`, `room.unlock`, `room.self.audio_mute`, `room.self.audio_unmute`, `room.self.video_mute`, `room.self.video_unmute`, `room.self.deaf`, `room.self.undeaf`, `room.self.set_input_volume`, `room.self.set_output_volume`, `room.self.set_input_sensitivity`, `room.self.set_position`, `room.self.set_meta`, `room.self.raisehand`, `room.self.lowerhand`, `room.self.screenshare`, `room.self.additional_source` - `join_from` (datetime, optional) — The user can't join the room before this time. Expects RFC 3339 datetime: `2022-01-01T23:59:60Z`. Date only: `2022-01-01` will be converted to `2022-01-01T00:00:00Z` - `join_until` (datetime, optional) — The user can't join the room after this time. Expects RFC 3339 datetime: `2022-01-01T23:59:60Z`. Date only: `2022-01-01` will be converted to `2022-01-01T00:00:00Z` - `remove_at` (datetime, optional) — Remove user from the room at this time. Expects RFC 3339 datetime: `2022-01-01T23:59:60Z`. Date only: `2022-01-01` will be converted to `2022-01-01T00:00:00Z` - `remove_after_seconds_elapsed` (integer, optional) — Remove user after they are in the room for N seconds. - `join_audio_muted` (boolean, optional, default: false) — Whether the user joins the room with their audio muted. - `join_video_muted` (boolean, optional, default: false) — Whether the user joins the room with their video muted. - `auto_create_room` (boolean, optional, default: true) — By default, if the user tries to use this token to join a room that doesn't exist, it will be created with default configuration. Set this to false to require the room to exist beforehand. - `enable_room_previews` (boolean, optional, default: false) — Whether to generate a video with a preview of the content of the room. This parameter has effect only if this token auto-creates the room, thus it will be ignored if the room already exists. - `room_display_name` (string, optional) — Display name used if a room is auto-created when the token joins. Maximum of 200 characters. Defaults to the value of room_name. - `end_room_session_on_leave` (boolean, optional, default: false) — Whether to end the room session when the member using this token leaves the room. - `join_as` (enum, optional, default: member) — Whether the user should join as a member or as a non-interactive audience participant. Audience participants cannot send audio or video. - Allowed values: `audience`, `member` - `media_allowed` (enum, optional, default: all) — Indicates what media the user is allowed to receive. - Allowed values: `all`, `video-only`, `audio-only` - `room_meta` (VideoCreateRoomTokenRequestRoomMeta, optional) — Set the room meta. Maximum of 2000 characters when serialized to JSON. - `meta` (VideoCreateRoomTokenRequestMeta, optional) — Set the member meta. Maximum of 2000 characters when serialized to JSON. - `sync_audio_video` (boolean, optional, default: false) — Enable/disable jitter buffer audio-video sync. ## Response ### 200 The request has succeeded. - `token` (string, required) — A Room Token to be used by clients to connect to the Room. ## Errors ### 400 Bad Request Error The request is invalid. - `error` (enum, required) - Allowed values: `Bad Request` ### 401 Unauthorized Error Access is unauthorized. - `error` (enum, required) - Allowed values: `Unauthorized` ### 422 Unprocessable Entity Error The request contains invalid parameters. See errors for details. - `errors` (list of Types.StatusCodes.RestApiErrorItem, required) — List of validation errors. ### 500 Internal Server Error An internal server error occurred. - `error` (enum, required) - Allowed values: `Internal Server Error` ## Types ### VideoCreateRoomTokenRequestRoomMeta Set the room meta. Maximum of 2000 characters when serialized to JSON. ### VideoCreateRoomTokenRequestMeta Set the member meta. Maximum of 2000 characters when serialized to JSON. ### Types.StatusCodes.RestApiErrorItem Details about a specific error. - `type` (string, required) — The category of error. - `code` (string, required) — A specific error code. - `message` (string, required) — A description of what caused the error. - `url` (string, required) — A link to documentation about this error. - `attribute` (string, optional, nullable) — The request parameter that caused the error, if applicable. ## Examples **Request** ```json { "room_name": "my_room" } ``` **Response** ```json { "token": "eyJ0eXAiOiJWUlQiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2MjIxMjAxMjMsImp0aSI6ImRmMzFjYTQ4LWRiZGMtNGJjZi1hYWU2LTQ1NWEwOGM5NDg2YSIsInN1YiI6IjBjOTdmNjM1LTFjMTMtNGZjMS04NmY3LWJiMmJlODU5ZDhiOSIsInUiOiJKb2huIERvZSIsInIiOiJteV9zdXBlcl9hd2Vzb21lX3Jvb20iLCJzIjpbInJvb20uc2VsZi5hdWRpb191bm11dGUiXSwiYWNyIjp0cnVlLCJqZiI6MTYyMDg5NjQwMCwianUiOjE2MjA5MDU5NjgsInJhdCI6MTYyMDkwMDAwMCwicnNlIjo5MDB9.5mu_H2PjQLtNBbMsBlS0c91EgsDjJzvZUFgj5-tP4VA0VoHZPIGgV_DLRGKt-BqG-DqC5LhpsdMWEFjhVkTBpQ" } ``` **SDK Code** ```python import requests url = "https://{your_space_name}.signalwire.com/api/video/room_tokens" payload = { "room_name": "my_room" } headers = { "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers, auth=("", "")) print(response.json()) ``` ```javascript const url = 'https://{your_space_name}.signalwire.com/api/video/room_tokens'; const credentials = btoa(":"); const options = { method: 'POST', headers: { Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json' }, body: '{"room_name":"my_room"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://{your_space_name}.signalwire.com/api/video/room_tokens" payload := strings.NewReader("{\n \"room_name\": \"my_room\"\n}") req, _ := http.NewRequest("POST", url, payload) req.SetBasicAuth("", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://{your_space_name}.signalwire.com/api/video/room_tokens") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request.basic_auth("", "") request["Content-Type"] = 'application/json' request.body = "{\n \"room_name\": \"my_room\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://{your_space_name}.signalwire.com/api/video/room_tokens") .basicAuth("", "") .header("Content-Type", "application/json") .body("{\n \"room_name\": \"my_room\"\n}") .asString(); ``` ```php request('POST', 'https://{your_space_name}.signalwire.com/api/video/room_tokens', [ 'body' => '{ "room_name": "my_room" }', 'headers' => [ 'Content-Type' => 'application/json', ], 'auth' => ['', ''], ]); echo $response->getBody(); ``` ```csharp using RestSharp; using RestSharp.Authenticators; var client = new RestClient("https://{your_space_name}.signalwire.com/api/video/room_tokens"); client.Authenticator = new HttpBasicAuthenticator("", ""); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"room_name\": \"my_room\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let credentials = Data(":".utf8).base64EncodedString() let headers = [ "Authorization": "Basic \(credentials)", "Content-Type": "application/json" ] let parameters = ["room_name": "my_room"] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://{your_space_name}.signalwire.com/api/video/room_tokens")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```