Updating flow status can be achieved using Tooling REST API by FlowDefinitionId
To disable flow definition, set version number 0
req.setBody( '{"Metadata": {"activeVersionNumber":0}}');
To activate flow definition, specify the version number to activate e.g 20
req.setBody( '{"Metadata": {"activeVersionNumber":20}}');
Here's a sample code in apex using user session Id as authorization for simplicity, use access token (OAuth) when calling the API from the external app.
Static string myDomain = 'https://yourdomain.my.salesforce.com'; private static HttpRequest buildHttpReq(String endpoint, String method){ HttpRequest req = new HttpRequest(); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); req.setHeader('Content-Type', 'application/json'); req.setEndpoint(endpoint); req.setMethod(method); return req; } public static String queryFlowDef(){ //find the flowdefinitionid String flowLabel='FlowMasterLabel'; //adapt query accordingly, here retrieving latest flow version String queryEndpoint = myDomain+ '/services/data/v55.0/tooling/query/?q=Select+DefinitionId+from+Flow+Where+MasterLabel=\'' + flowLabel + '\'order+by+VersionNumber+desc+limit+1'; HttpRequest req = buildHttpReq(queryEndpoint,'GET'); Http httpreq = new Http(); HttpResponse res = httpreq.send(req); String response = res.getBody(); Map<String,Object> rmp = (Map<String,Object>)JSON.deserializeuntyped(response); List<Object> lstObt = (List<Object>)rmp.get('records'); Map<String,Object> mapRec = (Map<String,Object>)lstObt[0]; String defId = (String)mapRec.get('DefinitionId'); System.debug(LoggingLevel.DEBUG, defId ); return defId; } public static void disableFlow(){ String flowDefId = queryFlowDef(); HttpRequest req = buildHttpReq(myDomain+'/services/data/v55.0/tooling/sobjects/FlowDefinition/'+flowDefId,'PATCH'); //to disable flow set version number 0 req.setBody( '{"Metadata": {"activeVersionNumber":0}}'); //to reactivate flow version specify the version number e.g 20 //req.setBody( '{"Metadata": {"activeVersionNumber":20}}'); Http http = new Http(); HttpResponse res = http.send(req); String response = res.getBody(); System.debug(LoggingLevel.DEBUG, response ); System.debug(LoggingLevel.DEBUG, res.getStatusCode() ); }
Additional references:
FlowDefinition tooling API
Metadatype FlowDefintion