How do you create a policy without tyk-dashboard?

Hi Troy,

To create Policies programmatically, yu will need to use the Dashboard REST API which has a policies endpoint.

If you are running Tyk and the Dashboard then this will be the only way to create and load policies.

To use file-based policy loading, then you’ll need to not use the dashboard at all (or at least, not to set up and manage policies).

Policies are added to the policie folder which is defined in the Tyk.conf file.

The relevant details are in the docs for he configuration file here:

https://tyk.io/docs/tyk-api-gateway-v-2-0/configuration/gateway-configuration-options/

The relevant config we’re using is:

policies.policy_source
Set this value to file to look on the file system for a definition file, set to service to use the dashboard service. Note the option for mongo has now been removed.

You’ll need to use the dashboard RESt API if you want to export your definitions into a file format.

The policy file format is like the example shows, one JSON object with all the relevant policies as sub documents (see tyk/policies/policies.json at master · TykTechnologies/tyk · GitHub)

Hope that helps.