> 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. # Update short code PUT https://%7BYour_Space_Name%7D.signalwire.com/api/relay/rest/short_codes/{id} Content-Type: application/json Changes how a project Short Code is identified or routes inbound messages. It can route incoming traffic to a cXML webhook, cXML Application, or Relay handler. Standard project phone numbers use [Update phone number](/docs/apis/rest/phone-numbers/update-phone-number) instead. #### Permissions The API token used to authenticate must have the following scope(s) enabled to make a successful request: _Numbers_. [Learn more about API scopes](/docs/platform/your-signalwire-api-space). Reference: https://signalwire.com/docs/apis/rest/short-codes/update-short-code ## 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 ### Path parameters - `id` (string, required) — Unique ID of the short code. ### Body (application/json) This endpoint expects an UpdateShortCodeRequest. - `name` (string, required) — The name given to the short code. - `message_handler` (enum, required) — The message handler type for incoming messages. - Allowed values: `relay_context`, `laml_webhooks`, `laml_application` - `message_request_url` (string, optional) — The URL to send message requests to when using laml_webhooks handler. - `message_request_method` (enum, optional, default: POST) — The HTTP method to use for message requests. Defaults to POST. - Allowed values: `GET`, `POST` - `message_fallback_url` (string, optional) — The fallback URL for message requests. - `message_fallback_method` (enum, optional, default: POST) — The HTTP method to use for fallback requests. Defaults to POST. - Allowed values: `GET`, `POST` - `message_laml_application_id` (string, optional) — The ID of the LāML application to handle messages when using laml_application handler. - `message_relay_context` (string, optional) — The Relay context to use when using relay_context handler. ## Response ### 200 The request has succeeded. - `id` (string, required) — The unique identifier of the short code. - `name` (string, required, nullable) — The name given to the short code. - `number` (string, required) — The short code number. - `capabilities` (list of enum, required) — The messaging capabilities of the short code. - Allowed values: `sms`, `mms` - `number_type` (enum, required) — The type of number (always 'shortcode'). - Allowed values: `shortcode` - `code_type` (enum, required) — The type of short code. - Allowed values: `vanity`, `random` - `country_code` (string, required) — The ISO 3166-1 alpha-2 country code. - `created_at` (string, required) — The date and time when the short code was created. - `updated_at` (string, required) — The date and time when the short code was last updated. - `next_billed_at` (string, required, nullable) — The date and time when the short code will next be billed. - `lease_duration` (string, required, nullable) — The lease duration of the short code (e.g., '12 months'). - `message_handler` (enum, required, nullable) — The message handler type for incoming messages. - Allowed values: `relay_context`, `laml_webhooks`, `laml_application` - `message_request_url` (string, required, nullable) — The URL to send message requests to when using laml_webhooks handler. - `message_request_method` (enum, required, nullable) — The HTTP method to use for message requests. - Allowed values: `GET`, `POST` - `message_fallback_url` (string, required, nullable) — The fallback URL for message requests. - `message_fallback_method` (enum, required, nullable) — The HTTP method to use for fallback requests. - Allowed values: `GET`, `POST` - `message_laml_application_id` (string, required, nullable) — The ID of the LāML application to handle messages when using laml_application handler. - `message_relay_context` (string, required, nullable) — The Relay context to use when using relay_context handler. ## Errors ### 401 Unauthorized Error Access is unauthorized. - `error` (enum, required) - Allowed values: `Unauthorized` ### 404 Not Found Error The server cannot find the requested resource. - `error` (enum, required) - Allowed values: `Not Found` ### 422 Unprocessable Entity Error The request failed validation. See errors for details. - `errors` (list of Types.StatusCodes.SpaceApiErrorItem, required) — List of validation errors. ### 500 Internal Server Error An internal server error occurred. - `error` (enum, required) - Allowed values: `Internal Server Error` ## Types ### Types.StatusCodes.SpaceApiErrorItem Details about a specific validation error. - `detail` (string, required) — A description of what caused the error. - `status` (string, required) — The HTTP status code. - `title` (string, required) — A short summary of the error type. - `code` (string, required) — The error code. ## Examples **Request** ```json { "name": "My Short Code", "message_handler": "relay_context" } ``` **Response** ```json { "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "name": "My Short Code", "number": "12345", "capabilities": [ "sms" ], "number_type": "shortcode", "code_type": "vanity", "country_code": "US", "created_at": "2023-01-15T10:30:00Z", "updated_at": "2023-01-15T10:30:00Z", "next_billed_at": "2024-01-15T10:30:00Z", "lease_duration": "12 months", "message_handler": "relay_context", "message_request_url": "https://example.com/message", "message_request_method": "GET", "message_fallback_url": "https://example.com/fallback", "message_fallback_method": "GET", "message_laml_application_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "message_relay_context": "my-context" } ``` **SDK Code** ```python import requests url = "https://{your_space_name}.signalwire.com/api/relay/rest/short_codes/id" payload = { "name": "My Short Code", "message_handler": "relay_context" } headers = { "Content-Type": "application/json" } response = requests.put(url, json=payload, headers=headers, auth=("", "")) print(response.json()) ``` ```javascript const url = 'https://{your_space_name}.signalwire.com/api/relay/rest/short_codes/id'; const credentials = btoa(":"); const options = { method: 'PUT', headers: { Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json' }, body: '{"name":"My Short Code","message_handler":"relay_context"}' }; 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/relay/rest/short_codes/id" payload := strings.NewReader("{\n \"name\": \"My Short Code\",\n \"message_handler\": \"relay_context\"\n}") req, _ := http.NewRequest("PUT", 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/relay/rest/short_codes/id") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Put.new(url) request.basic_auth("", "") request["Content-Type"] = 'application/json' request.body = "{\n \"name\": \"My Short Code\",\n \"message_handler\": \"relay_context\"\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.put("https://{your_space_name}.signalwire.com/api/relay/rest/short_codes/id") .basicAuth("", "") .header("Content-Type", "application/json") .body("{\n \"name\": \"My Short Code\",\n \"message_handler\": \"relay_context\"\n}") .asString(); ``` ```php request('PUT', 'https://{your_space_name}.signalwire.com/api/relay/rest/short_codes/id', [ 'body' => '{ "name": "My Short Code", "message_handler": "relay_context" }', '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/relay/rest/short_codes/id"); client.Authenticator = new HttpBasicAuthenticator("", ""); var request = new RestRequest(Method.PUT); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"name\": \"My Short Code\",\n \"message_handler\": \"relay_context\"\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 = [ "name": "My Short Code", "message_handler": "relay_context" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://{your_space_name}.signalwire.com/api/relay/rest/short_codes/id")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "PUT" 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() ```