Did you know: Workflows can be consumed as a REST API!

Last post 01-25-2018, 7:10 PM by Sky. 0 replies.
Sort Posts: Previous Next
  • Did you know: Workflows can be consumed as a REST API!
    Posted: 01-25-2018, 7:10 PM

    Have you ever written a really awesome workflow, but wish you could call it from your external script or another system easily?

    All you need to do is notify Commvault that a given workflow should expect to be called via REST API:

    1.  Edit your workflow via the Commcell Console
    2.  Under Workflow Properties, in the General tab, change the Mode option from Job to API
    3.  Save and redeploy the workflow

     

    Once the workflow has been re-deployed, you can use your favourite scripting language to Login (POST /Login), then call the API either via a GET or POST method (/wapi/<name of workflow>).

    In the example below, we're going to modify the Demo_CheckReadiness workflow to trigger it via GET request against a given Client Computer Group, and should expect an alert email to come back to our use as per the example workflow below.

    Here's an exercise on your own - try adapting one of your own workflows, or an existing one, and send the results back to your own script!

    For more information from Books Online, please refer to the API section, or check out the POSTMAN collection at https://api.commvault.com

    • http://documentation.commvault.com/commvault/v11/article?p=features/workflow/configure_workflow_properties.htm#Setting_Workflow_General_Properties 
    • http://documentation.commvault.com/commvault/v11/article?p=features/rest_api/operations/get_workflow_execute_api.htm 
    • http://documentation.commvault.com/commvault/v11/article?p=features/rest_api/operations/post_workflow_execute_api.htm 

     

    Powershell sample script:

    $WebServer = "http://localhost:81/SearchSvc/CVWebService.svc"
    $username = "<user here>"
    $password = "<pwd here>"

    $headers["Accept"] = "application/json"
    $Body = @{
    username = $username
    password = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($password))
    }

    # Login to Commvault REST API
    $Result = Invoke-RestMethod -Method POST -Uri "$WebServer/Login" -Headers $headers -Body $($Body | ConvertTo-Json) -ContentType "application/json"

    # Save QSDK token
    $headers["Authtoken"] = $Result.token

    # Call Workflow
    $Result = Invoke-RestMethod -Method GET -Uri "$WebServer/wapi/Demo_CheckReadiness?ClientGroupName=Media Agents" -Headers $headers


    Cheers,
    Luke
    (@cv_skywalker)
The content of the forums, threads and posts reflects the thoughts and opinions of each author, and does not represent the thoughts, opinions, plans or strategies of Commvault Systems, Inc. ("Commvault") and Commvault undertakes no obligation to update, correct or modify any statements made in this forum. Any and all third party links, statements, comments, or feedback posted to, or otherwise provided by this forum, thread or post are not affiliated with, nor endorsed by, Commvault.
Commvault, Commvault and logo, the “CV” logo, Commvault Systems, Solving Forward, SIM, Singular Information Management, Simpana, Commvault Galaxy, Unified Data Management, QiNetix, Quick Recovery, QR, CommNet, GridStor, Vault Tracker, InnerVault, QuickSnap, QSnap, Recovery Director, CommServe, CommCell, SnapProtect, ROMS, and CommValue, are trademarks or registered trademarks of Commvault Systems, Inc. All other third party brands, products, service names, trademarks, or registered service marks are the property of and used to identify the products or services of their respective owners. All specifications are subject to change without notice.
Close
Copyright © 2018 Commvault | All Rights Reserved. | Legal | Privacy Policy