NAV

Authentication for the V2 API

Getting Started


In order to authenticate to the Whiplash V2 APi, you will need the following:
The Whiplash V2 API uses Oauth2 as our authentication scheme.  This allows API requests to act on behalf of whoever authenticates with it.  When you authenticate as a user of a company, it allows you access to all of that customer's resources such as orders and items.

 Note: You will be required to manually create your initial Oauth token via Whiplash app authentication.  Once the relationship has been established, you can skip the manual login flow and just request refresh tokens.


Authenticating 


Step 1


   an example request is: 


   You will be prompted to authenticate in the Whiplash web app, do so with your login credentials.

Once you login, you will be a redirect to your redirect_uri with the parameter code appended to it.  For example:
 

(Note: we use hookbin.com just for an example, you could just as easily have this call an endpoint in your application.)

Retain this code value, it shall be refered to as RETURNED_CODE

Step 2

Make a POST to /oauth/token and include the following key/values in your post body:

  This will respond with a JSON object like:

  {
    "access_token": "ddb8c266333a19...",
    "token_type": "bearer",
    "expires_in": 7200,
    "scope": "user_manage",
    "created_at": 1510698627
    "refresh_token":"8c488ab5f75d61..."
}

This token will remain active for 2 hours, after that you will need to get a refresh token.  Hang onto the value of "refresh_token" so you will be able to get new tokens when this one expires.


Step 3

You can now make an API request to Whiplash on behalf of the user you authenticated as in Step 1. 
Simply add the Header Authorization:"Bearer YOUR_ACCESS_TOKEN"  (using the above example - Authorization: "Bearer ddb8c266333a19..." )

With that Header set, you can now call V2 API endpoints such as https://sandbox.getwhiplash.com/api/v2/items

Refresh Tokens

You can programatically get refresh tokens by sending a POST to /oauth/token with the following params:

This will return a new token response like:

  {
    "access_token": "ddb8c266333a19...",
    "token_type": "bearer",
    "expires_in": 7200,
    "scope": "user_manage",
    "created_at": 1510698627
    "refresh_token":"8c488ab5f75d61..."
}


You can now use the newly returned access_token as the value for your Authorization Header and retain the new refresh_token for future refresh calls.



Last updated Nov 21st, 2017