See api-docs Menu

Create Environment Variable

Use this API to create a new Hook Environment Variable and define its value.

Environment Variables are a safe and convenient way to inject secrets or common configuration items into hook functions.

For example, you may want to call an external API from within a hook function so could therefore define an API_KEY environment variable and include it in your hook function definition.

For more detail on how to use environment variables within a hook function see the Smart Hooks Overview.

Resource URL

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

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.

Content-Type

required

string

Set to application/json.

Request Parameters

name

required

string

The name for the environment variable that will be used to retrieve the value from a hook function.

value

required

string

The secret value that will be encrypted at rest and injected in applicable hook functions at run time.

Sample Request

{
    "name": "SAMPLE_VAR",
    "value": "helloworld"
}

Sample Responses

{
    "id": "80f65e4b-4325-4ee6-86af-9e6b8793f125",
    "name": "SAMPLE_VAR",
    "created_at": "2020-10-22T22:07:48.236Z",
    "updated_at": "2020-10-22T22:07:48.236Z"
}

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

Indicates that the syntax of the request is good but a value supplied is not valid.

{
    "message": "Validation failed: The associated Policy with ID 0 could not be found",
    "name": "UnprocessableEntityError"
}

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.

Create Hook Environment Variable

curl 'https://<subdomain>/api/2/hooks/envs' \
-X POST \
-H "Authorization: bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
    "name": "SAMPLE_VAR",
    "value": "helloworld"
}'

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.