Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Calling Iguana X APIs locally:

If you are calling Iguana’s APIs from a Translator within the same Iguana instance, you can use the iguana.call() function to call the API. This allows you to quickly call the desired API without having to authenticate.

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

Calling Iguana X APIs externally:

If you are calling Iguana’s APIs from outside of Iguana or from a different Iguana instance, you will need to use the net.http.* and authenticate before making API requests. This involves:

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

    • Note your username and password login details must be serialized in JSON format.

  2. Include the retrieved session cookie in the header of each subsequent Iguana API requests.

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

Try this out in the Translator with the following code:

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 api 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
   
   -- logout
   logout(cookie)
end
  • No labels