Use this script to tag your Snyk projects while being imported, in this example we will use Github as the source of the projects and tag them with an appId value
- List of projects from Snyk
- List all project API using
- Origin: github
- Name:
- List all project API using
- For each project
⚠️ 1 Github Repo -> Multiple projects into Snyk → 1 GH repo / 1 tag- Fetch tag
Apply appId tag to project appId: <VALUE>
Fetching project (with or without tags associated with them)
https://snyk.docs.apiary.io/#reference/projects/all-projects/list-all-projects
Adding a tag
https://snyk.docs.apiary.io/#reference/projects/project-tags/add-a-tag-to-a-project
(Bash)
#!/usr/bin/env bash
set -eux
IMPORT=$1
PROJECT=$2
LABEL=$3
SNYK_ORG=$4
SUFFIX=${SUFFIX:-}
curl -s -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' $IMPORT |\
jq -r '.logs|.[]|select(.name=="'$SNYK_ORG'/'$PROJECT'").projects|.[].projectUrl'
projects=$(curl -s -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' $IMPORT \
jq -r '.logs|.[]|select(.name=="'$SNYK_ORG'/'$PROJECT'").projects|.[].projectUrl' |\
awk '/-/' | gsed 's_.*/project/__;s_"__')
for p in $projects; do
echo $p
curl -s -X POST -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' --data-binary '{"key":"label","value":"'$LABEL'"}' https://snyk.io/api/v1/org/$ORG/project/$p/tags${SUFFIX}
done