See api-docs Menu

Get Hook Logs

Early Preview

This API is in early preview and may be subject to change. Please contact your account manager if you are interested in trying Smart Hooks.

Use this API to get back the execution output logs for a given hook.

These logs will contain the output of any console.log statements that are included in a hook function.

Using a try/catch pattern is a good way to catch any unforseen errors and log them to make debugging easier.

For example, a pre-authentication hook with error handling and logging.

exports.handler = async (context) => {
    // Log the context object coming in to see what is included
    console.log(context)

    try {
        // Do something that accidentally causes an error
        // in this case user would be undefined
        user.policy_id = 12345;
    }
    catch (error) {
        // Log the error so we can debug what went wrong
        console.error("Catch the error", error);
    }

    // Fall back to just returning the user which 
    // will let them continue the login flow
    return {
        user: context.user
    }
}

Resource URL

https://<api-domain>/api/2/hooks/:id/logs

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.

Query Parameters

Standard pagination is supported. Max page limit is 1000. See Pagination for detail on how this works.

request_id

string

Optional. Returns logs that contain this request_id.

correlation_id

string

Optional. Returns logs that contain this correlation_id.

Sample Responses

Sample of logging the context object.

[
    {
        "request_id": "54dfe2d2-5124-47f6-9343-ebd33e65eb14",
        "correlation_id": "a915055b-2a07-4440-83c5-3f8bcad80d8f",
        "created_at": "2020-10-19T20:03:07.610Z",
        "events": [
            "2020-10-19T20:03:07.579Z\t8b2319a4-0d2f-44f8-917f-51afe1d36086\tINFO\t{",
            "  user: {",
            "    user_identifier: 'sam@onelogin.com',",
            "    policy_id: 129314",
            "  },",
            "  device: {",
            "    user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',",
            "    is_mobile: false",
            "  },",
            "  location: { ip: '114.23.220.238', country_code: 'NZ' },",
            "  correlation_id: 'a915055b-2a07-4440-83c5-3f8bcad80d8f',",
            "  request_id: '54dfe2d2-5124-47f6-9343-ebd33e65eb14'",
            "}",
            ""
        ]
    },...
]

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"
}

Postman Collection

Replace sample variables indicated by {{ }} with your actual values.

Download for the Smart Hooks API

Sample Code

cURL

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

Get Hook Logs

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

Have a Question?

Have a how-to question? Seeing a weird error? Ask us about it on StackOverflow.

Found a bug? Submit a support ticket.

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