Test speech-to-text watson API with Postman, but get Error 401 on - ibm-watson

I am very new to this kind of stuff. This is my setup. enter image description here
Any suggestion is appreciated.

Hi The issue is in Authorization, API key needs to be provided under Authorization tab, I would suggest to cross check API key via IBM console
Here is steps to convert text to speech using IBM watson with postman
I assume you have ApiKey value, If you do not have Go to, IBM watson, create text-to-speech resource, -> Go to Manage -> You will have the API Key
Go to Postman, create new Post request
Now you need to add URL, Authorization using Basic Method, Headers & data refer
Click on Send and you will receive audio under response -> Body tab
If you want to do quick check then you can use curl for the same
curl -X POST \
https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize \
-H 'Accept: audio/wav' \
-H 'Authorization: Basic REPLACE_API_KEY' \
-H 'Content-Type: application/json' \
-H 'Postman-Token: 3c147726-2f1e-4531-abca-0898127e8644' \
-H 'cache-control: no-cache' \
-d '{"text": "hello world"}'

A 401 http error code typically means you are not able to authenticate. That means your token is either not valid or you've misconfigured how the token is given to the API. I believe the later is your problem. Based on these docs, you need to pass the token as the value to the X-Watson-Authorization-Token header not as a query parameter.

Related

https://appengine.google.com/_ah/logout still working?

Until a few days ago I could use the log out from google account procedure mentioned (among several others) in this link.
The recommended log out URL is similar to:
https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=http://localhost:4200/index.html
But all of a sudden when navigating to the recommended URL, a redirection notice page appears instead of navigating directly to http://localhost:4200/index.html
In this previous question a similar problem was reported, but also that the problem solved itself shortly after
Can anyone confirm that the log out from google account URL is still working?
Thank you very much
Redirection notice page appearance is the intended behavior of the appengine API.
For security reasons it will no longer work, unless URL will be signed.
Please check documentation, how to sign URL with the appengine API.
Example: you can find documentation and test it on the API method page. Expanding try this API window, you will get access to example in curl, http and javascript.
You also need to use ?key=<YOUR_API_KEY> part with the secret key for authentication
curl --request POST \
'https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/<service-account-name>%40<project-name>.iam.gserviceaccount.com:signBlob?key=<YOUR_API_KEY>' \
--header 'Authorization: Bearer <YOUR_ACCESS_TOKEN>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"payload":"<BLOB-TO-SIGN>"}' \
--compressed

How to exercise secured app engine hosted REST APIs using curl?

Let us assume that there is an app engine standard python app hosted at https://xyz.appspot.com and that its URLs are protected with:
login: admin
secure: always
How can I exercise the APIs using curl? I guess the real question is how can I authenticate to the app using curl. If the app is used from a browser, one is redirected to Google login but I am wondering how I can simulate the same from curl.
Any help is greatly appreciated.
Thanks,
Raghu
One way would be to do the authentication in browser first, and then copy the cookie from there to curl. For example in Chrome, you can open the devtools (F12) and select the Network tab.
When you access your secure resource it will appear there. Then you can right click -> Copy -> Copy as cURL (bash).
This will give you a cURL command that is authorized to call your secure resource.
Based on the suggestion from #Erfa, I visited the site in Chrome while keeping the dev tools open.
The browser takes you through login procedure and the site appears. At this point, right click on the GET request in "Network" tab and select "Save as HAR with Content" which saves the API information in a text file.
In the file, you will find a cookie that is being sent with the GET request. You can now use this same cookie with curl as follows:
$ curl --cookie "NAME=VALUE" <URL>
You can use a combination of Cloud Endpoints and API Key.
In this article https://cloud.google.com/endpoints/docs/frameworks/python/restricting-api-access-with-api-keys-frameworks from Google Cloud Platform you have an example of how to use curl authentication with this combination:
If an API or API method requires an API key, supply the key using a
query parameter named key, as shown in this cURL example:
curl \
-H "Content-Type: application/json" \
-X POST \
-d '{"message": "echo"}' \
"${HOST}/_ah/api/echo/v1/echo_api_key?key=${API_KEY}
where HOST and API_KEY are variables containing your API host name and API key,
respectively. Replace echo with the name of your API, and v1 with the
version of your API.

401 response when posting to Firebase Cloud messaging, when server key is valid

I'm implementing sending push notifications from my google-app-engine server to client apps.
I'm receiving response 401 when sending post message to Firebase cloud messaging server (https://fcm.googleapis.com/fcm/send). I've followed instructions in https://firebase.google.com/docs/cloud-messaging/server, so I'm sending "Authorization" header with my server key. When I'm checking for validity of the key with curl:
curl --header "Authorization: key=$api_key" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"registration_ids\":[\"ABC\"]}"
I'm getting response:
{"multicast_id":6193339963814546500,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Which should mean that my server key is valid.
I followed "Recommended Actions" for 401 described in: https://firebase.google.com/docs/cloud-messaging/http-server-ref
Apart from the last one: "Request originated from a server not whitelisted in the Server key IPs."
Can that be the cause? How to check that?
I solved the issue. It was my mistake. I wasn't truncating json to string properly and my server key wasn't in fact a correct one.
Sorry for bother.

Extracting OAuth token from Salesforce Workbench to do Rest Api calls

I am new to Salesforce and SF workbench.
I have been given read access and login credentials to the SF workbench for one of out clients.
I know I can use SF Rest API to extract data from Salesforce object, but I guess I would need OAuth token to be able to do that.
Is there a way to extract those tokens from the workbench to do simple rest api curl commands?
If you setup a Connected App in Salesforce (any org, including a developer org) and enable OAuth then you can use the following curl command to create an OAuth token from a username and password:
curl https://login.salesforce.com/services/oauth2/token \
-d "grant_type=password" \
-d "client_id=YOUR_OAUTH_CONSUMER_KEY" \
-d "client_secret=YOUR_OAUTH_CONSUMER_SECRET" \
-d "username=YOUR_USERNAME" \
-d "password=YOUR_PASSWORD"
From Workbench if you select Session Information from the Info menu and expand the Connection folder you will see a Session Id value this is your current session token and it can be used for Curl REST commands.
You could also use the REST Explorer found under the Utilities menu to do your simple REST API commands.

jhipster oauth : How can i get the access_token via CURL

i'm trying to use the jhipster tool in order to create a new project with the oauth2 authentication. The project example work fine, i can login with the angularjs interface, but can't understand how can i create a new user and then get the access token via Curl command line for this new user.
Thanks for your help
Step #1: Register the user.
Register a user at http://localhost:8080/#/register and make sure you can log in via the web interface.
Step #2: Obtain an OAuth2 token.
Information required for obtaining an OAuth2 token:
OAuth2 client id (see application.yml)
OAuth2 secret (see application.yml)
The user name and password used to register the new
user.
Required scope/s
Then, obtain an OAuth 2 token from the server:
curl -X POST -vu client:secret http://localhost:8080/oauth/token -H "Accept: application/json" -d "username=username&password=password&grant_type=password&scope=read&client_id=clientid&client_secret=secret"
.. returns something like this:
{"access_token":"7916d326-0f7f-430f-8e32-c5135a121052","token_type":"bearer","refresh_token":"2c69ca58-a657-4780-b5d8-dc965d518e9e","expires_in":1037,"scope":"read"}
Step #3: Use the token in calls to protected resources:
Then, the auth token must be supplied in the header on every call:
curl http://localhost:8080/app/rest/books -H "Authorization: Bearer 7916d326-0f7f-430f-8e32-c5135a121052"

Resources