Giter Site home page Giter Site logo

stepik-api's Introduction

Stepik.org API Readme

Stepik.org has REST API in JSON format. API endpoints are listed on https://stepik.org/api/docs, and you can also make API call there (but this page is limited to GET requests).

Stepik.org use the same API for its web front-end (JS app) and its iOS/Android applications. Therefore, almost all the platform features are supported in this API.

All API examples are up to date and working if the build status is passing: Build Status

Flat

Stepik API schema is flat, i.e. there are no nested end-points.

Every request returns a list of objects, even if only one object was requested. This list can contain 0 or more elements.

For example: https://stepik.org/api/courses/1 returns not a single course, but a list with single course.

Pagination

All responses to GET requests are paginated. They contain extra meta object with the information about pagination. It may look like this:

{
    meta: {
        page: 1,
        has_next: true,
        has_previous: false
    },
    requested_objects: [...]
}

If the next page exists, then it can be requested using get parameter ?page=.... By default, if no parameter is given, it’s equal to 1.

For example: https://stepik.org/api/courses is equal to https://stepik.org/api/courses?page=1. Next page: https://stepik.org/api/courses?page=2 and so on.

Usual page size is equal to 20 elements, but it can vary due to API endpoint, user’s permissions etc. We do not recommend to rely on a constant page size.

Side-Loading

Response may also contain multiple objects, related to the requested object.

For example: for registered user, response from https://stepik.org/api/courses also includes user’s course enrollments.

OAuth 2

In order to call Stepik.org API as a registered user, you can use this user’s OAuth2 keys. You can get your keys by creating an application on https://stepik.org/oauth2/applications/ (while being logged in), and you can also set redirect_uri, Client type and Authorization grant type there.

Authorization endpoint (Authorization code, Implicit grant; redirect_uri needed): https://stepik.org/oauth2/authorize/.

Token endpoint (Authorization code, Password and Client credentials): https://stepik.org/oauth2/token/.

Client credentials flow

You can then obtain access token using the following client credential flow:

curl -X POST -d "grant_type=client_credentials" -u"CLIENT_ID:CLIENT_SECRET" https://stepik.org/oauth2/token/

Response:

{"access_token": "ACCESS_TOKEN", "scope": "read write", "expires_in": 36000, "token_type": "Bearer"}

Example with access token:

curl -H "Authorization: Bearer ACCESS_TOKEN" "https://stepik.org/api/social-accounts?provider=github&uid=1216"

Response:

{"meta": {"page": 1, "has_next": false, "has_previous": false}, "social-accounts": []}

Authorization code flow

  • Set grant type = autorization_code and set redirect_uri in your application;
  • Redirect user to https://stepik.org/oauth2/authorize/?response_type=code&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI;
  • User should authenticate or register, and grant permissions to application;
  • It redirects to redirect_uri and receives the CODE;
  • Application asks for ACCESS_TOKEN: curl -X POST -d "grant_type=authorization_code&code=CODE&redirect_uri=REDIRECT_URI" -u"CLIENT_ID:SECRET_ID" https://stepik.org/oauth2/token/;
  • Application behaves as user, adding Authorization: Bearer ACCESS_TOKEN; to request headers.
  • Request to https://stepik.org/api/stepics/1 returns the current user.

Multiple IDs Calls

You can request multiple objects using the single API call by using ?ids[]=2&ids[]=3....

For example: to get courses with IDs = 2, 67, 76 and 70; you can to call https://stepik.org/api/courses?ids[]=2&ids[]=67&ids[]=76&ids[]=70.

This syntax is supported by all API endpoints.

Don’t make calls with large size of ids[]. Such calls may be rejected by the server because of a large HTTP header.

Examples

Simple operations:

Complete examples:

stepik-api's People

Contributors

mehanig avatar vyahhi avatar chisler avatar valeriyasinevich avatar eanioner avatar kirilltim avatar greenriverrus avatar shakhova avatar fineguy avatar ivan-afonichkin avatar pltb avatar archonoff avatar iskhakovt avatar kiryous avatar molchanovart avatar yanenkoa avatar 2pit avatar dainiak avatar krinkin avatar misteraverin avatar rbbelka avatar tsnik avatar psviderski avatar miloserdow avatar nkgsv avatar

Watchers

James Cloos avatar Igor Strebezhev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.