{% extends "base.html" %} {% load i18n static wger_extras %} {% block title %}{% translate "API access" %}{% endblock %} {% block content %}

{% blocktranslate trimmed %} Theare are two ways to authenticate against the API: JWT is the preferred mechanism for client applications, the static API key is intended for personal scripts or one-off integrations. {% endblocktranslate %}

{% translate "Long-lived refresh tokens" %}

{% blocktranslate trimmed %} Refresh tokens let scripts and CLI tools talk to the wger API using the JWT flow without logging in interactively each time. {% endblocktranslate %}

{% if new_refresh_token %}
{% translate "Copy this token now." %} {% blocktranslate trimmed %} It is shown only once. If you lose it, generate a new one and revoke the old session below. {% endblocktranslate %}
{{ new_refresh_token }}
{% endif %} {% if long_lived_sessions %}

{% blocktranslate trimmed with days=refresh_token_lifetime_days %} Refresh tokens expire {{ days }} days after they were generated, unless you revoke them sooner. {% endblocktranslate %}

{% for session in long_lived_sessions %} {% endfor %}
{% translate "Created" %} {% translate "Expires" %}
{{ session.long_lived.created|date:"Y-m-d H:i" }} {{ session.expire_date|date:"Y-m-d H:i" }}

{% endif %}

{% translate "JWT sessions" %}

{% blocktranslate count counter=active_jwt_sessions %} There is currently {{ counter }} active JWT session {% plural %} There are currently {{ counter }} active JWT sessions {% endblocktranslate %}

{% blocktranslate trimmed %} Revoking JWT sessions logs out every device that obtained a refresh token via the JWT login endpoint. {% endblocktranslate %}

{% translate "API key" %}

{% if token %}

{% endif %}
{% if token %} {{ token.key }} {% else %} {% translate "You have no API key yet" %} {% endif %}

{% blocktranslate with key=token.key|default:"1234567890abcde..." %} Pass Token {{ key }} in the Authorization header to use it. {% endblocktranslate %}

{% translate "Example with curl:" %}

curl -X GET https://wger.de/api/v2/routine/ \
     -H 'Authorization: Token {% if token %}{{ token.key }}{% else %}1234567890abcde...{% endif %}'
{% endblock %} {# #} {# Sidebar #} {# #} {% block sidebar %}
{% translate "Documentation" %}

{% translate 'API documentation' %}

{% endblock %}