# REST API Bonita 6.x - Auth - Error while logging in on the engine API

**URL:** https://community.ofelia.com/t/rest-api-bonita-6-x-auth-error-while-logging-in-on-the-engine-api/4116
**Category:** Q&A
**Created:** [15 January 2014 09:46 UTC](https://community.ofelia.com/t/rest-api-bonita-6-x-auth-error-while-logging-in-on-the-engine-api/4116 "2014-01-15T09:46:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![box](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@box](https://community.ofelia.com/u/box)
#### Post date: [15 January 2014 09:46 UTC](https://community.ofelia.com/t/rest-api-bonita-6-x-auth-error-while-logging-in-on-the-engine-api/4116/1 "2014-01-15T09:46:11Z")

</div>

**Server Enviroment**

- CentOS 6.4 (Final);

- Java(TM) SE Runtime Environment (build 1.7.0\_45-b18);

- BonitaBPMCommunity-6.2.0-Tomcat-6.0.37 (bundle);

- Postgresql 9.2.6;

**REST client**

package com.mkyong.rest.client;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.MalformedURLException;

import org.apache.http.HttpResponse;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.entity.StringEntity;

import org.apache.http.impl.client.DefaultHttpClient;

public class ApacheHttpClientPost {

// http://localhost:8080/RESTfulExample/json/product/post

&nbsp;&nbsp; &nbsp;public static void main(String[] args) {

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;DefaultHttpClient httpClient = new DefaultHttpClient();

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//HttpPost postRequest = new HttpPost(

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"http://localhost:8080/RESTfulExample/json/product/post");

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;HttpPost postRequest = new HttpPost("http://\<publicIPserver\>:\<port\>/bonita/loginservice");

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//StringEntity input = new StringEntity(

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"{\"qty\":100,\"name\":\"iPad 4\"}");

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;StringEntity input = new StringEntity("{\"username\":\"myusername\",\"password\":\"mypassword\",\"redirect\":\"false\"}");

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;input.setContentType("application/json");

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;postRequest.setEntity(input);

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;HttpResponse response = httpClient.execute(postRequest);

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (response.getStatusLine().getStatusCode() != 200) {

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throw new RuntimeException("Failed : HTTP error code : "

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;+ response.getStatusLine().getStatusCode());

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BufferedReader br = new BufferedReader(new InputStreamReader(

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;(response.getEntity().getContent())));

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String output;

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("Output from Server .... \n");

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;while ((output = br.readLine()) != null) {

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println(output);

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;httpClient.getConnectionManager().shutdown();

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (MalformedURLException e) {

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;e.printStackTrace();

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (IOException e) {

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;e.printStackTrace();

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}

&nbsp;&nbsp; &nbsp;}

**Output server**

Output from Server ....&nbsp;

\<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"\>

\<html\>

\<head\>

\<meta http-equiv="content-type" content="text/html; charset=UTF-8" /\>

\<title\>Bonita BPM Portal\</title\>

\<link rel="icon" type="image/png" href="images/favicon2.ico" /\>

\<!-- Load LESS CSS --\>

\<script type="text/javascript" src="portal/scripts/includes/array.prototype.js"\>\</script\>

\<link rel="stylesheet" type="text/css" href="portal/themeResource?theme=portal&location=bonita.css"/\>

\<script type="text/javascript" src="portal/scripts/jquery/jquery-1.6.4.js"\>\</script\>

\<script\>

&nbsp;&nbsp; &nbsp;/\* Add url hash to form action url \*/

&nbsp;&nbsp; &nbsp;$(document).ready(function() {

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;var form = $('#LoginForm');

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;form.attr('action', form.attr('action') + encodeURI(window.location.hash));

&nbsp;&nbsp; &nbsp;});

\</script\>

\</head\>

\<body id="LoginPage"\>

&nbsp;&nbsp; &nbsp;\<div id="LoginHeader"\>\<h1\>\<span\>Welcome to\</span\> Bonita BPM Portal\</h1\>\</div\>

&nbsp;&nbsp; &nbsp;\<div id="floater"\>\</div\>

&nbsp;&nbsp; &nbsp;\<div id="LoginFormContainer" \>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div id="logo"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<img src="portal/themeResource?theme=portal&location=skin/images/login-logo.png"/\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="body"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<form id="LoginForm" action="loginservice?" method="post"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="header"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<h2\>Login form\</h2\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<p class="error"\> **Unable to log in. Please check your username and password.** \</p\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="formentries"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="formentry" title="Enter your login (username)"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="label"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<label for="username"\>User\</label\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="input"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<input title="Login" id="username" name="username" value="" placeholder="User" type="text" tabindex="1" maxlength="50"&nbsp; /\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="formentry" title="Enter your password"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="label"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<label for="password"\>Password\</label\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="input"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<input title="Password" id="password" name="password" type="password" tabindex="2" maxlength="50" placeholder="Password"&nbsp; /\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<input name="\_l" type="hidden" value="en\_US" /\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<div class="formactions"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\<input type="submit" value="Login"&nbsp; /\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</form\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;\</div\>

&nbsp;&nbsp; &nbsp;\<div class="footer" id="footer"\>

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Bonitasoft ?? 2013 All rights reserved.

&nbsp;&nbsp; &nbsp;\</div\>

\</body\>

\</html\>

**bonita.2014-01-15.log**

gen 15, 2014 9:48:48 AM org.bonitasoft.console.common.server.login.datastore.LoginDatastore login  
 Grave: Error while logging in on the engine API.

---

Of course user myuser : mypassword is in db of the engine.

What's wrong?

Thanks in advance

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![grigoriadis](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@grigoriadis](https://community.ofelia.com/u/grigoriadis)
#### Post date: [12 December 2014 10:23 UTC](https://community.ofelia.com/t/rest-api-bonita-6-x-auth-error-while-logging-in-on-the-engine-api/4116/2 "2014-12-12T10:23:20Z")

</div>

look here. [http://community.ofelia.com//answers/rest-api-bonita-6x-authentication-401-unauthorized#comment-37864](http://community.ofelia.com//answers/rest-api-bonita-6x-authentication-401-unauthorized#comment-37864)

---

<div class="post-metadata">

### Author: ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)
#### Post date: [20 January 2014 09:29 UTC](https://community.ofelia.com/t/rest-api-bonita-6-x-auth-error-while-logging-in-on-the-engine-api/4116/3 "2014-01-20T09:29:29Z")

</div>

did you use the technical account (install / install) to create the first admin users ?

---

<div class="post-metadata">

### Author: ![box](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@box](https://community.ofelia.com/u/box)
#### Post date: [20 January 2014 09:54 UTC](https://community.ofelia.com/t/rest-api-bonita-6-x-auth-error-while-logging-in-on-the-engine-api/4116/4 "2014-01-20T09:54:35Z")

</div>

Yes I did

---

<div class="post-metadata">

### Author: ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)
#### Post date: [20 January 2014 10:08 UTC](https://community.ofelia.com/t/rest-api-bonita-6-x-auth-error-while-logging-in-on-the-engine-api/4116/5 "2014-01-20T10:08:27Z")

</div>

If I understand, you try to log in through the API, via a third party application?&nbsp;can you log in with Bonita BPM Portal, to check if the problem is with your script, or with Bonita.

---

<div class="post-metadata">

### Author: ![box](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@box](https://community.ofelia.com/u/box)
#### Post date: [20 January 2014 11:00 UTC](https://community.ofelia.com/t/rest-api-bonita-6-x-auth-error-while-logging-in-on-the-engine-api/4116/6 "2014-01-20T11:00:08Z")

</div>

Unfortunately,&nbsp;I can login to the portal with the same credentials. The problem is my script.&nbsp;If I understand the portal is "like" third part application (because use REST API).&nbsp;Do you know where I can find the code?
