API response "unauthorized"

Hi all,

ich experimentiere seit heute mit der AWORK API via Postman. Leider erhalten ich bei jedem Request (z.B. GET /users oder POST /projecttimebookings; URL: https://api.awork.com/api/v1) eine Response:
{
„message“: „Unauthorized“
}

Ich habe:

  • als Admin User einen API Client Token erstellt
  • den Token als Bearer in den Header eingefügt

Muss ich irgendwo weitere Berechtigungen setzen/die API aktivieren?

Beste Grüße, Sebastian

Hi @sh1, kannst du bitte einen cURL deines Requests posten und den Token unkenntlich machen? Dann kann ich besser sehen wo der Fehler liegt. Danke

curl --location ‚https://api.awork.com/api/v1/users‘ \

–header ‚Authorization: Bearer ***‘

Der Fehler ist mittlerweile:
{
„message“: „Bad token; invalid JSON“
}

Was sind die ersten beiden Buchstaben deines Bearer Tokens?

Der Token beginnt mit „ta“

Dann hast du nicht den richtigen Token verwendet. Der Token muss mit ey beginnen. Kann es sein, dass du das Client Secret verwendet hast? Hier ist noch einmal die Step by Step Anleitung: Authentication - awork.com

Danke für die Unterstützung!

Ich habe das Client Secret statt dem API Token verwendet :face_with_spiral_eyes:

Gerne! Viel Spaß mit der API :slight_smile:

Hallo und sorry, dass ich den Thread nochmals öffne. Ich bin, wie sh1 auch, dabei mit der api und postman zu experimentieren.
Dazu hab ich auch den API-Key angelegt. Wenn ich das korrekt verstehe, muss ich nun einen OAuth-AccessToken generieren. Dazu hab ich für den authorization code folgenden request: curl ‚https://api.awork.com/api/v1/accounts/authorize?client_id=%client-ID%&response_type=code&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost&scope=offline_access
–header ‚Content-Type: application/x-www-form-urlencoded‘ \

als response bekomme ich hier eine http-seite zurück.
ich habe die generierte Url auch in den Browser gepastet und dort consent eingegeben.

könnt ihr mir bitte helfen und sagen, was ich hier falsch machen?
danke!

Hi @it12 ,

es gibt zwei Wege die API zu benutzen:

  1. Mit einem fixen Bearer Token den du im Ui in awork generieren kannst (nicht das Client Secret). Siehe hier: Authentication — awork API | Documentation
  2. Über den Oauth Flow für deinen User. Dafür musst du den Oauth Flow implementieren (deutlich komplizierter).

Reicht für deinen Fall nicht ein fixer token?

Grüße

Nils

Hallo Nils, danke für die fixe Antwort!
ich würde gerne Weg 1 nutzen, hab aber keine Idee, wie ich mit dem Client-Secret einen fixen Token machen kann. in der Doku steht:

Using the API Key

To authenticate with and receive resources from the API, add the API Key to the Authorization header in the following form: Authorization: Bearer {api_key}

aber welche API muss ich aufrufen, um mit dem api_key das Token zu bekommen?

Hi @it12, the developer docs have a step by step instructions with screenshots on how to get a static token: Authentication — awork API | Documentation

You then use this token in every request. You don’t need an client id or client secret in this case at all.

Hi @Sebastian, thank you for your response. Unfortunatelly, i am not smart enough to find out how it works. So it would be great if you could help me. Obviously, linking 2 times to the same documenation does not really help me!
maybe a screenshot or the headline of the relevant part in the documentation would help?! If I navigate to Settings-> Integration in the UI, then I am only able to create an API-Client with a name/id/secret/redirct-uri. I can not find a button which states: „click here to create a static token“.
Thank you!

I am pasting a screenshot of the developer docs here where it shows the exact buttons to click. I hope this helps.

Thank you @Sebastian,
this brings me back to the beginning. If i use this API-Key (which starts with ‚qO‘) for the request (e.g. B. https://api.awork.com/api/v1/projects -H „Authorization: Bearer %api-key%“) then i also get a 401 (like SH1 did). Therefore, I assume that I have to use the api-key to generate such a token.

The API keys start with ey so you’re most likely not using the API key.

I created a quick recording to show how to get one.

I’m embarrassed! I’m sorry that I wasn’t able to read the documentary properly! Sorry and thank you!

1 „Gefällt mir“

You’re welcome!