IBM Watson Studio provides you with the environment and tools to solve your business problems by collaboratively working with data.
You can choose the tools you need to analyze and visualize data, to cleanse and shape data, to ingest streaming data, or to create and train machine learning models.
Users can manage assets under the IBM Watson Studio project via the web interface, but you can also use a collection of Watson Data REST APIs associated with Watson Studio and Watson Knowledge Catalog to manage data-related assets and the people who need to use these assets.
This post will outline how to manage the project assets through the API command line interface. Users who are interested in automating the process may benefit from this content.
1. Create the user token
The Watson Data API documentation provides instructions on creating an IAM bearer token.
To create a token in the IBM Cloud, log in to IBM Cloud and select Manage > Access (IAM) > IBM Cloud API Keys.
Create an API key for your own personal identity, copy the key value, and save it in a secure place. After you leave the page, you will no longer be able to access this value.
Use this curl command to retrieve a token:
Sample response:
Since, by default, the access token expires after an hour, it’s easier to use a script to get the IAM access token and refresh it when you need to.
A sample shell script:
Note: The script was created on MacOS—you might need to modify it to run correctly in other OS. ‘jq’ is a utility to format the output in JSON format.
2. Get the data asset
Once you have retrieved the access token, you can use it to access the data asset. For example, you may get the data asset by using something similar to the following code:
The access token is read from the stored text file in Step 1 wml_token.txt
.
Tip: You can get the data_asset_id
and project_id
from the URL of the Watson Studio interface:
Click on the data file GoSales.csv
and you can see the URL in the following screenshot:
Sample output:
3. (Optional) Delete the asset
Run the following curl command to delete the asset if you wish:
Summary
The Watson Data API provides a comprehensive list of functions to manage the assets, and most GUI interface based functions can also be implemented with the API command line.
You can also follow these guidelines to access other various assets in Watson Studio, such as projects, catalogs, buckets, etc. For further information on the API, please refer to the online documentation at IBM Watson Data API.