Cancel a Deployment in Progress Using REST

You can request a cancellation of a deployment that's already in progress. Make the cancellation request by patching the status of an ongoing deployRequest. The cancellation is processed asynchronously. For API versions 65.0 and higher, deployments with a status of Finalizing Deploy, can't be cancelled. For API versions below 65.0, attempts to cancel a deployment may fail if the deployment has started committing data. Alternatively, it's possible that the cancellation will succeed, but data from the deployment is also committed.
URI
https://host/services/data/vXX.0/metadata/deployRequest/deployRequestId
Formats
JSON
HTTP Method
PATCH
Authentication
Authorization: Bearer token

Request Body: Request Deployment Cancellation

The JSON request body for a deployment cancellation includes a PATCH to the status of the original deployRequest.

1{ 
2     "deployResult":
3           {
4           "status" : "Canceling"
5           }
6    }

Response Body: Request Deployment Cancellation

Because the cancellation request is processed asynchronously, the status shown in the response body can be either Canceling or Canceled.

1{ 
2      	"id" : "0Afxx00000000lWCAQ"
3      	"url" : “https://host/services/data/vXX.0/metadata/deployRequest/0Afxx00000000lWCAQ",
4       "deployResult":    
5             {
6             "checkOnly" : "false",
7             "ignoreWarnings" : "false",
8             "rollbackOnError" : "false",             
9             "status : "Canceling",  // or Canceled
10             "numberComponentsDeployed" : "10",
11             "numberComponentsTotal" : "1032",
12             "numberComponentErrors" : "0",
13             "numberTestsCompleted" : "45",
14             "numberTestsTotal" : "135",
15             "numberTestErrors" : "0",
16             "details" :  { 
17                "componentFailures" : [],
18                "componentSuccesses" : [],
19                      "retrieveResult" : null,
20                      "runTestResults” : {
21                         "numRun" : 0,
22                         "successes" : [ … ],
23                         "failures" : []
24                 	   	}             
25                },
26
27                "createdDate" : "2017-10-10T08:22Z",
28                "startDate" : "2017-10-10T08:22Z",
29                "lastModifiedDate" : "2017-10-10T08:44Z",
30                "completedDate" : "2017-10-10T08:44Z",
31                "errorStatusCode" : null,
32                "errorMessage" : null,
33                "stateDetail" : "Processing Type: Apex Component",
34                "createdBy" : "005xx0000001Sv1m",
35                "createdByName" : "steve stevens",
36                "canceledBy" : null, 
37                "canceledByName" : null,
38                "isRunTestsEnabled" : null
39                }
40       }

When an HTTP status code of 202 (Accepted) is returned, your cancellation request is in progress or successful.