Search This Blog

Friday, April 27, 2018

Watson analytics with nodejs integration

Get a key,from here

https://developer.ibm.com/api/view/id-160:title-Watson_Analytics


Go to the manage api section and get these two parameters.

X-IBM-Client-Id c1a4d636-51c1-4aad-
X-IBM-Client-Secret gC3pL3sG2eC0cK4kB3mK


Open postman and make a put request to

https://api.ibm.com/watsonanalytics/run/oauth2/v1/config


image


In body of put,enter like  this.

{
     "ownerName": "asdf",
     "clientName": "sdfasd",
     "redirectURIs": "https://localhost:6001",
     "ownerPhone": "9999999999",
     "ownerCompany": "asdf",
     "ownerEmail": asdfasdfs@sdfsd.com
}


replace junk with your info, this needs to be done once and put response will get the info you need.

Next time you can do a get on above url with headers, it will spit out the client info to you.


You are all set to push docs to analytics.

But we  have client id only and we need auth  code also, if you try without that you get below error.

"Failed to verify OAuth information. Transaction ID=42

so lets get the auth code

Open a browser and paste this.

https://api.ibm.com/watsonanalytics/run/clientauth/v1/auth?scope=userContext&response_type=code&client_id=-4cf7-89e2-94af7fd6180c&redirectui=http://realhost.org

Make sure you redirect url is same and is reachable, else you will get some background database not reachable error.

give permissions to the app.

image

You will get a call back with authcode likethis.


http://sdfsdfsdf:6001/?code=7qI2rTRi%2FrqOZkAvX61p835QFP7zkclb1NOyp3RI6NwN7wF%2Bm%2BaRUYFpN5ALvYK4RrN0netLwyFpBQmFjv%2Fc0t%2BC%2B4jOxEsnHW%2F5hPAJxBvI2YU3h3Nuk16iM0%2BW9AfP%2FF9AfK%2BrZgsHHEvMB9r1YAGq3m%2BqGR%2FtnfWrDptChBzhZyMv5LEnpm3p6O8cTI7yExGH%2FecXouP2KpwPB6y3ATDoIacoZUUcKZZlcSebqchDrx%2F5n2RWIxk5fSnWO%2BkQJwo%2BrLggmjLUXpMPeaA0qCOfX5P5gd3iU7spOgh5eA%3D%3D#/


Use this code in our node app, valid for 1 hour.

Don’ know why ibm confused so much with auths and tokens but friends.. one more step

we need access token before we get the data assets i know it sucks and sounds redundant.

use a decoder service to decode encoded code

image

Now we use this auth code to get token

https://api.ibm.com/watsonanalytics/run/oauth2/v1/token

image

image

Ref these docs, i could pass from here, tried different grant_type, all of them which were assigned to me in config , but none worked.

{
     "error": "invalid_client"
}


===================Not working….. from here…..so i moved to another analytics solution.. mailed ibm india team but no reply..

Ref.

github repo. followed instructions but didnt work .

https://github.com/WatsonAnalytics/oauth2-nodejs


https://developer.ibm.com/watson-analytics/#getstarted

https://community.watsonanalytics.com/discussions/questions/23305/automatic-upload-of-datasets-through-rest-api.html



Other errors encountered.

These were due to different tenants, i was using for  calling the auth requests or may be i was using localhost instead of actual reachalbe url of my app.(This one got fixed after using reachable url)

error_description": "Invalid grant type. TransactionI

couldn’t proceed after this and tried lot of things, but didn’t work.I tried with both Partner accounts and general public free accounts.

image

No comments:

Post a Comment