# Cal.com Token Refresh & Integration POST /api/v1/bookings/token/refresh/ Content-Type: application/json Refreshes Cal.com access token for the authenticated user. For first-time users, this endpoint will also handle the initial Cal.com integration implicitly, including user creation and token setup. Reference: https://docs.aisquare.studio/api-reference/ai-square-studio-api/bookings/token-refresh-create ## OpenAPI Specification ```yaml openapi: 3.1.0 info: title: AISquare Studio API version: 1.0.0 paths: /api/v1/bookings/token/refresh/: post: operationId: token-refresh-create summary: Cal.com Token Refresh & Integration description: >- Refreshes Cal.com access token for the authenticated user. For first-time users, this endpoint will also handle the initial Cal.com integration implicitly, including user creation and token setup. tags: - subpackage_bookings responses: '200': description: Token refreshed successfully or integration completed content: application/json: schema: $ref: '#/components/schemas/CalTokenRefresh' '400': description: Bad request - invalid parameters content: application/json: schema: description: Any type '401': description: Unauthorized - user not authenticated content: application/json: schema: description: Any type '500': description: Internal server error during token refresh or integration content: application/json: schema: description: Any type requestBody: content: application/json: schema: $ref: '#/components/schemas/CalTokenRefreshRequest' components: schemas: CalTokenRefreshRequest: type: object properties: force_refresh: type: boolean default: false description: Force refresh even if token is still valid cal_email: type: string format: email description: Email for Cal.com integration (optional, defaults to user's email) timezone: type: string default: UTC description: Timezone for Cal.com integration (optional, defaults to UTC) description: >- Serializer for Cal.com token refresh request and optional integration parameters. title: CalTokenRefreshRequest CalTokenRefresh: type: object properties: access_token: type: string description: New Cal.com access token expires_in: type: integer description: Token expiry time in seconds token_type: type: string default: Bearer description: Token type refreshed: type: boolean description: Whether the token was refreshed or was still valid integration_status: type: string description: >- Integration status: 'created' for new users, 'existing' for returning users cal_client_id: type: string description: Cal.com OAuth client ID for frontend API integrations required: - access_token - refreshed - integration_status - cal_client_id description: Serializer for Cal.com token refresh response. title: CalTokenRefresh ``` ## SDK Code Examples ```python Token Refresh Success (Existing User) import requests url = "https://api.example.com/api/v1/bookings/token/refresh/" payload = {} headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript Token Refresh Success (Existing User) const url = 'https://api.example.com/api/v1/bookings/token/refresh/'; const options = {method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{}'}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Token Refresh Success (Existing User) package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.example.com/api/v1/bookings/token/refresh/" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) 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 Token Refresh Success (Existing User) require 'uri' require 'net/http' url = URI("https://api.example.com/api/v1/bookings/token/refresh/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request.body = "{}" response = http.request(request) puts response.read_body ``` ```java Token Refresh Success (Existing User) import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/api/v1/bookings/token/refresh/") .header("Content-Type", "application/json") .body("{}") .asString(); ``` ```php Token Refresh Success (Existing User) request('POST', 'https://api.example.com/api/v1/bookings/token/refresh/', [ 'body' => '{}', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Token Refresh Success (Existing User) using RestSharp; var client = new RestClient("https://api.example.com/api/v1/bookings/token/refresh/"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Token Refresh Success (Existing User) import Foundation let headers = ["Content-Type": "application/json"] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/api/v1/bookings/token/refresh/")! 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() ``` ```python First-time Integration Success import requests url = "https://api.example.com/api/v1/bookings/token/refresh/" payload = {} headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript First-time Integration Success const url = 'https://api.example.com/api/v1/bookings/token/refresh/'; const options = {method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{}'}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go First-time Integration Success package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.example.com/api/v1/bookings/token/refresh/" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) 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 First-time Integration Success require 'uri' require 'net/http' url = URI("https://api.example.com/api/v1/bookings/token/refresh/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request.body = "{}" response = http.request(request) puts response.read_body ``` ```java First-time Integration Success import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/api/v1/bookings/token/refresh/") .header("Content-Type", "application/json") .body("{}") .asString(); ``` ```php First-time Integration Success request('POST', 'https://api.example.com/api/v1/bookings/token/refresh/', [ 'body' => '{}', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp First-time Integration Success using RestSharp; var client = new RestClient("https://api.example.com/api/v1/bookings/token/refresh/"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift First-time Integration Success import Foundation let headers = ["Content-Type": "application/json"] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/api/v1/bookings/token/refresh/")! 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() ```