Open-event-server: Wrong API documentation example for creating a user?

Created on 28 Apr 2018  路  8Comments  路  Source: fossasia/open-event-server

I'm submitting a

  • bug report

Current behavior:
For accessing the API, I need the JWT access token. The docs say "Once you have registered yourself as a user, you can send a request to get the access_token." But to send the request for registering as a user (creating a user), I need the access_token itself. So I'm stuck in a (kind of) deadlock.

As @srv-twry mentioned on Gitter, a JWT token isn't required for creating a user. I made a sample user data payload and posted it without the access token. Now the response says Invalid credentials:

>>> headers
{'Content-Type': 'application/vnd.api+json'}
>>> r = requests.post('http://localhost:5000/auth/session', headers=headers, data=json.dumps(payload))
>>> r.json()
{u'status_code': 401, u'description': u'Invalid credentials', u'error': u'Bad Request'}
>>>

Expected behavior:
Either I should be able to obtain the access token directly or creating a user shouldn't require the token (former seems preferable).

Steps to reproduce:
Try posting a sample user data payload (for creating a user) without passing the access token in the header

I'll try resolving this issue, but I may need help.

has-PR

All 8 comments

@schedutron Please follow the steps mentioned by me and other fellow contributors. It should work now.

PS: Also change the title to something related to wrong API documentation example for creating a user. It wrongly states that it needs a JWT token.

One more thing for auth/session
use {'Content-Type': 'application/json'} instead of {'Content-Type': 'application/vnd.api+json'}

@schedutron you are using the wrong API to create a user.

Need to use
https://open-event-api.herokuapp.com/#users-users-collection-post

@schedutron Have you gone through https://open-event-api.herokuapp.com/#users-users-collection-post as Niranjan wrote.
For creating user goto /v1/users POST
Headers:

Content-Type: application/vnd.api+json
Authorization: JWT <Auth Key>

Auth Key is what you received from /auth/session

Body:

{
  "data": {
    "attributes": {
      "email": "[email protected]",
      "password": "password",
      "avatar_url": "http://example.com/example.png",
      "first-name": "John",
      "last-name": "Doe",
      "details": "example",
      "contact": "example",
      "facebook-url": "http://facebook.com/facebook",
      "twitter-url": "http://twitter.com/twitter",
      "instagram-url": "http://instagram.com/instagram",
      "google-plus-url": "http://plus.google.com/plus.google",
      "original-image-url": "https://cdn.pixabay.com/photo/2013/11/23/16/25/birds-216412_1280.jpg"
    },
    "type": "user"
  }
}

@bhaveshAn Thanks a lot; I have my exams till 7th May, after that I will recheck with these values and let you know the results :)

I finally used the right endpoint for creating the user and it worked! Now when I use the registered email and password and send it to the server via the /auth/session endpoint, I get a different error instead of the session key:

400 Bad Request
The browser (or proxy) sent a request that this server could not understand.

The header I use is {'Content-Type': 'application/vnd.api+json'} and the data I send is:

body = {
      "email": "[email protected]",
      "password": "password"
    }

@schedutron use content type as application/json for the authentication endpoint.

Also, i'm closing this issue as this is not a documentation issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CosmicCoder96 picture CosmicCoder96  路  4Comments

schedutron picture schedutron  路  4Comments

aviaryan picture aviaryan  路  3Comments

iamareebjamal picture iamareebjamal  路  4Comments

shubham-padia picture shubham-padia  路  4Comments