Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleSTEP 1: Call the '/session/login' API to login, authenticate, and retrieve the session cookie.

Call the '/session/login' API passing your Iguana login credentials to authenticate and get a session cookie from the response header.

Note: the username and password login details must be serialized in JSON format.

Screen Shot 2024-02-02 at 3.58.38 PM.png
Expand
titleSTEP 2: Use the session cookie to authenticate subsequent Iguana API requests

In this example we are calling the '/component/list' API to get a list of all components on the Iguana instance.

To call the API, the retrieved session cookie is included in the header of Iguana API requests to authenticate. View the request’s response using the Annotations!

Screen Shot 2024-02-02 at 4.00.39 PM.png
Expand
titleSTEP 3: Call the '/session/logout' API to logout using the session cookie.

Call the '/session/logout' API to passing pass the session cookie to logout when finished.

Screen Shot 2024-02-02 at 4.04.55 PM.png

...

Code Block
languagelua
local function login(Credentials)
   -- url-encoded POST parameters
  local _, _, header = net.http.post{
      url = '127.0.0.1:7654/session/login',
      parameters = Credentials,
      live = true
   }
   -- return only the set cookie from header
   return header["Set-Cookie"]:split(';')[1]
end

local function logout(Cookie)
   net.http.post{
      url = '127.0.0.1:7654/session/logout',
      headers = {['Cookie'] = Cookie},
      live = true
   }
end

function main()
   local credentials = {
      username='admin',
      password='password'
   }
   -- Log in and get a session cookie
   local cookie = login(credentials)

   -- Call an Iguana X apiAPI using the cookie
   local componentList = net.http.post{
      url = '127.0.0.1:7654/component/list',
      headers = {['Cookie'] = cookie},
      live = true
   }
   local componentList = json.parse{data=componentList}

   -- Make more API calls with the cookie
   
   -- Log logoutout
   logout(cookie)
end