See api-docs Menu

Get Hook Logs

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://<subdomain>/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.

Many of the search tools described in our Getting Started documentation can be applied to your parameters, allowing you to fine-tune your results.

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

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 Logs

curl 'https://<subdomain>/api/2/hooks/:id/logs' \
-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.