wger Workout Manager provides a full REST API to all database objects: https://wger.de/api/v2/
Authentication
Public endpoints, such as the list of exercises or the ingredients can be accessed without authentication. For user owned objects such as workouts, you need to generate an API KEY and pass it in the header, see the link on the sidebar for details.
You should always use HTTPS if possible when communicating with the server.
Public endpoints
- daysofweek
- equipment
- exercise
- exerciseinfo
- exercisecategory
- exercisecomment
- exerciseimage
- ingredient
- ingredienttoweightunit
- language
- license
- muscle
- weightunit
- setting-repetitionunit
- setting-weightunit
Private endpoints
- day
- meal
- mealitem
- nutritionplan
- schedule
- schedulestep
- set
- setting
- userprofile
- weightentry
- workout
- workoutlog
Format negotiation
At the moment only JSON and the browsable HTML view are supported, but other formats such as YAML or XML could be theoretically be added, should the need arise. Because of this, for the majority of REST clients it will not be necessary to explicitly set the format, but you have the following options:
- Set the Accept header:
application/json
-
application/json; indent=4
- useful for debugging, will indent the result -
text/html
- browsable HTML view
-
Set the format directly in the URL:
-
/api/v2/<endpoint>.json/
-
/api/v2/<endpoint>/?format=json
-
/api/v2/<endpoint>.api/
- browsable HTML view
-
Fetching Data
# Api-Wide /api/v2/ # Object detail view /api/v2/<endpoint>/<id>/
This lists out all the different resources available. If you visit the link with a browser, you'll get a human-browsable HTML version of the contents. If you are logged in, you can use the built in form to try different requests (POST, PATCH, etc.)
You can do a OPTIONS /api/v2/<endpoint>/
to get more
information on the endpoint such as the accepted formats. It also outputs
a listing with all the resource's fields, their type (date, int, etc.) and
a short description. This is more easier done when using the browseable
version.
Miscellaneous operations
Ordering
Simply use ?ordering=<fieldname>
to order by that field.
You can also specify more than one field name, just give it a list separated
by commas ?ordering=<field1>,<field2>
. To reverse
the order use like in django a -
in front of the field.
Pagination
By default all results are paginated by 20 elements per page. If you want to
change this value, add a ?limit=<xxx>
to your query.
You will find in the answer JSON the next
and previous
keywords with links to the next or previous result pages.
Filtering resources
You can easily filter all resources by specifying the filter queries in the
URL: ?<fieldname>=<value>
, combinations are possible,
the filters will be AND-joined: ?<f1>=<v1>&<f2>=<v2>
.
Please note that for boolean values you must pass 'False' or 'True' other
values, e.g. 1, 0, false, etc. will be ignored. Like with not filtered queries,
your objects will be available under the 'results' key.
Note that it is not currently possible to specify more than one value, e.g. category 1 or 2.
Some examples:
- All exercises in German:
api/v2/exercise/?language=1
- 'Main' image for all exercises:
api/v2/exerciseimage/?is_main=True
- Exercises that train the biceps with barbells:
api/v2/exercise/?muscles=1&equipment=3
Submitting exercise images
If you want to submit exercise pictures, remember that you have to set the
correct header Content-Type: multipart/form-data
, otherwise the
file upload won't work.
Exercises
When accessing exercises, consider that by default all exercises are
returned, including those submitted by users but not yed approved. You will
very probably want to add a &status=2
to your URL to only get the
ones already added to the database.
Also note that, at the moment, to actually retrieve all the details for an exercise you will need to fire up different queries for the images, comments, etc.
Special endpoints
The following endpoints provide additional information, comfort functions, etc.:
api/v2/workout/<id>/canonical_representation/
api/v2/exerciseimage/<id>/thumbnails/
api/v2/exerciseiinfo/<id>/
api/v2/nutritionplan/<id>/nutritional_values/
api/v2/meal/<id>/nutritional_values/
api/v2/mealitem/<id>/nutritional_values/
Data documentation
The data structures should be pretty forward and easy to understand: a workout is composed of workout days. Each day has different exercises they in turn have repetitions, and so on. These diagrams are automatically generated from the database structure, which is basically exposed through the API 1-to-1. Click on the images to download a bigger version.
Tools
You can play and experiment with the API by sending the requests with many tools, here are two:
# In the terminal, e.g. bash curl -H "Authorization: Token 123456..." \ -H "Accept: application/json; indent=4" \ -X PATCH --data '{"key": value, ...}' \ --dump-header - https://wger.de/api/v2/....
# In the python console >>> import requests >>> import json >>> from pprint import pprint >>> >>> url = 'https://wger.de/api/v2/....' >>> data = '{"key": "value"}' >>> headers = {'Accept': 'application/json', 'Authorization': 'Token 12345...'} >>> r = requests.patch(url=url, data=data, headers=headers) >>> r >>> r.content >>> pprint(json.loads(r.content))
/api/v1
Deprecation warning