diff --git a/public_html/api/index.php b/public_html/api/index.php
index 3e45c62185cd5115393899ec80ba6d3271fa2992..7f2b6599a7143bb4203b2747db1750ebe490be45 100644
--- a/public_html/api/index.php
+++ b/public_html/api/index.php
@@ -170,14 +170,18 @@
 
                     $sPrjId     = isset($aUriSplit[2]) ? $aUriSplit[2] : false;
                     $sPrjAction = isset($aUriSplit[3]) ? $aUriSplit[3] : false;
+                    $sParam4    = isset($aUriSplit[4]) ? $aUriSplit[4] : false;
+                    $sMethod    = $_SERVER['REQUEST_METHOD'];
                     _wd('$sPrjId = '.$sPrjId);
                     _wd('$sPrjAction = '.$sPrjAction);
                     
+                    $oCLog = new logger();
                     // try to init the given project
                     try{
                         ob_start();
                         $oProject=new project($sPrjId);
-                        $oProject->setProjectById($sPrjId);
+                        
+                        // $oProject->setProjectById($sPrjId);
                         ob_end_clean();
                             
                     } catch (Exception $exc) {
@@ -193,14 +197,41 @@
 
                     // check authorization 
                     _checkAuth($sProjectSecret);
-                    
-                    echo "OK: request was authorized successfully.\n";
+
+                    // echo "OK: request was authorized successfully.\n";
+
+                    $oProject->oUser->setUser('api');
+
                     switch($sPrjAction){
                         case "build":
-                            echo "build ...";
+                            if ($sParam4){
+                                $aResult=$oProject->setBranchname("origin/".$sParam4);
+                                // echo "branch was set.\n";
+
+                            }
+                            $sBranchname=$oProject->getBranchname();
+                            $aRepodata = $oProject->getRemoteBranches(true);
+                            if(!isset($aRepodata[$sBranchname])){
+                                _quit('ERROR: branch not found '.$sBranchname);
+                            }
+                            
+                            
+                            // echo "branch is set to ".$oProject->getBranchname()."\n";
+                            if ($sMethod==='GET'){
+                                $sNext=$oProject->getNextPhase();
+                                _done(array(
+                                    'branch'=>$sBranchname,
+                                    'phase'=>$sNext,
+                                    'repo'=>$aRepodata[$sBranchname]
+                                ));
+                            }
+                            if ($sMethod==='POST'){
+                                echo "starting build() ...";
+                                flush();
+                                die("ABORT");
+                                echo $oProject->build();
+                            }
 
-                            $oCLog = new logger();
-                            echo $oProject->build();
                             break;;
                         default:
                             _quit('ERROR: Wrong action ['.$sApiItem.'].');
diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php
index 687ba48fb328dedcb0f3e92994f84cfe396cffcf..dd56aceb4dae443f73a2400b2a40150453bc690e 100644
--- a/public_html/deployment/classes/project.class.php
+++ b/public_html/deployment/classes/project.class.php
@@ -1353,8 +1353,8 @@ class project extends base {
         if ($this->_sProcessTempOut && file_exists($this->_sProcessTempOut)) {
             unlink($this->_sProcessTempOut);
         }
-        $sNewTempfile = sys_get_temp_dir() . "/" . basename($sNewTempfile);
-        $this->_sProcessTempOut = $sNewTempfile;
+        // $sNewTempfile = sys_get_temp_dir() . "/" . basename($sNewTempfile);
+        $this->_sProcessTempOut = $sNewTempfile ? sys_get_temp_dir() . "/" . basename($sNewTempfile) : false;
         return $this->_sProcessTempOut;
     }
 
@@ -1452,7 +1452,7 @@ class project extends base {
         }
         return $this->_sBranchname;
     }
-
+        
     // ----------------------------------------------------------------------
     // ACTIONS
     // ----------------------------------------------------------------------
diff --git a/public_html/deployment/classes/user.class.php b/public_html/deployment/classes/user.class.php
index 13dc9d68a565bedf8a658d18f99f67b3b7e10fdc..756b6ae9efa712f02f0fb60c13297a8d23fffe00 100644
--- a/public_html/deployment/classes/user.class.php
+++ b/public_html/deployment/classes/user.class.php
@@ -162,7 +162,7 @@ class user {
                 
                 // set a session - it must correspondent with _autoDetectUser()
                 $_SESSION["PHP_AUTH_USER"]=$sUser;
-                $this->setUser();
+                $this->setUser('');
                 return true;
             }
         }
@@ -182,9 +182,13 @@ class user {
     /**
      * set an authenticated user and get its roles
      */
-    public function setUser(){
-        $this->_sUsername=$this->_autoDetectUser();
-        
+    public function setUser($sUser=false){
+        if($sUser!==false){
+            $this->_sUsername=$sUser;
+            $_SESSION["PHP_AUTH_USER"]=$sUser;
+        } else {
+            $this->_sUsername=$this->_autoDetectUser();
+        }
         $this->_getUserGroups();
         $this->_getUserPermission();
     }
diff --git a/public_html/deployment/classes/vcs.git.class.php b/public_html/deployment/classes/vcs.git.class.php
index c994e34251c07740041a30b773ed24b142237d53..d361b364e4071507b2cec9b65ac115b92a399c76 100644
--- a/public_html/deployment/classes/vcs.git.class.php
+++ b/public_html/deployment/classes/vcs.git.class.php
@@ -357,6 +357,9 @@ class vcs implements iVcs {
         } else {
             $a = $this->getRevision(false);
         }
+        if(!isset($a['branch'])){
+            return false;
+        }
         // merge with cached info ... to add type and label
         if(isset($this->_aRemoteBranches[$a['branch']])){
             $this->_aRemoteBranches[$a['branch']]=array_merge($this->_aRemoteBranches[$a['branch']], $a);
diff --git a/shellscripts/api-client.sh b/shellscripts/api-client.sh
index 4568b21aafe6282984a7379e5ce0c2493f06497e..0c1700c3f1d4cccc6bc35778d8adf2b35a391bf2 100644
--- a/shellscripts/api-client.sh
+++ b/shellscripts/api-client.sh
@@ -18,12 +18,44 @@ myProject=ci-webgui
 secret="cOiScVAElvcJKmJ1eGrKXZvv6ZROlSgZ9VpSVFK1uxZI8J5ITXuZZb8jIYobuoAB"
 
 myAction=build
+myBranch=
+# myBranch=helloworld
+# myBranch="task3869-api"
 apiHost="http://dev.ci.iml.unibe.ch:8002"
 apiBaseUrl="/api/v1"
 apiMethod=GET
 
 line="----------------------------------------------------------------------"
 
+# ----------------------------------------------------------------------
+# FUNCTIONS
+# ----------------------------------------------------------------------
+
+function showhelp(){
+echo "
+
+SYNTAX
+   projects         show projects
+   list             list branches
+   info  [branch]   show infos about what happens on build
+   build [branch]   build
+
+PARAMETERS
+  branch  name of branch (optional), i.e. feature-123 (without "origin/")
+"
+}
+
+
+# ----------------------------------------------------------------------
+# MAIN
+# ----------------------------------------------------------------------
+
+if  [ $# -lt 1 ]; then
+    showhelp
+    exit 1
+fi
+
+
 # ----------------------------------------------------------------------
 # REQ #1 - list project ids
 # ----------------------------------------------------------------------
@@ -47,6 +79,7 @@ echo
 
 # --- build url
 apiRequest="${apiBaseUrl}/project/${myProject}/${myAction}"
+test -z $myBranch || apiRequest="${apiRequest}/${myBranch}"
 
 # --- date in http format
 LANG=en_EN