API Specifications Document
API Specifications Document
API Specifications Document
Welcome to the guide for using the Coursera for Business API. This document will lay out the
key details you need to access your API, how to set up access, the libraries and requests you
can use, and some FAQs.
Type Value
Client ID y0LScSEQuMjIsq2Ov8LAlA
Org ID c37xwraOSFytEjHm5uQEEA
This new Coursera account is created specifically for the API client and is authorized to access
organization information about the API.
After logging in, please navigate to your app page, where the OAuth client_id & client_secret
are displayed.
● Note them down as you will need these credentials later.
● The redirect URL can be adjusted if necessary.
The scope to be used is "access_business_api", which is not displayed on the page, but access
to the scope has been granted to the app.
To access program data, you will need your org_id, which is listed in the table at the top.
access_token
● The access_token will expire in 1800 seconds.
● You can get a new access_token with the refresh token you received (see step No 3).
● Every time when you requested a new access token it also prolongs the refrest_token
life (for two weeks.)
refresh_token
● The refresh_token will expire in two weeks.
● For the new refresh token, repeat step No 1.
Step No 4. Getting a new access_token with refresh_token
You should get a new access_token for new requests every 30min.
It’s important to also prolong the refresh_token lifetime by this action.
2. The response will have a new access_token and will look like below
{
"access_token": <access_token(NEW)>,
"token_type": "Bearer",
"expires_in": 1800
}
Explanation of parameters
Available Libraries
We have resources in Python and PHP to help with your development. The links below will
hopefully serve as useful examples regardless of what language you plan to develop in.
Python client
Coursera has released a python library for accessing Coursera APIs that are behind OAuth 2.0.
You can follow the instructions to install and setup the client. During the setup process, you
need to log in using the "sa+suncor@coursera.org" account. The script will download the
access and refresh tokens, and it will save them in a local file. After that when you make API
requests using the library, the tokens will be read from the file and be used to authenticate the
client.
PHP client
We do not have a PHP library to make Coursera specific calls, but there are open source PHP
clients for OAuth 2.0. For example, this PHP OAuth wrapper is quite easy to use. Linked below,
you can find two PHP files, which use that library to access the Coursera API. The first file,
setup.php, handles the OAuth2 handshake and downloads the access tokens. The second file,
programs.php, uses the saved tokens to make API requests.
Common Requests
The following postman collection contains many common requests you will want to make to the
Coursera API.
Troubleshooting
When I send the request from the step 4 I receive an error: "Invalid Code"
It is likely to be one of this reasons:
1. You tried to use a code for the second time
2. There is space before or after the code
3. There is a typo within one of the parameters in the request
After some time I send a request and get the error: "Not Authorized"
This means your access token is expired and you need to regenerate it by next request :
curl --location --request POST
'https://accounts.coursera.org/oauth2/v1/token' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'client_id=<client_id>' \
--data-urlencode 'client_secret=<client_secret>' \
--data-urlencode 'refresh_token=<refresh_token>'
When I send a request with unexpired access_token but get an error : "Not
Authorized"
It means when you received the code in step 2 you were logged into a personal account (eg
user@company.com) and not in your service account, which will be something like:
(sa+client_name@coursera.org).
General information
OAuth2 is a protocol designed to let third-party applications authenticate to perform actions as a
user, without getting the user's password. Coursera uses OAuth2 (specificallyRFC-6749) for
authentication and authorization of Coursera API.
Coursera only supports Authorization Code Flow grant which means you will be required to
login using a Coursera account during the Authorization request.
Performing the OAuth2 token request flow requires the following items that will be provided by
Coursera:
● Coursera account
● Your client_id
● Your client_secret(the client secret should never be shared)
FAQs
Below you can find answers to the most common issues you’ll face and questions you’ll have while
using the Coursera Enterprise APIs.
INVALID_EMAIL 400 Invalid email address You used the email with The refresh
you@mail invalid format. token is still valid
auth.perms 401 Missing authentication You need to update the Access token
access token. should be
updated.
DUPLICATE_EX 400 ExternalID You try to invite the same The refresh
TERNAL_ID 413861904646 already user with the same id but token is still
in use in roster with a different email valid.
uX6uZKfbS0iyIKcY160 address.
uGw
INVITATION_AL 400 An active invitation You try to invite the same The refresh
READY_EXISTS already exists for user with the same email token is still
jdoe@domain.com in address and id. valid.
program
_4R9y4T_EeiCTg7Px
GqkyA
MEMBERSHIP_ 400 A valid membership You try to invite a user that The refresh
ALREADY_EXIS already exists for id is already a member in the token is still
TS 45602592~uX6uZKfbS program. valid.
0iyIKcY160uGw, email
u@m
- 504 Request timed out. You used wrong limits. The refresh
Request: FINDER token is still
/api/enterpriseCourseE valid.
nrollmentReports.v1
finder: byProgram,
args: Map(id ->
7KDXEJQUEeeqWw7v
8NDIpg), limit:
Some(1000), start:
Some(43000)
a. Be sure that you are not logged into a personal account on Coursera, even in a
different tab. It may be easier to use incognito mode.
b. We recommend to use https://accounts.coursera.org/console instead of
https://www.coursera.org/ to get the key.
c. You may be sending uppercase names for parameters: “Client_id” & “Client_secret”.
Make sure to use lower case: “client_id” & “client_secret”.
d. There is a space between or after the parameters.
e. You have the wrong value for a parameter eg “Org_id”.
https://www.coursera.org/programs/your_program_id?productId=your_course_id&pro
ductType=course&showMiniModal=true
This is the url that will be used to redirect the response from Coursera. You will be able
to get the authorization code from this url, which can be used to get refresh and access
tokens for the first time. It can also be used for automatic response processing and
further requests for the pair of tokens.