Tech Blog

User Tokens and the Primo APIs

Several of the Primo REST APIs operate in the context of a user. Those APIs require that the caller send in a token which represents the user’s context. This post lays out the steps required to create the token and use it in subsequent API calls.

Create the Token

To create the user token, you use the JWT API. The API expects to receive a payload with details about the user and the desired scope. The payload includes the following fields:

FieldDescription
viewIdThe code of the desired view. For Primo VE, use the institution code as well, i.e. 01MY_INST:VIEW1
institutionInstitution code, i.e. 01MY_INST
language4 character language code, i.e. en_US
userNameThe primary ID of the user
userGroupThe user group for the context
onCampusWhether the user should be considered on campus during this session
$ curl -X POST -H 'Content-type: application/json' -d '{"viewId":"01MY_INST:VIEW1","institution":"01MY_INST","language": "en_US","userName": "jsmith","userGroup":"","onCampus": "true"}' https://api-na.hosted.exlibrisgroup.com/primo/v1/userJwt?apikey=l8xx...

"eyJraWQiOiJwcmltYVByaXZhdGVLZXktVFJfSU5URUdSQVRJT05fSU5TVCIsImFsZyI6IkVTMjU2In0.eyJpc3MiOiJQcmltYSIsImp0aSI6IkEwRkRBQzU2OTBCRUVDNjgxQ0Y1QzkwRTM4MTY3Q0JGLmFwaTAxLm5hMDEucHJvZC5hbG1hLmRjMDQuaG9zdGVkLmV4bGlicmlzZ3Jvd..."

The response is a string which contains the JWT token.

Using the Token

The token can now be used to make requests in the user’s context, such as the Favorites API. The token is placed in the Authorization header as follows: Authorization: Bearer <TOKEN>. The token must be used in conjunction with the API Key, which should be placed in the query string.

For example, to retrieve the user’s favorites, perform the following request:

$ curl -H 'Authorization: Bearer eyJraWQiOiJwcmltYVByaXZhdGVLZXkt...' https://api-na.hosted.exlibrisgroup.com/primo/v1/favorites?apikey=l8xx...

{
  "totalItems" : 0,
  "unlabeledRecords" : 0,
  "labels" : { },
  "records" : [ ]
}

I hope this example provides insight into how to call the Primo APIs with user tokens.

Leave a Reply