Skip to content

JSON REST API

Sebastian Pütz edited this page Jan 27, 2020 · 7 revisions

Endpoints

The endpoints are defined as follows. By default, all endpoints return JSON unless otherwise stated.

Projects

  • GET /rest/projects/ Will return the latest 20 Projects by default
  • GET /rest/projects?limit=40 Will return the latest 40 projects
  • GET /rest/events?limit=40&union=muenster,osnabrueck Will return the latest 40 projects for Weitblick Muenster and Osnabrück
  • GET /rest/projects?start=2019-10-01&end=2020-01-01&limit=30 Will return 30 projects in the specified time range
  • GET /rest/projects/123 Project with id 123

Filter Parameters

  • limit Restricts the number of elements to be returned. Default is 20.
  • union Filter for a corresponding host / union, use the slag ids, e.g., `osnabrueck,muenster
  • start Specifies the start date, all entries after that date will be returned with respect to the other filters
  • end Specifies the end date, all entries before that date will be returned with respect to the other filters
  • archive Filters for a specific month or year, e.g., 2018 or 2017-06. Only active if start or end is not set.
  • search Filters for a specific search value / word(s)
  • country Filters for countries, e.g., de, en, or en,de
  • visibility Filters for completed projects and for current projects, if not specified, all projects are returned with respect to the other filter parameters

Events

  • GET /rest/events/ Will return the latest 20 events by default
  • GET /rest/events?limit=40 Will return the latest 40 events
  • GET /rest/events?limit=40&host=muenster, osnabrueck Will return the latest 40 events for Weitblick Muenster and Osnabrück
  • GET /rest/events?start=2019-10-01&end=2020-01-01&limit=30 Will return 30 events in the specified time range
  • GET /rest/events/123 Event with id 123

Filter Parameters

  • limit Restricts the number of elements to be returned. Default is 20.
  • union Filter for a corresponding host / union, use the slag ids, e.g., `osnabrueck,muenster
  • start Specifies the start date, all entries after that date will be returned with respect to the other filters
  • end Specifies the end date, all entries before that date will be returned with respect to the other filters
  • archive Filters for a specific month or year, e.g., 2018 or 2017-06. Only active if start or end is not set.
  • search Filters for a specific search value / word(s)

Blog Posts

  • GET /rest/blog/ Will return the latest 20 blog posts by default
  • GET /rest/blog?limit=40 Will return the latest 40 posts
  • GET /rest/nlog?limit=40&host=muenster,osnabrueck Will return the latest 40 blog posts for Weitblick Muenster and Osnabrück
  • GET /rest/blog?start=2019-10-01&end=2020-01-01&limit=30 Will return 30 posts in the specified time range
  • GET /rest/blog/123 Blog-Post with id 123

Filter Parameters

  • limit Restricts the number of elements to be returned. Default is 20.
  • union Filter for a corresponding host / union, use the slag ids, e.g., `osnabrueck,muenster
  • start Specifies the start date, all entries after that date will be returned with respect to the other filters
  • end Specifies the end date, all entries before that date will be returned with respect to the other filters
  • archive Filters for a specific month or year, e.g., 2018 or 2017-06. Only active if start or end is not set.
  • search Filters for a specific search value / word(s)

News Posts

  • GET /rest/news/ Will return the latest 20 news posts by default
  • GET /rest/news?limit=40 Will return the latest 40 posts
  • GET /rest/events?limit=40&host=muenster,osnabrueck Will return the latest 40 news posts for Weitblick Muenster and Osnabrück
  • GET /rest/news?start=2019-10-01&end=2020-01-01&limit=30 Will return 30 posts in the specified time range
  • GET /rest/news/123 News-Post with id 123

Filter Parameters

  • limit Restricts the number of elements to be returned. Default is 20.
  • union Filter for a corresponding host / union, use the slag ids, e.g., `osnabrueck,muenster
  • start Specifies the start date, all entries after that date will be returned with respect to the other filters
  • end Specifies the end date, all entries before that date will be returned with respect to the other filters
  • archive Filters for a specific month or year, e.g., 2018 or 2017-06. Only active if start or end is not set.
  • search Filters for a specific search value / word(s)

Hosts

Hosts are the city associations, e.g., Weitblick Osnabrück, or Weitblick Münster

  • GET /rest/hosts/ Will return all hosts
  • GET /rest/news/osnabrueck Will return the Host Meta Data for Weitblick Osnabrück e.V.

Locations

  • GET /rest/locations/ Will return all locations
  • GET /rest/locations/123 Will return the location with the id 123

Addresses

  • GET /rest/addresses will return all addresses
  • GET /rest/addresses/123 will return the address with the id 123

Auth

Login

Check the credentials and return the REST Token if the credentials are valid and authenticated.

Accept the following POST parameters: username, email, password Return the REST Framework Token key.

  • POST /rest/auth/login/

Request:

{
    "username": "",
    "email": "",
    "password": ""
}

Response:

{
    "key": "{{ token }}"
}

Logout

  • POST /rest/auth/logout/
  • Header: Authorization: Token {{ token }} Logout delets the Token object assigned to the current User object.

Change Password

  • POST /rest/auth/password/change/
  • Header: Authorization: Token {{ token }}

Accepts the following POST parameters: new_password1, new_password2 Returns the success/fail message.

{
    "new_password1": "{{ new password 1 }}",
    "new_password2": "{{ new password 2 }}",
}

Rest Password

  • POST /rest/auth/password/reset/

Accepts the following POST parameters: email Returns the success/fail message.

{
    "email": "{{ email }}",
}

Rest Confirm Password

  • POST /rest/auth/password/reset/confirm/

Password reset e-mail link is confirmed, therefore this resets the user's password. Accepts the following POST parameters: token, uid, new_password1, new_password2 Returns the success/fail message.

{
    "new_password1": "{{ new password 1 }}",
    "new_password2": "{{ new password 2 }}",
    "uid": "{{ uid }}",
    "token": "{{ token }}",
}

User Details

  • GET, PUT, PATCH /rest/auth/user/
  • Header: Authorization: Token {{ token }}

Reads and updates UserModel fields Accepts GET, PUT, PATCH methods. Default accepted fields: username, first_name, last_name Default display fields: pk, username, email, first_name, last_name Read-only fields: pk, email Returns UserModel fields.

Request:

{
    "username": "{{ username }}",
    "first_name": "{{ first name }}",
    "last_name": "{{ last name }}"
}

Response:

{
    "pk": "{{ private key }}",
    "username": "{{ username }}",
    "email": "{{ email }}",
    "first_name": "{{ first name }}",
    "last_name": "{{ last name }}",
    "image": "{{ user image uri }}",
}

Cycle

Cycle Donations

  • GET /rest/cycle/donations/

Returns the cycle donation objects structured as follows:

[
    {
        "id": "1",
        "projects": [
            {
                "project": 1,
                "cycle_donation": 1,
                "current_amount": 100.0,
                "goal_amount": 10000.0,
                "finished": false
            }
        ],
        "partner": 1,
        "logo": "/media/WeitblickOsnabrueckLogo.png",
        "name": "Fahren von Weitblick Osnabrück",
        "description": "Test Beschreibung",
        "goal_amount": 10000.0,
        "rate_euro_km": 0.1
    }
]

Cycle Segment

  • POST /rest/cycle/segment/ adds a cycle segment for a user.
  • Header: Authorization: Token {{ token }}

Request The request should contain the following JSON structure:

{
    "start": "2019-10-01T07:08:04Z",
    "end": "2019-10-01T07:08:14Z",
    "distance": 0.16,
    "project": 1,
    "tour": 0,
}

Response

{
    "tour": 0,
    "project": {
        "id": "1",
        "hosts": [
            "osnabrueck"
        ],
        "cycle": [
            {
                "project": 1,
                "cycle_donation": 1,
                "current_amount": 100.016,
                "goal_amount": 10000.0,
                "finished": false
            }
        ]
    },
    "finished": false,
    "euro": 0.016,
    "km": 0.16
}

Cycle Ranking

  • GET /rest/cycle/ranking returns the cycle ranking with user objects.
  • Header: Authorization: Token {{ token }}

Returns a list of user objects with the following content:

{
"user_field": [
    {
        "username": "{{ user name }}",
        "image": {{ user image URI }},
        "km": {{ cycled km of user }},
        "euro": {{ cycled amount of donations in euros }}
    }, ...],
"best_field":
[
    {
        "username": "{{ user name }}",
        "image": {{ user image URI }},
        "km": {{ cycled km of user }},
        "euro": {{ cycled amount of donations in euros }}
    }, ....]
}

Cycle Tours

  • GET /rest/cycle/tours/
  • Header: Authorization: Token {{ token }}

Response

[
    {
        "tour": 0,
        "project": {
            "id": "1",
            "hosts": [
                "osnabrueck"
            ],
            "cycle": [
                {
                    "project": 1,
                    "cycle_donation": 1,
                    "current_amount": 100.016,
                    "goal_amount": 10000.0,
                    "finished": false
                }
            ]
        },
        "finished": false,
        "euro": 0.016,
        "km": 0.16
    }
]