I have a need to (programatically) analyse the details of Scheduled Queries in BigQuery (eg which tables are updated and which tables accessed in the SQL). I have done something similar for the BQ Tables/Views using Apps Script BigQuery.Tables.list()
, but I cannot find an API to access the Scheduled Queries.
The UI is able to list them, so I feel this should be possible programmatically, e.g. via a REST API. Does anyone know if this is possible, what interface is supported (Apps Script, REST ...), and possibly an example of how to use it.
Here is a shell script that will notify you in Slack if any of your scheduled queries fail. Simply integrate into your existing workflow (as blocking or non blocking) or have it on a separate Cron job. I have used httpie to send my HTTP post but you can also use curl or others. Also, you can also change your HTTP post for any other action.
See link for potential states of transfer state object
If running outside the cloud or on something that hasn't already authenticated, you will need to authenticate before hand. To do this use before the above:
where $PROD_KEY is the service key for whatever you are trying to access.
The above answers are excellent responses for using the REST API. For completeness, I'd like to include the CLI commands approach for solving the same thing. Personally I find this better suited for shell scripts but YMMV.
Example: List of Schedule Queries from Default Project.
Example: Details of a Schedule Query from Default Project.
Further details can be found here.
Scheduled queries are part of BigQuery's Data Transfer Service so you have to use its API. In particular, the
projects.transferConfigs.list
method. Fill in thedataSourceIds
field withscheduled_query
andparent
withprojects/PROJECT_ID
. As discussed in the comments, if you are using a regional location such as europe-west2 instead of a multi-regional one (EU or US) you should useprojects.locations.transferConfigs.list
instead. Now, parent resource will be in the form ofprojects/PROJECT_ID/locations/REGIONAL_LOCATION
.In addition, for other transfers you can get the corresponding
dataSourceIds
using theprojects.dataSources.list
method. That's how I got thescheduled_query
one.Response will be an array of scheduled queries such as:
Example of an API call with bash and
curl
: