How to Reuse DAPSESSION via cURL

Goal

You observe that the access from automation via REST API fails with HTTP Error 401 when too many requests are started in a short period of time. To work around the issue you are describing, you can reuse the DAPSESSION cookie returned by the first successful RESTful call.

 

Learn

Follow the short example that creates a folder `Test` within the file browser (which is usually not necessary). You will most likely only need the DAPSESSIONID used later on.

Step-by-step guide

  1. Open a session and gather session ID and CSRF token. You can do this in example by

    Gather ID and token
    curl -u admin:admin -H 'Connection: keep-alive' -D - http://localhost:8080/dev | grep "DAPSESSIONID=[a-z0-9]*\|DatameerCSRF.token = '"
    curl -u admin:admin -H 'Connection: keep-alive' -D - http://localhost:8080/dev | grep -oe "DAPSESSIONID=[a-z0-9]*\|\(DatameerCSRF.token = '\)[^']*[']" 
  2. Reuse the session ID and CSRF token.

    The example shows how to create an folder called Test under the parent folder for the user admin

    Access via cookie
    curl 'http://localhost:8080/browser/create-folder'
    -H 'Cookie: datameerWelcomeThisSession=false; datameerWelcomeNextStart=true; jstree_open=null; jstree_load=%23null; DAPSESSIONID=<id>; tutorial=false'
    -H 'Origin: http://localhost:8080'
    -H 'Accept-Encoding: gzip, deflate'
    -H 'Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4'
    -H 'X-Datameer-CSRF: <token>‘
    -H 'User-Agent: cURL'
    -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
    -H 'Accept: */*'
    -H 'Referer: http://localhost:8080/browser'
    -H 'X-Requested-With: XMLHttpRequest'
    -H 'Connection: keep-alive'
    --data 'parentFolderId=23&name=Test' --compressed

Usually it will not be necessary to create folders in that way, as if you upload artifacts via REST API it will be done for you automatically.