Show the collection IDs of IBM Cloud Watson Discovery projects using cURL

This blog post is a simple example (cheat sheet) of listing the collections for a project in Watson Discovery using cURL and the IBM Cloud Watson Discovery API V2. You can get more details in the IBM Cloud Watson Discovery API documentation.

1. Log on to IBM Cloud

ibmcloud login (-sso)

2. List the projects

OAUTHTOKEN=$(ibmcloud iam oauth-tokens | awk '{print $4;}')

WATSON_DISCOVERY_INSTANCE_ID=XXXX
DISCOVERY_URL="https://api.us-east.discovery.watson.cloud.ibm.com/instances/$WATSON_DISCOVERY_INSTANCE_ID"
VERSION="2020-08-30"

curl -X GET -H "Authorization: Bearer $OAUTHTOKEN" "$DISCOVERY_URL/v2/projects?version=$VERSION"
{
  "projects" : [ {
    "project_id" : "YYYYY",
    "type" : "document_retrieval",
    "name" : "Sample Project 1",
    "collection_count" : 1
  }, {
    "project_id" : "ZZZZZ",
    "type" : "document_retrieval",
    "name" : "Sample Project 2",
    "collection_count" : 1
  } ]

3. List the collections

OAUTHTOKEN=$(ibmcloud iam oauth-tokens | awk '{print $4;}')

PROJECT_ID=ZZZZZZ

curl -X GET -H "Authorization: Bearer $OAUTHTOKEN" "$DISCOVERY_URL/v2/projects/$PROJECT_ID/collections?version=$VERSION"
{
  "collections" : [ {
    "name" : "Collection1",
    "collection_id" : "ZZZZZ_ZZZZZZ"
  } ]


I hope this was useful to you, and let’s see what’s next?

Greetings,

Thomas

#curl, #watsondiscovery, #api, #watson, #ibmcloud, #ai

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: