{"metadata":{"image":[],"title":"","description":""},"api":{"url":"/v1/users/login","auth":"required","results":{"codes":[{"status":200,"language":"json","code":"{\n  \"token\": \"ses_oCPDsQsATQyWc0-usr_j3LB5QPAH8B9UD-KJmrd2N4O4tgE1AkZMoX\", \n  \"refresh_after_secs\": 3600\n}","name":""},{"name":"","status":400,"language":"json","code":"{\n  \"error\": {\n    \"type\": \"user_authentication_error\",\n    \"code\": \"unauthorized\",\n    \"message\": \"Wrong login or password.\",\n    \"retry_wait\": 30.0  // Or null\n  }\n}"}]},"settings":"","examples":{"codes":[{"code":"curl https://api.userkit.io/v1/users/login \\\n -u api:{YOUR_APP_SECRET_KEY} \\\n -H \"Content-Type: application/json\" \\\n -d '{\"username\": \"jane.smith:::at:::example.com\", \"password\": \"secretpass\"}'","language":"curl"},{"code":"uk = userkit.UserKit(\"{YOUR_APP_SECRET_KEY}\")\n\n# param 1: email, username or phone.\n# param 2: password.\n# param 3 (OPTIONAL): 2-factor or on-demand\n# \t\t\t\tlogin code.\nsession = uk.users.login_user(\"[email protected]\", \"secretpass\")","language":"python"},{"language":"ruby","code":"def login_user(username, password=nil,\n  \t\t\t\t\t\tlogin_code=nil)\n    url = 'https://api.userkit.io/v1/users/login'\n    resource = RestClient::Resource.new(url, 'api', '{YOUR_APP_SECRET_KEY}')\n    data = {:username => username}\n    if password\n        data['password'] = password\n    end\n    if login_code\n        data['login_code'] = login_code\n    end\n    response = resource.post(\n        data.to_json,\n        :content_type => 'application/json')\n    return JSON.parse(response.body)\nend\n\n# Param 1: email, username or phone.\n# Param 2: password.\n# Param 3 (optional): 2-factor or on-demand\n#\t\t\t\t\tlogin code.\nsession = login_user(\"[email protected]\", \"secretpass\")"},{"code":"package main\n\nimport (\n\t\"fmt\"\n\tuserkit \"github.com/workpail/userkit-go\"\n)\n\nfunc main() {\n  uk := userkit.NewUserKit(\"{YOUR_APP_SECRET_KEY}\")\n  \n  // param 1: username, email or phone\n  // param 2: password\n  // param 3: OPTIONAL 2-factor or on-demand\n  //          login code\n  session, _ := uk.Users.Login(\"[email protected]\", \"secretpass\", \"\")\n\tfmt.Printf(\"%+v\", session)\n  \n  // You can also fetch the user by their session token if you like:\n  user, _ := uk.Users.GetUserBySession(session.Token)\n  fmt.Printf(\"%+v\", user)\n}","language":"go"},{"language":"php","code":"<?php\n\n$uk = new UserKit('<YOUR_APP_SECRET_KEY>');\n\n// param 1: email, username or phone.\n// param 2: password.\n// param 3 (OPTIONAL): 2-factor or on-demand\n// \t\t\t\tlogin code.\n$session = $uk->users->loginUser('[email protected]', 'secretpass');"}]},"method":"post","params":[{"name":"username","type":"string","default":"","desc":"A user identifier, this can be a username, email or phone number","required":false,"in":"body","ref":"","_id":"57efddcc8daa662b00d94fdc"},{"name":"password","type":"string","default":"","desc":"The user's password","required":false,"in":"body","ref":"","_id":"57efddcc8daa662b00d94fdb"},{"name":"login_code","type":"string","default":"","desc":"OPTIONAL, a two-factor or on-demand login code if user's account has this turned on","required":false,"in":"body","ref":"","_id":"57efddcc8daa662b00d94fda"}]},"next":{"description":"","pages":[]},"title":"Login a user","type":"endpoint","slug":"login-a-user","excerpt":"Your users can login with the widget, but you can also login a user directly via the API","body":"","updates":[],"order":3,"isReference":true,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"57efe21845f5d92200b8e2db","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Server API","slug":"tutorials","order":2,"from_sync":false,"reference":true,"_id":"57d4a754899ab90e00105e5d","project":"5589ceae9883a40d00c433f3","__v":0,"createdAt":"2016-09-11T00:37:40.706Z","version":"5589ceae9883a40d00c433f6"},"createdAt":"2016-10-01T16:19:36.357Z","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":true,"is_hidden":false,"is_deprecated":false,"categories":["5589ceaf9883a40d00c433f7","559ab19d2100d117005f1269","57d4a754899ab90e00105e5d","5807813b6d24211900953b99","5819154bf62fee0f00949855","5841d27cae05ac2500ba2680","5846c4ee5d064323007b1774","589e29c72793e937001c15c5","5cf0460e272f2c0014a80d17","5cf047bde14258005d7a374e","5db6fa2c7f86fa004ff2c35b","5e349a6a02520b006458b0ae","5e4c89eafd907100654072f2","5e4d7a1feca7f90018b15b9b","5e4eff0ec3399b005118d83a"],"_id":"5589ceae9883a40d00c433f6","releaseDate":"2015-06-23T21:25:02.865Z","__v":15,"createdAt":"2015-06-23T21:25:02.865Z","project":"5589ceae9883a40d00c433f3"},"user":"5542d87d795b590d001dc7ff","__v":10,"parentDoc":null,"githubsync":"","project":"5589ceae9883a40d00c433f3"}

postLogin a user

Your users can login with the widget, but you can also login a user directly via the API

Definition

{{ api_url }}{{ page_api_url }}

Parameters

Body Params

username:
string
A user identifier, this can be a username, email or phone number
password:
string
The user's password
login_code:
string
OPTIONAL, a two-factor or on-demand login code if user's account has this turned on

Examples


Result Format


User Information

Try It Out

post
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}