Create custom governance functions in Postman

API Governance custom functions are available on Postman Enterprise plans. If you don't have an Enterprise account, you'll be able to see the API Governance page, but you won't be able to configure custom functions.

You can create custom governance functions and use them in your custom API Governance rules that Postman applies to your API definitions.

Super Admins and API Governance Managers can manage custom governance functions for their team.

Adding a custom function

You can add custom governance functions to use in your custom API Governance rules. Postman provides you with a boilerplate function to help you start writing your custom governance function. You must write custom functions in JavaScript using ES6 syntax or CommonJS syntax.

  1. Go to the Postman home screen, and then select API Governance from the team information pane.

  2. Select the Rule Library tab, and then select the Functions tab.

  3. Select Create Function.

    Create custom API Governance function
  4. Name the function's file, and then write the function in the editor. It must adhere to custom functions guidelines.

    Postman will prompt you with suggestions as you enter text. Select one to autocomplete your code.

  5. Select Create.

    New custom API Governance function

Adding a custom function to a custom rule

To add a custom function to a custom API Governance rule, add a custom function, and then begin the steps to add a custom rule.

Add the then.function property to the rule, and add the custom function's filename as its value to use it in your rule (for example, function: custom_function_name). If your custom function accepts options, add the then.functionOptions property. Learn more about Spectral rule properties and Spectral custom functions.

Then select Create to create a custom rule that uses a custom function.

Viewing custom rules that use a custom function

You can view the custom rules a custom function is used in.

  1. Select the Rule Library tab, and then select the Functions tab.

  2. Select a custom function's filename in the Name column.

    To view only the number of custom rules each custom function is used in, you can review the values in the Used In column.

  3. Select Rules affected by this function to expand the custom rules your custom function is used in.

    Custom API Governance functions used in custom rules
  4. Optionally, you can select a custom rule's name to open it in a new tab.

Editing a custom function

  1. Select the Rule Library tab, and then select the Functions tab.
  2. Select a custom function's filename in the Name column.
  3. Edit the function, and then select Save.

Removing a custom function

To remove a custom API Governance function, you must remove the API Governance rules that use the custom function. Then select the delete icon Delete icon next to the custom function's filename.

Delete a custom API Governance function

Last modified: 2023/06/15