[First-Gen] How to use APIs to identify which Workflows reference a specific template?

Howdy!

If you are working with Harness resources in a specific application workflow, you might need to retrieve the JSON and YAML of those resources. This can help you search through the configuration as code for all the template references. In this article, we will show you how to retrieve the JSON and YAML of Harness resources using API calls.

Step 1: Open your terminal or command prompt.

Step 2: Copy the first API call to get the JSON of Harness resources from a specific application workflow:

curl --location --request GET "https://app.harness.io/gateway/api/setup-as-code/yaml/directory?accountId={accountId}&appId={appId}" \
-H "accept: application/json" \
-H "content-type: application/json; charset=utf-8" \
-H "x-api-key: <api-key>"

Step 3: Replace the placeholders {accountId} and {appId} with the actual account ID and application ID, respectively. You can find these values in the Harness UI. The following screenshot shows the values in the UI URL (/account/<account-Id>/app/<app-id>/details).

Step 4: Replace <api-key> with your actual Harness API key. You can find instructions on how to generate an API key here.

Step 5: Execute the API call by running the command in the terminal.

Step 6: The output will be the JSON of all the resources in the application workflow. This output can be used to search through the config as code for all the template references.

Step 7: Copy the second API call to get the YAML of the workflow:

curl --location --request GET "https://app.harness.io/gateway/api/setup-as-code/yaml/{node.restName}/{node.uuid}?accountId={accountId}&appId={appId}" \
-H "accept: application/json" \
-H "content-type: application/json; charset=utf-8" \
-H "x-api-key: <api-key>"

Step 8: Replace the placeholders {node.restName}, {node.uuid}, {accountId}, and {appId} with the actual values of the Harness resource you want to get the YAML for:

Field Value
node.restName is the name of the Harness entity type: workflows, services, pipelines, environments, etc.
node.uuid is the universally unique identifier (UUID) of the node.
accountId is your account identifier (ID).
appId is the Application identifier (ID).

Step 9: Replace <api-key> with your actual Harness API key.

Step 10: Execute the API call by running the command in the terminal.

Step 11: The output will be the YAML of the specified resource.

That’s it! You can now use these API calls to retrieve the JSON and YAML of Harness resources from a specific application workflow and validate if the resource has references to a Template. If you have any further issues or questions, please do not hesitate to reach out to Harness support.