Trigger a dataset update via python using a post call

left1414
left1414 Member
edited May 2023 in APIs & Domo Developer

I am currently successfully triggering a dataset update from Snowflake to Domo via python using the following code:

import requests
#list of dataset ids and stream ids for the Snowflake>Domo connections guids = { 'datasetID': 'StreamID', 'DatasetID2': 'StreamID2', }
#Does the work of kicking off updates for all Domo datasets linked to Snowflake

domo_token = 'xxxxx' headers = {'x-domo-developer-token': domo_token}

for i in guids: url = f'https://domain.domo.com/api/data/v1/streams/{guids[i]}/executions' r = requests.post(url, headers=headers)

The problem is that this is legacy code and so I'm trying to determine how the original developers set this up. I know the dataset ID is in the dataset URL, but I'm not sure how to get a streamID, or set up a stream if necessary that works by executing a snowflake query.

Does anyone know how to set something like the above up where you can trigger the execution of a dataset via the stream api?

For reference, I found some documentation from domo on streams but it's a little too bare to put into action.

Best Answer

  • left1414
    left1414 Member
    Answer ✓

    I was able to figure this out. In case anyone needs it:

    from pydomo import Domo
    from pprint import pprint
    domo = Domo(client_id, client_secret, api_host=api_host)
    dataset_id = xxxx
    streams = domo.streamsstream_list = streams.list(2000,0)
    dataset_streams = [stream for stream in stream_list if stream['dataSet']['id'] == dataset_id]dataset_stream = dataset_streams[0]
    pprint(dataset_stream)
    dataset_stream_id = dataset_stream['id']
    streams.create_execution(dataset_stream_id) print(dataset_stream_id )

Answers

  • left1414
    left1414 Member
    Answer ✓

    I was able to figure this out. In case anyone needs it:

    from pydomo import Domo
    from pprint import pprint
    domo = Domo(client_id, client_secret, api_host=api_host)
    dataset_id = xxxx
    streams = domo.streamsstream_list = streams.list(2000,0)
    dataset_streams = [stream for stream in stream_list if stream['dataSet']['id'] == dataset_id]dataset_stream = dataset_streams[0]
    pprint(dataset_stream)
    dataset_stream_id = dataset_stream['id']
    streams.create_execution(dataset_stream_id) print(dataset_stream_id )

  • Beat me to it as I was going to suggest pydomo to do this. Here’s more documentation for future users https://github.com/domoinc/domo-python-sdk/blob/master/examples/stream.py

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**