---
title: LoginWithUsernamePassword
summary: Login using username/password, this can be used for testing.
order: 1000
section: Auth - Authentication
method: POST
operation: LoginWithUsernamePassword
auth: false
scopes: []
schemas: [LoginWithUsernamePasswordRequest, AuthResponseFormat, AuthResult, ErrorResponse]
link-terms: true
path: /auth/LoginWithUsernamePassword
---

# LoginWithUsernamePassword

<div class="api-path"><div class="api-path-method"><span class="pill pill-method">POST</span></div><pre><span class="host" data-api-host></span>/openapi/auth/LoginWithUsernamePassword</pre></div>

For production use we advise LoginWithApiToken

## Try it {#try-it}

Edit the request and send it; it runs against this instance, and the examples follow the form.

<div class="try-it" id="try-loginwithusernamepassword" data-operation="LoginWithUsernamePassword" data-method="POST" data-path="/auth/LoginWithUsernamePassword" data-content-type="application/json" data-auth="none" data-schema="LoginWithUsernamePasswordRequest" data-tag="Auth" data-required="username,password"><div class="try-it-bar"><div class="tabs" role="tablist"><button type="button" role="tab" class="tab active" data-try-tab="request">Request</button><button type="button" role="tab" class="tab" data-try-tab="headers">Headers</button><button type="button" role="tab" class="tab" data-try-tab="snippet" data-try-snippet-tab>curl</button></div><span class="try-it-cred" data-try-cred></span><div class="try-it-actions"><button type="button" class="btn" data-try-reset>Reset</button><button type="button" class="btn btn-primary" data-try-send>Send</button></div></div><div class="try-it-body"><div class="try-it-request"><div class="try-it-pane active" data-try-pane="request"><div class="try-it-kv"><div class="try-it-key">Authorization</div><div class="try-it-val"><span class="try-it-none">none, this call is available before logging in</span></div><div class="try-it-key">Content-Type</div><div class="try-it-val"><code>application/json</code></div></div><div class="try-it-caption"><span>Body</span><span class="try-it-valid" data-try-valid></span></div><div class="try-it-editor lesson-code"><div class="lesson-gutter" data-try-gutter>1
2
3
4
5</div><textarea class="lesson-input try-it-textarea" data-try-body spellcheck="false" aria-label="Request body" rows="5">{
  &quot;username&quot;: &quot;&quot;,
  &quot;password&quot;: &quot;&quot;,
  &quot;response_format&quot;: &quot;auth&quot;
}</textarea></div></div><div class="try-it-pane" data-try-pane="headers"><pre class="code"><code data-try-headers>Content-Type: application/json
Accept: application/json</code></pre></div><div class="try-it-pane" data-try-pane="snippet"><pre class="code"><code class="language-shell" data-try-snippet>curl -X POST &quot;$BIMWORKS_URL/openapi/auth/LoginWithUsernamePassword&quot; \
  -H &quot;Content-Type: application/json&quot; \
  -d '{
  &quot;username&quot;: &quot;&quot;,
  &quot;password&quot;: &quot;&quot;,
  &quot;response_format&quot;: &quot;auth&quot;
}'</code></pre></div></div><div class="try-it-response"><div class="try-it-status"><span class="pill-status" data-try-status hidden></span><span class="try-it-meta" data-try-meta>Send to see the response</span><span class="try-it-spacer"></span><div class="tabs try-it-rtabs" data-try-rtabs hidden><button type="button" class="tab active" data-try-rtab="body">Body</button><button type="button" class="tab" data-try-rtab="headers">Headers</button></div><a class="try-it-download" data-try-download hidden download>Download</a></div><pre class="code try-it-out" data-try-out></pre></div></div><script type="application/json" data-try-sdk>{"java":{"program":"import nl.bimbase.bimworks.sdk.api.AuthApi;\nimport nl.bimbase.bimworks.sdk.client.ApiClient;\nimport nl.bimbase.bimworks.sdk.model.LoginWithUsernamePasswordRequest;\n\npublic class Example {\n    public static void main(String[] args) throws Exception {\n        // 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\n        ApiClient client = new ApiClient();\n        client.updateBaseUri(\"BIM_WORKS_ADDRESS/openapi\");\n\n        // 2. The request\n        LoginWithUsernamePasswordRequest request = client.getObjectMapper().readValue(\"\"\"\n                {\n                  \"username\": \"\",\n                  \"password\": \"\",\n                  \"response_format\": \"auth\"\n                }\n                \"\"\", LoginWithUsernamePasswordRequest.class);\n\n        // 3. The call\n        var result = new AuthApi(client).loginWithUsernamePassword(request);\n\n        // 4. The result\n        System.out.println(client.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(result));\n    }\n}","template":"import nl.bimbase.bimworks.sdk.api.AuthApi;\nimport nl.bimbase.bimworks.sdk.client.ApiClient;\nimport nl.bimbase.bimworks.sdk.model.LoginWithUsernamePasswordRequest;\n\npublic class Example {\n    public static void main(String[] args) throws Exception {\n        // 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\n        ApiClient client = new ApiClient();\n        client.updateBaseUri(\"BIM_WORKS_ADDRESS/openapi\");\n\n        // 2. The request\n        LoginWithUsernamePasswordRequest request = client.getObjectMapper().readValue(\"\"\"\n                @@BODY@@\n                \"\"\", LoginWithUsernamePasswordRequest.class);\n\n        // 3. The call\n        var result = new AuthApi(client).loginWithUsernamePassword(request);\n\n        // 4. The result\n        System.out.println(client.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(result));\n    }\n}","escape":"backslash"},"csharp":{"program":"using System.Text.Json;\nusing BIMworks.Sdk.Api;\nusing BIMworks.Sdk.Client;\nusing BIMworks.Sdk.Extensions;\nusing BIMworks.Sdk.Model;\nusing Microsoft.Extensions.DependencyInjection;\n\n// 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\nIServiceProvider Connect(string bearer)\n{\n    var services = new ServiceCollection();\n    services.AddApi(options =>\n    {\n        options.AddTokens(new BearerToken(bearer));\n        options.AddApiHttpClients(http =>\n        {\n            http.BaseAddress = new Uri(\"BIM_WORKS_ADDRESS\" + \"/openapi\");\n            http.Timeout = Timeout.InfiniteTimeSpan;\n        });\n    });\n    return services.BuildServiceProvider();\n}\nvar client = Connect(\"\");\nvar json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;\n\n// 2. The request\nvar request = JsonSerializer.Deserialize<LoginWithUsernamePasswordRequest>(\"\"\"\n    {\n      \"username\": \"\",\n      \"password\": \"\",\n      \"response_format\": \"auth\"\n    }\n    \"\"\", json);\n\n// 3. The call\nvar response = await client.GetRequiredService<IAuthApi>().LoginWithUsernamePasswordAsync(request);\n\n// 4. The result\nvar result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);\nConsole.WriteLine(JsonSerializer.Serialize(result.Auth, json));","template":"using System.Text.Json;\nusing BIMworks.Sdk.Api;\nusing BIMworks.Sdk.Client;\nusing BIMworks.Sdk.Extensions;\nusing BIMworks.Sdk.Model;\nusing Microsoft.Extensions.DependencyInjection;\n\n// 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\nIServiceProvider Connect(string bearer)\n{\n    var services = new ServiceCollection();\n    services.AddApi(options =>\n    {\n        options.AddTokens(new BearerToken(bearer));\n        options.AddApiHttpClients(http =>\n        {\n            http.BaseAddress = new Uri(\"BIM_WORKS_ADDRESS\" + \"/openapi\");\n            http.Timeout = Timeout.InfiniteTimeSpan;\n        });\n    });\n    return services.BuildServiceProvider();\n}\nvar client = Connect(\"\");\nvar json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;\n\n// 2. The request\nvar request = JsonSerializer.Deserialize<LoginWithUsernamePasswordRequest>(\"\"\"\n    @@BODY@@\n    \"\"\", json);\n\n// 3. The call\nvar response = await client.GetRequiredService<IAuthApi>().LoginWithUsernamePasswordAsync(request);\n\n// 4. The result\nvar result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);\nConsole.WriteLine(JsonSerializer.Serialize(result.Auth, json));","escape":"none"},"typescript":{"program":"import { AuthApi, AuthResultToJSON, Configuration, LoginWithUsernamePasswordRequestFromJSON } from \"@bimworks/sdk\";\n\n// 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\nconst client = new Configuration({ basePath: \"BIM_WORKS_ADDRESS/openapi\" });\n\n// 2. The request\nconst request = LoginWithUsernamePasswordRequestFromJSON({\n  \"username\": \"\",\n  \"password\": \"\",\n  \"response_format\": \"auth\"\n});\n\n// 3. The call\nconst result = await new AuthApi(client).loginWithUsernamePassword({ loginWithUsernamePasswordRequest: request });\n\n// 4. The result\nconsole.log(JSON.stringify(AuthResultToJSON(result), null, 2));","template":"import { AuthApi, AuthResultToJSON, Configuration, LoginWithUsernamePasswordRequestFromJSON } from \"@bimworks/sdk\";\n\n// 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\nconst client = new Configuration({ basePath: \"BIM_WORKS_ADDRESS/openapi\" });\n\n// 2. The request\nconst request = LoginWithUsernamePasswordRequestFromJSON(@@BODY@@);\n\n// 3. The call\nconst result = await new AuthApi(client).loginWithUsernamePassword({ loginWithUsernamePasswordRequest: request });\n\n// 4. The result\nconsole.log(JSON.stringify(AuthResultToJSON(result), null, 2));","escape":"none"},"php":{"program":"<?php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse BIMworks\\Api\\AuthApi;\nuse BIMworks\\Configuration;\nuse BIMworks\\Model\\LoginWithUsernamePasswordRequest;\nuse BIMworks\\ObjectSerializer;\n\n// 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\n$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');\n\n// 2. The request\n$request = ObjectSerializer::deserialize(<<<'JSON'\n{\n  \"username\": \"\",\n  \"password\": \"\",\n  \"response_format\": \"auth\"\n}\nJSON, LoginWithUsernamePasswordRequest::class);\n\n// 3. The call\n$result = (new AuthApi(config: $client))->loginWithUsernamePassword($request);\n\n// 4. The result\necho json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;","template":"<?php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse BIMworks\\Api\\AuthApi;\nuse BIMworks\\Configuration;\nuse BIMworks\\Model\\LoginWithUsernamePasswordRequest;\nuse BIMworks\\ObjectSerializer;\n\n// 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\n$client = (new Configuration())->setHost('BIM_WORKS_ADDRESS/openapi');\n\n// 2. The request\n$request = ObjectSerializer::deserialize(<<<'JSON'\n@@BODY@@\nJSON, LoginWithUsernamePasswordRequest::class);\n\n// 3. The call\n$result = (new AuthApi(config: $client))->loginWithUsernamePassword($request);\n\n// 4. The result\necho json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;","escape":"none"},"python":{"program":"import json\n\nimport bimworks\n\n# 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\nclient = bimworks.ApiClient(bimworks.Configuration(host=\"BIM_WORKS_ADDRESS/openapi\"))\n\n# 2. The request\nrequest = bimworks.LoginWithUsernamePasswordRequest.from_json(r\"\"\"\n{\n  \"username\": \"\",\n  \"password\": \"\",\n  \"response_format\": \"auth\"\n}\n\"\"\")\n\n# 3. The call\nresult = bimworks.AuthApi(client).login_with_username_password(request)\n\n# 4. The result\nprint(json.dumps(client.sanitize_for_serialization(result), indent=2))","template":"import json\n\nimport bimworks\n\n# 1. Connect to BIM.works (LoginWithUsernamePassword needs no login)\nclient = bimworks.ApiClient(bimworks.Configuration(host=\"BIM_WORKS_ADDRESS/openapi\"))\n\n# 2. The request\nrequest = bimworks.LoginWithUsernamePasswordRequest.from_json(r\"\"\"\n@@BODY@@\n\"\"\")\n\n# 3. The call\nresult = bimworks.AuthApi(client).login_with_username_password(request)\n\n# 4. The result\nprint(json.dumps(client.sanitize_for_serialization(result), indent=2))","escape":"none"}}</script></div>

## Examples {#examples}

<div class="examples" data-examples="try-loginwithusernamepassword"><div class="examples-bar"><span class="examples-lang" data-ex-lang>curl</span><span class="examples-note" data-ex-note>shell</span><button type="button" class="link-button" data-ex-change>Change language</button><button type="button" class="code-copy" data-ex-copy title="Copy">Copy</button></div><pre class="code"><code class="language-shell" data-ex-code>curl -X POST &quot;$BIMWORKS_URL/openapi/auth/LoginWithUsernamePassword&quot; \
  -H &quot;Content-Type: application/json&quot; \
  -d '{
  &quot;username&quot;: &quot;&quot;,
  &quot;password&quot;: &quot;&quot;,
  &quot;response_format&quot;: &quot;auth&quot;
}'</code></pre></div>

The examples are complete programs in the [[page:reference/sdk#openapi|OpenAPI SDKs]], all in the same four steps. The method in each SDK's reference: [[page:reference/sdk/java/authapi#loginwithusernamepassword|Java]] · [[page:reference/sdk/dotnet/authapi#loginwithusernamepassword|.NET]] · [[page:reference/sdk/typescript/authapi#loginwithusernamepassword|TypeScript]] · [[page:reference/sdk/php/authapi#loginwithusernamepassword|PHP]] · [[page:reference/sdk/python/authapi#loginwithusernamepassword|Python]].

## Request body {#request-body}

[[page:api/schemas#LoginWithUsernamePasswordRequest|LoginWithUsernamePasswordRequest]] · `application/json`

<table class="dense">
<thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr id="field-username"><td><code>username</code></td><td><code>string</code><span class="req">required</span></td><td></td></tr>
<tr id="field-password"><td><code>password</code></td><td><code>string</code><span class="req">required</span></td><td></td></tr>
<tr id="field-response-format"><td><code>response_format</code></td><td>[[page:api/schemas#AuthResponseFormat|AuthResponseFormat]]<span class="opt">optional</span></td><td>The preferred response format for calls that return authentication material: the full Auth object (&quot;auth&quot;, the default), or only its Base64 encoded JSON serialization (&quot;base64&quot;), which is directly usable as a bearer token</td></tr>
</tbody>
</table>

## Responses {#responses}

<table class="dense">
<thead><tr><th>Status</th><th>Schema</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code class="status-2xx">200</code></td><td>[[page:api/schemas#AuthResult|AuthResult]]</td><td>The login attempt succeeded. The token is also returned in the <code>Authorization</code> response header.</td></tr>
<tr><td><code class="status-4xx">400</code></td><td>[[page:api/schemas#ErrorResponse|ErrorResponse]]</td><td>Invalid input: a missing or invalid argument, an invalid query/identifier/path, a state conflict caused by the request (for example a Node name that already exists), or an uploaded file that was rejected because it cannot be read (<code>type</code> for example <code>INVALID_INPUT_FILE</code>, <code>NO_CONVERTIBLE_CONTENT</code> or one of the <code>StepParserErrorCode</code> codes; uploading the same file again fails the same way)</td></tr>
<tr><td><code class="status-4xx">401</code></td><td>[[page:api/schemas#ErrorResponse|ErrorResponse]]</td><td>Authentication failed: the bearer token is missing, malformed, expired or otherwise invalid, or the provided login credentials are incorrect</td></tr>
<tr><td><code class="status-4xx">429</code></td><td>[[page:api/schemas#ErrorResponse|ErrorResponse]]</td><td>Too many requests from this client in a short time, on an installation that limits the request rate. Wait the number of seconds in <code>Retry-After</code> before trying again</td></tr>
<tr><td><code class="status-5xx">500</code></td><td>[[page:api/schemas#ErrorResponse|ErrorResponse]]</td><td>An unexpected server-side error (database, routing, IO, unknown)</td></tr>
<tr><td><code class="status-5xx">503</code></td><td>[[page:api/schemas#ErrorResponse|ErrorResponse]]</td><td>BIM.works is temporarily unavailable: it is restarting, stopped, or down for scheduled maintenance (<code>type</code> <code>SERVICE_UNAVAILABLE</code> or <code>MAINTENANCE</code>). Wait the number of seconds in <code>Retry-After</code> before trying again</td></tr>
<tr><td><code class="status-5xx">504</code></td><td>[[page:api/schemas#ErrorResponse|ErrorResponse]]</td><td>BIM.works did not respond in time (<code>type</code> <code>REQUEST_TIMED_OUT</code>). The request may still be completed: check its result before trying again</td></tr>
</tbody>
</table>
