Update policy
curl --request PUT \
--url https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"deploymentId": 123,
"policyId": 456,
"rulePath": "<string>"
}
'import requests
url = "https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}"
payload = {
"deploymentId": 123,
"policyId": 456,
"rulePath": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({deploymentId: 123, policyId: 456, rulePath: '<string>'})
};
fetch('https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'deploymentId' => 123,
'policyId' => 456,
'rulePath' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}"
payload := strings.NewReader("{\n \"deploymentId\": 123,\n \"policyId\": 456,\n \"rulePath\": \"<string>\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"deploymentId\": 123,\n \"policyId\": 456,\n \"rulePath\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"deploymentId\": 123,\n \"policyId\": 456,\n \"rulePath\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"policyId": "1",
"updatedRule": {
"category": "security",
"confidence": "CONFIDENCE_HIGH",
"cweCategories": [
"CWE-918: Server-Side Request Forgery (SSRF)"
],
"hasValidators": true,
"id": "<string>",
"languages": [
"python"
],
"lastChangeAt": "2024-07-29T22:33:37.380Z",
"lastChangeBy": "<string>",
"owaspCategories": [
"A07: Cross-Site Scripting (XSS)"
],
"path": "python.rule.1",
"policyMode": "MODE_BLOCK",
"registryMaintainer": "semgrep",
"rulesets": [],
"secretType": "<string>",
"severity": "SEVERITY_HIGH",
"source": "SOURCE_COMMUNITY",
"technologies": [
"django",
"flask"
],
"url": "<string>",
"vulnerabilityClass": "Improper Authentication"
}
}Policies
Update policy
deprecated
PUT
/
api
/
v1
/
deployments
/
{deploymentId}
/
policies
/
{policyId}
Update policy
curl --request PUT \
--url https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"deploymentId": 123,
"policyId": 456,
"rulePath": "<string>"
}
'import requests
url = "https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}"
payload = {
"deploymentId": 123,
"policyId": 456,
"rulePath": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({deploymentId: 123, policyId: 456, rulePath: '<string>'})
};
fetch('https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'deploymentId' => 123,
'policyId' => 456,
'rulePath' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}"
payload := strings.NewReader("{\n \"deploymentId\": 123,\n \"policyId\": 456,\n \"rulePath\": \"<string>\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"deploymentId\": 123,\n \"policyId\": 456,\n \"rulePath\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://semgrep.dev/api/v1/deployments/{deploymentId}/policies/{policyId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"deploymentId\": 123,\n \"policyId\": 456,\n \"rulePath\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"policyId": "1",
"updatedRule": {
"category": "security",
"confidence": "CONFIDENCE_HIGH",
"cweCategories": [
"CWE-918: Server-Side Request Forgery (SSRF)"
],
"hasValidators": true,
"id": "<string>",
"languages": [
"python"
],
"lastChangeAt": "2024-07-29T22:33:37.380Z",
"lastChangeBy": "<string>",
"owaspCategories": [
"A07: Cross-Site Scripting (XSS)"
],
"path": "python.rule.1",
"policyMode": "MODE_BLOCK",
"registryMaintainer": "semgrep",
"rulesets": [],
"secretType": "<string>",
"severity": "SEVERITY_HIGH",
"source": "SOURCE_COMMUNITY",
"technologies": [
"django",
"flask"
],
"url": "<string>",
"vulnerabilityClass": "Improper Authentication"
}
}Authorizations
Get access to data with your API token. Example header:
Authorization: Bearer 2991e2fb4b540fe75b8f90677b0b892b6314e4961cb001fe6eb452eee248a628
The token can be provisioned from the Tokens section in your Settings, and requires explicitly enabling Web API access.
Path Parameters
Deployment ID (numeric). Example: 123. Can be found at /deployments, or in your Settings in the web UI.
Example:
123
Policy ID (numeric). Example: 456. Can be found at /deployments/{deploymentId}/policies.
Example:
456
Body
application/json
Deployment ID (numeric). Example: 123. Can be found at /deployments, or in your Settings in the web UI.
Example:
123
Policy ID (numeric). Example: 456. Can be found at /deployments/{deploymentId}/policies.
Example:
456
New policy mode to set for the Rule.
- MODE_MONITOR: Monitor mode, silently report findings
- MODE_COMMENT: Comment mode, leaves PR comments but does not block
- MODE_BLOCK: Block mode, leaves PR comments and blocks PR
- MODE_DISABLED: Disabled mode, not active
| value | description |
|---|---|
| MODE_MONITOR | Monitor mode, silently report findings |
| MODE_COMMENT | Comment mode, leaves PR comments but does not block |
| MODE_BLOCK | Block mode, leaves PR comments and blocks PR |
| MODE_DISABLED | Disabled mode, not active |
Available options:
MODE_MONITOR, MODE_COMMENT, MODE_BLOCK, MODE_DISABLED Full path of the Rule.
Was this page helpful?