Refreshing Tokens

Here are all the steps to get a new access token and refresh token.


Endpoint


Method URI
POST https://apiv2.keliweb.it/oauth/token

Request Parameters


Parameter Type Description Required
grant_type string default value: refresh_token Required
client_id string The client ID provided to access APIs Required
client_secret string The client secret key provided to access APIs Required
refresh_token string The refresh token Required

Response Parameters


Parameter Type Description
token_type string default value: Bearer
expires_in integer The token lifetime (in seconds)
access_token string The access token
refresh_token string The refresh token

Example Request (PHP Curl)

            

                    $curl = curl_init();
                    
                    curl_setopt_array($curl, array(
                      CURLOPT_URL => "https://apiv2.keliweb.it/oauth/token",
                      CURLOPT_RETURNTRANSFER => true,
                      CURLOPT_ENCODING => "",
                      CURLOPT_MAXREDIRS => 10,
                      CURLOPT_TIMEOUT => 0,
                      CURLOPT_FOLLOWLOCATION => false,
                      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                      CURLOPT_CUSTOMREQUEST => "POST",
                      CURLOPT_POSTFIELDS =>
                        http_build_query(
                                array(
                                    'grant_type'    => 'refresh_token',
                                    'client_id'     => 'ea9ea94e-a0c2-4b87-9834-26b218ed26a0',
                                    'client_secret' => 'MoQSElJG5MoLkVhRJCJ7jdQZVwfbrtwKKepwOsXO',
                                    'refresh_token' => 'def50200cb918cb70defe79d45f1f2193c4c0a959fd78a5c3123e5d3f33f3b8af6b1080f6c7458e910f6992f4f7b2f25da42b58ae7542950',
                                )
                            ),
                      CURLOPT_HTTPHEADER => array(
                        "Content-Type: application/x-www-form-urlencoded",
                        "X-Requested-With: XMLHttpRequest"
                      ),
                    ));
                    
                    $response = curl_exec($curl);
                    $err = curl_error($curl);
                    
                    curl_close($curl);
                    
                    if ($err) {
                      echo "cURL Error #:" . $err;
                    } else {
                      echo $response;
                    }

            
        

Example Request (jQuery AJAX)

            
                    var form = new FormData();

                    form.append("grant_type", "refresh_token");
                    form.append("client_id", "ea9ea94e-a0c2-4b87-9834-26b218ed26a0");
                    form.append("client_secret", "MoQSElJG5MoLkVhRJCJ7jdQZVwfbrtwKKepwOsXO");
                    form.append("refresh_token", "def50200cb918cb70defe79d45f1f2193c4c0a959fd78a5c3123e5d3f33f3b8af6b1080f6c7458e910f6992f4f7b2f25da42b58ae");
                    
                    var settings = {
                      "async": true,
                      "crossDomain": true,
                      "url": "https://apiv2.keliweb.it/oauth/token",
                      "method": "POST",
                      "headers": {
                        "cache-control": "no-cache",
                      },
                      "processData": false,
                      "contentType": false,
                      "mimeType": "multipart/form-data",
                      "data": form
                    }
                    
                    $.ajax(settings).done(function (response) {
                      console.log(response);
                    });
            
        

Example Response (JSON payload)

            
                    {
                        "token_type": "Bearer",
                        "expires_in": 3600,
                        "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImYyYjBjOWNkODFiYzRmODMwOGZlNjZkZjAxZWY0MmVkZjc1YTRmMDU3NjFlODk2ZjZ",
                        "refresh_token": "def50200cb918cb70defe79d45f1f2193c4c0a959fd78a5c3123e5d3f33f3b8af6b1080f6c7458e910f6992f4f7b2f25da42b58ae75429"
                    }