Create Watch

Xray REST APIs

Products
JFrog Xray
Content Type
REST API
ft:sourceType
Paligo

Description: Creates a new Watch

API Version: v2

Security: Requires the "Manage Watches" role to be set on the User or Group level.

Notes: For Xray version 3.21.2 and above with Projects, a Project Admin with Manage Security Assets privilege can create a Watch using this REST API in the scope of a project, by using the additional query parameter projectKey. A Watch can include both Global and Project Policies.

Usage: POST api/v2/watches

Consumes: application/json

Produces: application/json

Response Codes:

201: Success - Watch has been successfully created

415: Failed to parse request

400: invalid watch

403: No permissions for watch

409: Watch with name {name} already exists

500: Failed to create watch

Sample Usage: Sample 1 - Watch a Repository

POST api/v2/watches

{
    "general_data": {
        "name": "vuln-prod",
        "description": "This is a new watch created using API V2",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "repository",
                "bin_mgr_id": "art-prod-eu",
                "name": "libs-release-local",
                "filters": [
                    {
                        "type": "regex",
                        "value": ".*"
                    }
                ]
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "medium_policy",
            "type": "security"
        }
    ]
   },  
    "watch_recipients":["galba@myemail.com","umac@youremail.com"]
}

Sample 2 - Watch All Repositories

POST api/v2/watches

{
    "general_data": {
        "name": "all-repositories",
        "description": "This is a new watch created using API V2",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "all-repos",
                "filters": [
                    {
                        "type": "package-type",
                        "value": "Docker"
                    },
                    {
                        "type": "package-type",
                        "value": "Debian"
                    }
                ]
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "critial_issues",
            "type": "security"
        }
    ]
 },  
   "watch_recipients":["name@myemail.com","umac@youremail.com"]
}

Sample 3 - Watch a Build

POST api/v2/watches

{
    "general_data": {
        "name": "specific-build-watch",
        "description": "This is a new watch created using API V2",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "build",
                "bin_mgr_id": "art-prod-eu",
                "name": "release-pipeline"
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "critial_issues",
            "type": "security"
        },
        {
            "name": "block_policy",
            "type": "security"
        }
    ]
 },  
   "watch_recipients":["name@myemail.com","umac@youremail.com"]
}

Sample 4- Watch all Builds

{
    "general_data": {
        "name": "build-watch",
        "description": "This is a new watch created using API V2",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "all-builds",
                "bin_mgr_id": "default",
                "filters": [
                    {
                        "type": "ant-patterns",
                        "value":{
                            "ExcludePatterns": ["a*","b*"],
                            "IncludePatterns": ["ab*"]
                        }
                    }
                ]
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "test-license-policy-allowed-12956",
            "type": "license"
        }
    ],
    "watch_recipients":["galba@myemail.com","umac@youremail.com","galba@myemail.com"]
}

Sample 5 - Create a Watch in Projects

POST api/v2/watches?projectKey=<project_key>

Sample 6- Watch Projects by Project Key

POST api/v2/watches {
    "general_data": {
        "name": "single_project_watch",
        "description": "This is a new watch created using API V2",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "project",
                "bin_mgr_id": "default",
                "name": "<project-key#1>"
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "medium_policy",
            "type": "security"
        }
    ],
    "watch_recipients": [
        "galba@myemail.com",
        "umac@youremail.com"
    ]
} 

Sample 7 - Watch All Projects

POST api/v2/watches

{
    "general_data": {
        "name": "vuln-prod",
        "description": "This is a new watch created using API V2",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "all-projects",
                "bin_mgr_id": "art-prod-eu",
            }
        ]
     }
  ]
    },
    "assigned_policies": [
        {
            "name": "medium_policy",
            "type": "security"
        }
    ]
   },  
    "watch_recipients":["galba@myemail.com","umac@youremail.com"]
}

Sample 8 - Watch Projects with Include/Exclude Patterns on Project Key

POST api/v2/watches {
    "general_data": {
        "name": "vuln-prod",
        "description": "This is a new watch created using API V2",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "all-projects",
                "bin_mgr_id": "default",
                "filters": [
                    {
                        "type": "ant-patterns",
                        "value": {
                            "ExcludePatterns": [
                                "a*",
                                "b*"
                            ],
                            "IncludePatterns": [
                                "ab*"
                            ]
                        }
                    }
                ]
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "medium_policy",
            "type": "security"
        }
    ],
    "watch_recipients": [
        "galba@myemail.com",
        "umac@youremail.com"
    ]
} 

Sample 9 - Create Watch with Jira Integration Enabled

{
    "general_data": {
        "name": "testwatch5",
        "description": "This is a new watch created using API V2",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "repository",
                "bin_mgr_id": "default",
                "name": "testrepo",
                "filters": [
                    {
                        "type": "regex",
                        "value": ".*"
                    }
                ]
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "testpolicy",
            "type": "security"
        }
    ],
    "create_ticket_enabled":true,
    "ticket_profile":"test",
   "watch_recipients":["galba@myemail.com","umac@youremail.com"]
}

Sample 10 - Watch a Release Bundle

POST api/v2/watches

{
    "general_data": {
        "name": "specific-bundle-watch",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "releaseBundle",
                "bin_mgr_id": "default",
                "name": "release-pipeline"
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "block_policy",
            "type": "security"
        }
    ]
}

Sample 11- Watch all Release Bundles

POST api/v2/watches

{
    "general_data": {
        "name": "bundles-watch",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "all-releaseBundles",
                "bin_mgr_id": "default"
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "test-license-policy-allowed-12956",
            "type": "license"
        }
    ]
}

Sample 12- Watch a Release Bundle V2

POST api/v2/watches

{
    "general_data": {
        "name": "specific-bundle-watch",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "releaseBundleV2",
                "bin_mgr_id": "default",
                "name": "release-pipeline"
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "block_policy",
            "type": "security"
        }
    ]
}

Sample 13- Watch all Release Bundle V2

POST api/v2/watches

{
    "general_data": {
        "name": "bundles-watch",
        "active": true
    },
    "project_resources": {
        "resources": [
            {
                "type": "all-releaseBundlesV2",
                "bin_mgr_id": "default
            }
        ]
    },
    "assigned_policies": [
        {
            "name": "test-license-policy-allowed-12956",
            "type": "license"
        }
    ]
}