Docs‎ > ‎API Creator‎ > ‎Security‎ > ‎Authentication‎ > ‎

Retrieve an API Key

You can retrieve an API key from the command line using curlUse the apikey in an HTTP header named Authorization, in the format:
Authorization: CALiveAPICreator ff908cee433929b06ad8ecc122ff8fa1:1
The :1 added at the end of the API key is required.
  1. Ask the API Server what type of authentication information is required (skip this if you know that a certain authentication provider is in use):
    curl https://eval.espressologic.com/rest/acme/myproject/v1/@login_info
    Substitute the proper URL to your project.
    The following response is expected:
    {
      "links": [
      ],
      "fields": [
        {
          "name": "username",
          "display": "Username",
          "description": "Enter your username",
          "helpURL": null,
          "type": "text",
          "length": 30
        },
        {
          "name": "password",
          "display": "Password",
          "description": "Enter your password",
          "helpURL": null,
          "type": "password",
          "length": 30
        }
      ]
    }

  2. Submit values for the parameters described in the response:
    curl -H "Content-type: application/json" --data-binary "{\"username\": \"jdoe\", \"password\": \"secret\"}" 
    -X POST https://eval.acme.com/rest/acme/myproject/v1/@authentication

    Substitute the proper values for the URL, the username, and the password.
    The following response is expected:
    {
      "apikey": "ff908cee433929b06ad8ecc122ff8fa1",
      "expiration": "2014-07-22T12:00:42.398Z",
      "lastLoginTs": "2014-07-21T02:00:04.000Z",
      "lastLoginIP": "12.34.56.78",
      "email": "jdoe@acme.com"
    }

Example: change the expiration date of an auth token

In this example, we'll change an existing auth token's expiration date from its default of 24 hours. We'll assume that you logged into the Demo project and have gotten an auth token with value MYTOKEN.

Step 1: Log in as admin

First, get an admin auth token:
curl -H "Content-type: application/json" --data-binary "{\"username\": \"admin\", \"password\": \"Password1\"}"  -X POST https://eval.acme.com/rest/abl/admin/v2/@authentication

And retrieve the auth token (aka apikey) from the response:

{
  "apikey": "4b409bfcaac36d47828fb0e10239f9ea",
  "expiration": "2016-06-24T16:04:54.854Z",
  "lastLoginTs": "2016-06-23T15:58:41.000Z",
  "lastLoginIP": "0:0:0:0:0:0:0:1",
  "accountIdent": "1000",
  "email": "None"
}

Step 2: Retrieve your auth token

Now, using your new admin token, retrieve your auth token:
curl -H "Content-type: application/json" -H "Authorization: CALiveAPICreator 4b409bfcaac36d47828fb0e10239f9ea:1" -X GET https://eval.acme.com/rest/abl/admin/v2/apikeys?sysfilter="equal(apikey: 'MYTOKEN')"

You should receive the object:

[
  {
    "ident": 4365,
    "ts": "2016-06-10T01:05:36+00:00",
    "name": "Temp AuthToken for demo [2016-06-10 01:05:36.481]",
    "description": null,
    "apikey": "MYTOKEN",
    "status": "A",
    "expiration": "2016-06-10T18:05:36+00:00",
    "logging": "admini=FINE,buslog=FINE,depend=FINE,generl=FINE,persis=FINE,engine=FINE,resrcs=FINE,securi=FINE,sysdbg=FINE,ulogic=FINE",
    "user_identifier": "demo",
    "data": "username=demo",
    "origin": "A",
    "project_ident": 2004,
    "@metadata": {
      "href": "https://eval.acme.com/rest/abl/admin/v2/admin:apikeys/4365",
      "checksum": "A:3d29f1cf19055d64"
    }
  }
]

Step 3: Update the expiry

Now send back that object with an updated expiry:
curl -H "Content-type: application/json" -H "Authorization: CALiveAPICreator 4b409bfcaac36d47828fb0e10239f9ea:1" -X PUT --data-binary "{\"ident\": 4365, \"expiration\": \"2017-01-01T00:00:00+00:00\", \"@metadata\": {\"checksum\": \"A:3d29f1cf19055d64\"}}" https://eval.acme.com/rest/abl/admin/v2/admin:apikeys/4365

The response will confirm that the expiry has indeed changed:

{
  "statusCode": 200,
  "txsummary": [
    {
      "@metadata": {
        "href": "https://eval.acme.com/rest/abl/admin/v2/admin:apikeys/4365",
        "resource": "admin:apikeys",
        "verb": "UPDATE",
        "checksum": "A:2214eee3029bb548"
      },
      "ident": 4365,
      "ts": "2016-06-23T16:17:21+00:00",
      "name": "Temp AuthToken for demo [2016-06-10 01:05:36.481]",
      "description": null,
      "apikey": "MYTOKEN",
      "status": "A",
      "expiration": "2017-01-01T00:00:00+00:00",
      "logging": "admini=FINE,buslog=FINE,depend=FINE,generl=FINE,persis=FINE,engine=FINE,resrcs=FINE,securi=FINE,sysdbg=FINE,ulogic=FINE",
      "user_identifier": "demo",
      "data": "username=demo",
      "origin": "A",
      "project_ident": 2004
    }
  ]
}