error_outline
Apps connect other software to Ans through the API. An app acts as a separate user at your school and can only access the data and perform the actions allowed by the permissions your school approves. Unlike an API token, an app does not depend on the account of an employee, and it continues to work when that employee leaves the school.
This article explains how administrators install an app, and how app builders create one. In Ans, the app builder registers an app as an application in the API settings. Administrators find it as an app on the Integrations page.
Install an app
To install an app at your school, follow the steps below.
- Click on your School name from the home page.
- Click settings Settings in the menu at the top.
- Click Integrations in the menu on the left.
- Find the app under Apps, or type its name in the search bar. You can also open the installation link you received from the app builder.
- Click the app.
- Review the permissions listed under Permissions. These permissions determine which data the app can access and which actions it can perform. They are called scopes and apply across the entire school.
- Click Install.
- If the app has a setup URL, you are redirected to the website of the app. Follow its instructions to finish the setup.
The app is now listed under Installed on the Integrations page. Click the app to see who installed it, when, and which permissions it has.
lightbulb_outline Only install apps that need the permissions they ask for. A scope gives the app the same rights as an administrator for that type of data, across all courses, assignments and question banks of the school.
Approve new scopes for an installed app
Approve new scopes for an installed app
When an app builder adds scopes to an app, the app receives the new scopes only after your school approves them. Until then, the label Needs approval is displayed on the app in the Integrations page.
To approve new scopes, follow the steps below.
- Click on your School name from the home page.
- Click settingsSettings in the menu at the top.
- Click Integrations in the menu on the left.
- Click the app.
- Check the new scopes. They are labelled Needs approval under Permissions.
- Click Approve in the banner at the top of the page.
If you do not approve the new scopes, the app continues to work with the scopes it already has. Features of the app that need the new scopes do not work until you approve them.
Revoke an app
Revoke an app
Revoking an app removes all its access to your school at once. Its access tokens stop working and its webhooks are deleted.
To revoke an app, follow the steps below.
- Navigate to Manage integrations in Adminland.
- Click the app.
- Click the Revoke button in the Danger zone section.
- Click Revoke in the dialog to confirm.
You can install the app again later, unless the app is suspended. You then approve its scopes again.
What an app does at your school
What an app does at your school
An app works through its own user. This user:
- cannot log in to Ans and is not displayed in lists of people or in user counts.
- can only do what the approved scopes allow.
- is displayed as the author of the comments it posts and as the grader of the answers it grades.
Changes an app makes are recorded in the logs, like the changes of any other user.
A Suspended label on an app means Ans has suspended the app. A suspended app stops working at every school, and it cannot be installed, until the suspension is lifted.
Create an app
An app is created in the API settings of the school that builds it. Only administrators can create an app. After creating the app, you receive a client ID and a client secret. Your app uses these credentials to authenticate itself and request access tokens for the API.
To create an app, follow the steps below.
- Click on your School name from the home page.
- Click settings Settings in the menu at the top.
- Click API in the menu on the left.
- Click + New application under Applications.
- Optionally, click the image placeholder to upload an Icon. The icon must be a square PNG, JPEG or WebP image of at least 256×256 pixels and smaller than 1 MB.
- Enter the Name of the app. Administrators see this name when they install the app.
- Optionally, enter a Description of up to 200 characters. It is displayed on the app in the Integrations page.
- Optionally, enter the Setup URL. After an administrator installs the app, Ans redirects them to this URL, with the installation ID. It must start with https://.
- Select the Scopes the app needs: tick Read, Write or both for each type of data.
- Click Create.
- Copy the Client ID and the Client secret and store them in a safe place. Click the visibility -icon to display the secret, or the content_copy -icon to copy it.
- Click I've copied it.
error_outline
After you close the dialog, the page of the app displays its details and credentials. You can access this page later through API in the school settings by clicking the app under Applications. The client secret is not displayed again after you close the dialog. If you lose it, you need to regenerate it.
A new app is private: only your own school can install it. To install it at your school, see Install an app.
Choose scopes
Choose scopes
Each scope gives access to one type of data, such as courses, assignments or results. When creating an app, select the scopes it needs. You can also change these scopes later if your app needs access to additional data or no longer needs certain permissions.
In the Scopes table, each type of data has two options:
- Read allows the app to view data.
- Write allows the app to create, update and delete data. It also includes permission to read that data.
Administrators see the scopes as permissions, for example Read courses or Read & write results.
The API documentation lists the scope each endpoint requires. Only the beta version of the API accepts app tokens.
When you add a scope to an app that is already installed at other schools, each of those schools approves the new scope first. At your own school, the new scope is approved when you save. When you remove a scope, it stops working at every school at once, and webhooks that need it are deleted.
To edit the scopes of an app, follow the steps below.
- Navigate to Manage API in Adminland.
- Under Applications, click the app.
- Click the more_vert -icon next to the name of the app.
- Click Edit.
- Select or deselect the scopes.
- Click Update.
You can change the icon, name, description and setup URL of the app in the same way.
Connect your app to Ans
Connect your app to Ans
Each school that installs your app has its own installation. Your app requests an access token for each installation separately.
1. Receive the installation ID
After an administrator installs your app, Ans redirects them to the setup URL of your app, with the ID of the installation in the installation_id parameter. Store this ID with the school in your app.
Your app can also list all its installations with its client ID and client secret:
GET https://ans.app/api/beta/app/installations
Authorization: Basic base64(client_id:client_secret)
2. Request an access token
Send the client ID, the client secret and the installation ID as a form (application/x-www-form-urlencoded) in the body of the request:
POST https://ans.app/oauth/token
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&installation_id=<installation ID>
Instead of the Authorization header, you can send client_id and client_secret in the body. Do not send both.
The response contains the token:
{
"access_token": "ansapp_…",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "courses:read results:read"
}
By default, the token receives all scopes the school approved. To limit a token, add scope with a space-separated list of scopes, for example scope=courses:read.
3. Call the API
Send the token in the Authorization header of every request to the beta API:
GET https://ans.app/api/beta/me
Authorization: Bearer ansapp_…
A token is valid for one hour. Request a new token when it expires. If a request needs a scope the token does not have, the API returns 403 with "error": "insufficient_scope" and the missing scope.
You can also try the token request in the API documentation.
Receive events with webhooks
Receive events with webhooks
An app can create its own webhooks through the beta API, with POST /api/beta/webhooks and an access token of the installation. App webhooks have the following rules:
- The API version of the webhook must be beta.
- Each subscription requires the read scope of its data. For example,
result.updatedrequiresresults:read. - The
*subscription to all events is not available for apps. - An installation can have up to ten webhooks.
When a school revokes the app, the webhooks of that installation are deleted.
More information can be found in Use the API to create a webhook.
Regenerate the client secret
Regenerate the client secret
An app has one client secret. You cannot regenerate it while the app is suspended. The Client secret row in the Credentials section of the app displays when it was created and last used.
To regenerate the client secret, follow the steps below.
- Navigate to Manage API in Adminland.
- Under Applications, click the app.
- Click refresh next to Client secret in the Credentials section.
- Click Confirm.
- Copy the new client secret, click I've copied it and update the secret in your app.
error_outline
Delete an app
Delete an app
Deleting an app removes it from every school. The app can no longer request tokens, and every installation loses access.
If only your own school has installed the app, it is deleted immediately. You cannot undo this.
If other schools have installed the app, it is suspended at every school immediately and permanently deleted after 30 days. Until then, a banner on the page of the app displays the date of deletion. To cancel the deletion, click Don’t delete in the banner.
To delete an app, follow the steps below.
- Navigate to API in the school settings.
- Under Applications, click the app.
- Click more_vert next to the name of the app.
- Click Delete.
- Click Delete in the dialog to confirm.
Make an app available to other schools
Make an app available to other schools
A private app can only be installed at the school that created it. It has the label Private on the Integrations page. To make an app available to other schools, contact our Support team. After Support makes the app public, the Public switch on the app is on and any school can install it.
Share the installation link with the administrators of other schools:
https://ans.app/settings/apps/<app ID>/installations/new
The app ID is the last part of the URL of the app's page in your API settings.
When Support makes an app private again, schools that already installed it keep their installation.
Rate limits
Rate limits
Each installation has its own rate limit per minute, equal to the API rate limit of the school. This means an app does not compete with a single employee for the same limit. The requests of the app do count towards the school's total API volume, which is the rate limit multiplied by the number of concurrent requests in your plan. More information can be found in Increase API rate limit.
The following limits also apply:
- An installation can have up to ten active access tokens. When this limit is reached, the token request returns 429 with a
Retry-Afterheader. Reuse a token until it expires instead of requesting a new one for every API call. - An app can make up to 100 requests per minute to
/oauth/tokenand/api/beta/app/installations.
Learn more about the endpoints your app can use in What is the API.
Comments
0 comments
Article is closed for comments.