Refresh Tokens

Refresh an Access token using the Refresh token to continue making calls on Peoplevine APIs.

Refresh a token via the API

The Refresh token is used to reactivate the Access token once the Access token’s 30 minute time limit expires. The Access token can be refreshed for 24 hours if the remember_me parameter was set to false in the call that created the Access and Refresh tokens, or for 7 days if the remember_me parameter was set to true.

Refreshing a token requires a call to the /api/token/refresh API containing your current access_token and refresh_token data. An example of this call is as follows:

{
   "access_token" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Im9lbWFwaSJ9.eyJpYXQiOjE2MDU4MjUwODAsIm5iZiI6MTYwNTgyNTA1MCwiZXhwIjoxNjA1ODI1MzgwLCJqdGkiOiJmYzA5ZjZlOC1iOTI2LTQ2MWQtYWY2Yy01NDFmNDQzOTZlOTQiLCJzZXNzaW9uX2lkIjoidFdiTEhtblhWOWR1VDhBL1hhRVIyU2ljdmVhQm41SkU0eVF6U21JZ0FPSGdpNlZrQ2ZsNmRpSXpZRkFNT0wzM2ZIRk9NVTl5dGt2NzdKTENnYnB2OUE9PSJ9.VLRuUfLc-JWdayKnc7LJgTC1snWlC4O1Rtc-xEUMwD5nr5GTPJJpvorhg3lE4IFDEjyy0fDDac1w_e6HtDZ4s1xVMy-CBfBRsovGl6p17CgQ6sz8LaSXIkJSG9OdatdaehA9hJF4Au-_21r1sFcFrt5T1YZM3ODd4QNvEiC_fPbbXtUPsfmcl713oRrUwpoz28ktbA1pWHd0fYX8msC0z_9zD-xGRCJlye1Kul2w6i2i4LJOyovgd31SJJ-sRk5w8WVwQkIFIoUR7nUCwZYzlROOMEKjfclUfHA7RR3rUnc5hPa-8u_tfGye74Nw50pAjDkj8IDulvK1DV3S55uw8w",
   "refresh_token": "tWbLHmnXV9duT8A/XaER2SicveaBn5JE4yQzSmIgAOHgi6VkCfl6diIzYFAMOL33fHFOMU9ytkv77JLCgbpv9A=="
}

Once a token has been successfully refreshed, it can continue to be used to access Peoplevine APIs.

Request and refresh a token in your code

You can both request and refresh a token programmatically in your app code to reduce the need for manual interaction with the APIs. Click the tab below matching your app language for example code snippets. Make sure to replace the following text with your company's information to make the code work as expected.

  • username

  • password

  • company_id

// Define the base URL for the API
const baseUrl = 'https://api.peoplevine.com/api/token';

// Define the interface for the user authentication response
interface UserAuthResponse {
  refresh_token: string;
  access_token: string;
}

async function authenticate(): Promise<void> {
  try {
    // Define the JSON payload for user authentication
    const userAuthPayload = {
      username: 'example@example.com',
      password: '****',
      grant_type: 'password',
      remember_me: true,
    };

    // Send the user authentication request
    const userAuthResponse = await fetch(baseUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(userAuthPayload),
    });

    if (!userAuthResponse.ok) {
      throw new Error('User authentication request failed');
    }

    const { refresh_token, access_token } = await userAuthResponse.json() as UserAuthResponse;

    // Define the JSON payload for company authentication
    const companyAuthPayload = {
      refresh_token,
      access_token,
      grant_type: 'access_token',
      company_id: 1234567,
    };

    // Send the company authentication request
    const companyAuthResponse = await fetch(baseUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(companyAuthPayload),
    });

    if (!companyAuthResponse.ok) {
      throw new Error('Company authentication request failed');
    }

    const companyAuthResult = await companyAuthResponse.json();
    // Handle the response from the company authentication request
    console.log(companyAuthResult);
  } catch (error) {
    // Handle any errors that occurred during the requests
    console.error('An error occurred:', error);
  }
}

// Call the authenticate function
authenticate();

This will automatically create the User Access token, then create the User Company Access token. It will also refresh a token automatically when the Access token expires.