See api-docs Menu

Get a Hook

Use this API to get back the configuration object for a given hook.










Resource URL

https://<subdomain>/api/2/hooks/:id

Header Parameters

Authorization

required

string

Set to bearer <access_token>.

Set <access_token> to the access token you generated using the Generate Token API.

The access token must have been generated using an API credential pair created using the scope required to call this API. This API can be called using any one of the following scopes: Manage All.

In order to use Smart Hooks your API Credentials must be created after 21st October 2020.

Resource Parameters

id

required

string

Set to the id of the Hook that you want to return.

Sample Response

A pre-authentication hook.

{
    "id": "d360aded-6063-4c60-8add-45f32772ff71",
    "type": "pre-authentication",
    "packages": {
      "ua-parser-js": "0.7.21"
    },
    "runtime": "nodejs18.x",
    "context_version": ">= 1.0.0",
    "retries": 0,
    "timeout": 1,
    "disabled": false,
    "status": "ready",
    "env_vars": [
      "MY_API_KEY"
    ],
    "options": {
      "location_enabled": false,
      "risk_enabled": false,
      "mfa_device_info_enabled": false
    },
    "created_at": "2020-10-14T01:54:59.976Z",
    "updated_at": "2020-10-16T17:28:45.970Z",
    "function": "CmV4cG9ydHMuaGFuZGxlciA9IGFzeW5jIChjb250ZXh0KSA9PiB7CiAgICBjb25zb2xlLmxvZyhjb250ZXh0KTsKICAgIHJldHVybiB7CiAgICAgICAgdXNlcjogY29udGV4dC51c2VyCiAgICB9Cn0K"
}

Typically, this error means that your access token value is invalid.

{
    "name": "UnauthorizedError",
    "message": "The request requires user authentication."
}

The requested app id does not exist.

{
    "message": "The resource with the given id could not be found",
    "name": "NotFoundError"
}

Response Elements

id The Hook unique ID in OneLogin.
type A string describing the type of hook. e.g. `pre-authentication`
packages An object containing NPM packages that are bundled with the hook function.
runtime The Smart Hooks supported Node.js version to execute this hook with.
context_version The semantic version of the content that will be injected into this hook.
retries Default 0. Max 4. Number of retries if execution fails.
timeout Default 1. The number of seconds to allow the hook function to run before before timing out. Maximum timeout varies based on the type of hook. See overview for more details.
disabled Boolean to enable or disable the hook. Disabled hooks will not run.
status String describing the state of the hook function. When a hook is ready and disabled is false it will be executed.
  • ready
  • create-queued
  • create-running
  • create-failed
  • update-queued
  • update-running
  • update-failed
env_vars Array of Environment Variable objects that will be available via process.env.ENV_VAR_NAME in the hook code.
options

A set of attributes allow control over the information that is included in the hook context.

See the docs for each hook type to learn about which config options are available.

created_at ISO8601 format date that they hook function was created.
created_at ISO8601 format date that they hook function was last updated.
function A Base64 encoded representation of the javascript function that will be executed when this hook fires.

Postman Collection

Run In Postman

    Clicking Run in Postman button navigates to the page where you can fork the collection to your workspace. Forking the collection into your workspace will enable you to contribute to the source collection using pull requests. You can also view the collection in a public workspace if you like and even import a copy of the collection using the links present on the screen.

Sample Code

cURL

Replace sample values indicated by < > with your actual values.

Get Hook

curl 'https://<subdomain>/api/2/hooks/:id' \
-X GET \
-H "Authorization: bearer <access_token>"

Have a Question?

Found a problem or a bug? Submit a support ticket.

Looking for walkthroughs or how-to guides on OneLogin's user and admin features? Check out the documentation in our Knowledge Base.

Have a product idea or request? Share it with us in our Ideas Portal.