Associate a Project with a Webhook

Coverity on Polaris

Version
latest
Once you have created a webhook, you can associate it with projects.

Prerequisites

Before setting up a project-webhook association, you must have:

  • The webhook id, which you should have saved when creating the webhook.
  • The project id, which is included in project details from /api/common/v0/projects.

About Project Webhooks

The project-webhooks object uses the project-id as its identifier. You can automatically generate project webhooks objects for projects that exist in the common object service if they don't exist in the notifications service.

Associate a Webhook with a Project

The following workflow describes the bigger process from creating a new webhook to using it as a project webhook.

Step API Call
1. Create a webhook POST /api/notifications/v0/webhooks
2. Retrieve project details GET /api/common/v0/projects
3. Create project-webhook association POST /api/notifications/v0/project-webhooks

When using webhooks, keep these guidelines in mind:

  • Use only POST for creating an association with a project.
  • Use PATCH to update project associations or to remove an association with a project.

Associating a Webhook with a Project

The following example enables you to associate a webhook with a project.

Request:

// POST https://subdomain.cop.blackduck.com/api/notifications/v0/project-webhooks

{
    "data": {
        "type": "project-webhook",
        "id": "150cd9f0-ef40-434b-b862-2a97cd884a1e",
        "attributes": {
            "webhook-ids": [
            "c605f908-dfe4-11e9-8a34-2a2ae2dbcce4"
            ]
        }
    }
}
                    

Ensure that the request includes the project-id in the id field, as well as an array of webhook-ids that you want to associate with the project. These are required.