## An example app

Integrating with Clever’s API is very similar to implementing Google login, and should take 3-6 days of development time with one engineer, on average. An example integration can be found at https://github.com/brettcvz/clever-example-app/.

## Initiating the Single Sign-On Flow

Once the user accepts the data sharing consent screen, they will be routed to your redirect URI with an authentication code, identical to the standard Clever Instant Login (SSO) OAuth flow. Implement a route in your app (this corresponds to your redirect URI) to complete the code exchange for token and receive the user’s bearer token, request the user’s Clever ID and user type via /me endpoint. Follow the steps in [our SSO developer docs](🔗) for details.

Your Authorization header value will be a string containing the word _Bearer_ followed by a space character and then the access token value you receive after exchanging the auth code.

`GET https://api.clever.com/v2.1/me` Authorization: Bearer {bearer_token}

Once you've retrieved the user's Clever ID, you may want to ask the user if they already have an existing account, and if so, if they want to associate their Clever ID with their existing account.

## Determining if this is a district-shared object or a teacher-shared object

Many of our app partners support teachers and students who are shared at the district or school level, in addition to Library users (“teacher-shared”). You should always check to see if the user logging in is shared by the district or by a teacher so that you can route the user appropriately in your system (e.g. to either a premium or free-trial experience).

### Method 1: Checking for District ID

You may check the JSON response that you receive for the presence of a district ID, which will **always** be present for district-shared data, but will **never** be present for Sign Up with Clever users. You can then redirect the user appropriately, for example, to your paid or free/freemium product.

### Method 2: “Authorized_by” parameter (NEW in July 2018)

At the request of several of our partners to better distinguish between teachers shared by the district and Library teachers, we’ve added a /v2.1/me endpoint that provides an additional “authorized_by” parameter, which takes one of two values:

  • “teacher” - this user is shared because of a Sign Up with Clever action by the user or an associated teacher.

  • “district” - this user is shared because their district shared them via Clever.

`GET https://api.clever.com/v2.1/me` Authorization: Bearer {token}

## Syncing Teacher and Class Data

Here we’ll use the teacher’s Clever ID (obtained above) to retrieve teacher profile data, section data, and student data to create user accounts and teacher-student associations.

Recommended Account Provisioning Logic

If teacher’s Clever ID matches in the system → log them in Else → ask teacher if they want to merge an existing account or create a new one If merge → prompt for credentials and merge accounts Else → Create new user

Then, query Clever API for data and update existing records or create new ones → log them in

### Teacher Profile Data

`GET https://api.clever.com/v2.1/teachers/{teacher Clever ID}` Authorization: Bearer {token}

Once you've retrieved the user's Clever ID, you may want to ask the user if they already have an existing account, and if so, if they want to associate their Clever ID with their existing account.

### Section Data with Enrollments

`GET https://api.clever.com/v2.1/teachers/{teacher Clever ID}/sections` Authorization: Bearer {token}

### Student Profile Data

`GET https://api.clever.com/v2.1/sections/{section Clever ID}/students` Authorization: Bearer {token}

## Onboarding Questions

You may require certain information to create a teacher account, questions that are likely asked during your manual signup process: school association, subjects taught, country, etc. Given that, here, you’re only provided the teacher’s name and email address, if you need additional information from the teacher, **we recommend asking these questions during the teacher’s first-time onboarding into your application.**

Try to minimize steps for the teacher by pre-populating fields with information that is already provided by Clever, for example, teacher email, student grade, class subject. Consider relaxing certain mandatory field requirements for Library-based teachers in order to streamline the first time experience in your application.

## Encoding

Clever supports all UTF-8 characters, and your application should expect to receive special characters that might be found in names/email addresses such as _', -, ñ, à,_ etc.