Skip to main content

Does anyone have a solution to "run schedules" using the API (2.8, 2.7, 2.6)?

 

I have seen "undocumented references" like (/api/2.x/run/schedules/) to run schedules, but am reticent to use....

 

The "run schedule" from tabcmd is very helpful in that, it can trigger an extract refresh for MULTIPLE books that happen to be on the same schedule_id... And I'm trying to recreate that ability once the data is ready rather than what for say, 10 o'clock.

 

Does anyone know if I can use the schedule_id as input to a refresh extract and it will work?? Or, better know of a way to avoid hardcoding the books so that I can run extract commands programitically when the ETL finishes??

 

thanks!

jim!

3 réponses
  1. 28 mars 2018, 14:44

    Hi Gaurav

    Have written the following REST API code in Powershell to run all tasks assigned to a schedule.

    Hopefully this will resolve your problem

    You will need to save the code into a .ps1 file

    and then run in powershell window.

     

    ie. .\RunSchedule.ps1 -server localhost -username glen -password password -Schedule "Every 15 Mins"

     

    param(

       [string[]] $server,

       [string[]] $username,

       [string[]] $password,

       [validateset('http','https')][string[]] $protocol = 'http',

       [string[]] $siteID = "",

       [string[]] $ScheduleName

    )

     

    function TS-GetScheduleDetails

    {

    param(

    [string[]] $Name = ""

    )

     

    $PageSize = 100

    $PageNumber = 1

    $done = 'FALSE'

     

    While ($done -eq 'FALSE')

    {

      $response = Invoke-RestMethod -Uri ${protocol}://$server/api/$api_ver/schedules?pageSize=$PageSize`&pageNumber=$PageNumber -Headers $headers -Method Get

      $totalAvailable = $response.tsResponse.pagination.totalAvailable

      If ($PageSize*$PageNumber -gt $totalAvailable) { $done = 'TRUE'}

      $PageNumber += 1

      foreach ($detail in $response.tsResponse.schedules.schedule)

       {

        if ($Name -eq $detail.name){Return $detail.ID}

       }

    }

     

    }

     

    $api_ver = '2.8'

     

    $global:server = $server

    $global:protocol = $protocol

    $global:username = $username

    $global:password = $password

     

    # generate body for sign in

    $signin_body = (’<tsRequest>

      <credentials name=“’ + $username + ’” password=“’+ $password + ’” >

       <site contentUrl="’ + $siteID +’"/>

      </credentials>

    </tsRequest>’)

     

       $response = Invoke-RestMethod -Uri ${protocol}://$server/api/$api_ver/auth/signin -Body $signin_body -Method Post

       # get the auth token, site id and my user id

       $authToken = $response.tsResponse.credentials.token

       $siteID = $response.tsResponse.credentials.site.id

       $myUserID = $response.tsResponse.credentials.user.id

     

       # set up header fields with auth token

       $headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”

       # add X-Tableau-Auth header with our auth tokents-

       $headers.Add(“X-Tableau-Auth”, $authToken)

     

    #Get Schedule ID

     

    $ScheduleID = TS-GetScheduleDetails -Name $ScheduleName

    $ScheduleID

     

    #Get Tasks assigned to this schedule and run them8

     

      $PageSize = 100

      $PageNumber = 1

      $done = 'FALSE'

     

      While ($done -eq 'FALSE')

       {

        $response = Invoke-RestMethod -Uri ${protocol}://$server/api/$api_ver/sites/$siteID/schedules/$ScheduleID/extracts?pageSize=$PageSize`&pageNumber=$PageNumber -Headers $headers -Method Get

        $totalAvailable = $response.tsResponse.pagination.totalAvailable

     

        If ($PageSize*$PageNumber -gt $totalAvailable) { $done = 'TRUE'}

     

        $PageNumber += 1

     

        ForEach ($detail in $response.tsResponse.extracts.extract)

         {

           $TaskID = $detail.ID

           $body = "<tsRequest></tsRequest>"

           $response = Invoke-RestMethod -Uri ${protocol}://$server/api/$api_ver/sites/$siteID/tasks/extractRefreshes/$TaskID/runNow -Headers $headers -Method POST -Body $body -ContentType "text/xml"

           $response.tsresponse.job

               }

       }

     

      $response = Invoke-RestMethod -Uri ${protocol}://$server/api/$api_ver/auth/signout -Headers $headers -Method Post

      "Signed Out Successfully from: " + ${protocol}+ "://"+$server

0/9000