Update a Hook
Use this API to update a Hook function.
See Hook Overview for more detail on the types of hooks available, the context object inserted into the hook function, and how to return from your hook function.
Also download the Postman Collection which has multiple examples of hook functions to use in different scenarios.
Resource URL
https://<subdomain>/api/2/hooks/:id
Header Parameters
Authorization required string | Set to Set 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: In order to use Smart Hooks your API Credentials must be created after 21st October 2020. |
Content-Type required string |
Set to application/json . |
Resource Parameters
id required string |
Set to the |
Request Parameters
type required integer |
The type of hook function that will be updated. Must be one of:
See the Smart Hooks Overview for more detail on the types of hooks available, the context object inserted into the hook function, and how to return from your hook function. |
disabled required boolean |
Default true. Indicates if function is available for execution or not. |
timeout required integer |
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. |
env_vars required array |
An array of predefined environment variables to be supplied to the function at runtime. |
runtime required string |
The Node.js version to execute the hook function with. Must be one of the following supported versions:
|
context_version optional string |
Defaults to latest version of context. Supports semantic versioning. e.g. |
retries required integer |
Default 0. Max 4. Number of retries if execution fails. |
options object |
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. |
packages required object |
A list of public npm packages than will be installed as part of the function build process. Packages can be any version and support the semantic versioning syntax used by NPM. |
function required string |
A base64 encoded string containing the javascript function code. |
conditions array |
An array of objects that let you limit the execution of a hook to users in specific roles. See the docs for each hook type to learn about which config options are available. |
Sample Request
Update a Pre-Authentication hook with risk enabled, external NPM packages, and including environment variables.
{
"type": "pre-authentication",
"function": "",
"disabled": false,
"runtime": "nodejs18.x",
"retries": 0,
"timeout": 1,
"options": {
"risk_enabled": true,
"location_enabled": false,
"mfa_device_info_enabled": true
},
"env_vars": [
"API_KEY"
],
"packages": {
"axios": "0.21.1"
},
"conditions": [
{
"source": "roles",
"operator": "~",
"value": "123456"
}
]
}
Sample Responses
- 200 Ok
- 401 Unauthorized
- 422 Unprocessable Entity
{
"id": "bcc59ea8-002c-4ef7-8002-742ce7cc1892",
"type": "pre-authentication",
"packages": {},
"runtime": "nodejs18.x",
"retries": 0,
"timeout": 1,
"disabled": false,
"status": "update-queued",
"env_vars": [],
"options": {
"location_enabled": false,
"risk_enabled": false,
"mfa_device_info_enabled": false
},
"created_at": "2020-10-19T23:18:35.162Z",
"updated_at": "2020-10-19T23:47:30.606Z",
"function": "CmV4cG9ydHMuaGFuZGxlciA9IGFzeW5jIChjb250ZXh0KSA9PiB7CiAgICBjb25zb2xlLmxvZyhjb250ZXh0KQogICAgcmV0dXJuIHsKICAgICAgICB1c2VyOiBjb250ZXh0LnVzZXIKICAgIH0KfQo="
}
Typically, this error means that your Authorization
header value is missing or incorrectly formatted. The Authorization
header value should use this format: bearer:<access_token>
.
{
"name": "UnauthorizedError",
"message": "The request requires user authentication."
}
You function is not base64 encoded.
{
"name": "UnprocessableEntityError",
"message": "instance.function does not match pattern \"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$\""
}
Response Elements
The values sent in the original payload body will be returned along with the following additions.
id |
The Hook unique ID in OneLogin. |
status |
String describing the state of the hook function. When a hook is ready and disabled is false it will be executed.
|
Postman Collection
- 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.
Create Hook
curl 'https://<subdomain>/api/2/hooks/:id' \
-X POST \
-H "Authorization: bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"type": "pre-authentication",
"function": "CmV4cG9ydHMuaGFuZGxlciA9IGFzeW5jIChjb250ZXh0KSA9PiB7CiAgICBjb25zb2xlLmxvZyhjb250ZXh0KQogICAgcmV0dXJuIHsKICAgICAgICB1c2VyOiBjb250ZXh0LnVzZXIKICAgIH0KfQo=",
"disabled": false,
"runtime": "nodejs18.x",
"retries": 0,
"timeout": 1,
"env_vars": [
],
"packages": {
},
"conditions": [
{
"source": "roles",
"operator": "~",
"value": "123456"
}
]
}'
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.