How do you connect to the Google Translate service using REST API? - rest

This is my first time using the REST API and I'm not sure if what I'm doing is correct.
I bought a subscription to use the Google Translate service from Rapid API marketplace: https://rapidapi.com/googlecloud/api/google-translate1
When I test the above link using the "Test Endpoint" in the Endpoints tab it works.
Now I want to use it in a web app.
So I set up the endpoint that connects to the Google Translate service using a REST adapter in Oracle Integration Cloud.
In the endpoint I used the information in the above link to set up the connection. Here is what I did:
I set this as the REST API URL:
https://google-translate1.p.rapidapi.com/language/translate/v2
I set these two custom headers (I hid my actual key):
'X-RapidAPI-Key': '--MyKeyIsEnteredHere--',
'X-RapidAPI-Host': 'google-translate1.p.rapidapi.com'
I set the request body to the following json sample:
{
"q" : "Hello World!",
"target" : "es",
"source" : "en"
}
And I set the response body to the following json sample:
{
"translatedText" : "¡Hola Mundo!"
}
Here is the cURL (again hid my key):
curl -X POST -H 'X-RapidAPI-Host: google-translate1.p.rapidapi.com' -H
'X-RapidAPI-Key: --MyKeyIsEnteredHere--'
-H 'Accept: application/json' -H 'Content-Type: application/json' -d '{ "q": "Hello World!", "source": "en", "target": "es" }'
'https://test-frxsj5gfrkv8-fr.integration.ocp.oraclecloud.com/ic/api/integration/v1/flows/rest/TRANSLATION_INTEGRATION/1.0/translation'
Here is the error I get when trying to connect to the Google Translate service:
"The API is unreachable, please contact the API provider", "info": "Your Client (working) ---> Gateway (working) ---> API (not working)"}.The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server. There could be several reasons including 1) The domain name not resolvable, 2) The origin server is down, 3) A firewall or another intermediary blocks the request. Try to replicate the same request using the same set of intermediaries using cURL or any other REST client. You can trace the cURL representation of the request sent to the target service from the Oracle Integration Cloud server logs. Try invoking the target service using cURL. If the problem persists, contact the target service admin."

Related

Using a login token in subsequent GET calls after successful login

I have an application written in PHP that exposes a REST endpoint to allow a client to download a document stored in the application. One can also access this PHP system via a web browser and download a document when logged into the system.
When using the REST endpoint provided by this system for downloading documents, I expect a PDF or some other form, e.g. a link in the response. However, below is what it is in the response.
curl -X GET --header 'Accept: application/json' --header 'DOLAPIKEY: XXXXXXXXXX' 'http://dxxx.com.zw/api/index.php/documents/download?modulepart=order_supplier&original_file=000008'
Response
{
"filename": "000008",
"content-type": "application/octet-stream",
"filesize": 4096,
"content": "",
"encoding": "base64"
}
This response is not helpful. Nonetheless, I know for sure that if I am logged into this system, the internal links allows me to download the file. If I am not logged in, the system prompts for a username and password. This system provides a REST login endpoint, which is working and this is what it is returned.
{
"success": {
"code": 200,
"token": "XXXXXXXXXX",
"entity": "0",
"message": "Welcome doketera - This is your token (recorded for your user). You can use it to make any REST API call, or enter it into the DOLAPIKEY field to use the Dolibarr API explorer."
}
}
So my question then, is how do I use this information in the login response to emulate the same actions I would do on the web browser using the GET method in POSTMAN for example or within any other REST client . This is the internal link provided in the web browser.
http://dxxx.com.zw/document.php?modulepart=commande_fournisseur&file=000009%2F000009.pdf&entity=1

Using the Actions REST API Outside of Google Assistant?

We currently have a Google Action that requires users to log into our system and our OAuth account linking flow successfully provides an access token for authenticating with our fulfillment backend. This works great when our Action makes queries within Google Assistant.
We're also interested in using the Google Actions REST API with own custom chatbot in our web app, our iOS app, and other app platforms, but when making requests of the Google Actions API outside of Google Assistant, we keep receiving 401 authentication error responses.
Is it possible to use the Google Actions REST API outside of the Google Assistant environment? If so, then would someone be able to tell us what we're missing in our REST API calls?
As an example, based on the Google Actions REST API documentation - https://developers.google.com/assistant/actions/api - if we include our valid OAuth access token via the "Authorization: Bearer" header when making a test Google Actions REST API call via the command line:
curl -X POST "https://actions.googleapis.com/v2/projects/[OUR PROJECT ID]:matchIntents" -H "Authorization: Bearer [OUR OAUTH ACCESS TOKEN]" -H "x-goog-user-project: [OUR PROJECT ID]" -H "User-Agent: [OUR APP PLATFORM/VERSION INFO]" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"query\": \"how much money do we owe\", \"locale\": \"en-US\"}"
We always get a 401 error response, no matter how we tweak the headers:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
We've searched extensively online for any troubleshooting hints, but we have not found any answers to what we might be doing wrong here. Is there something missing from our API calls -OR- is the Google Actions REST API simply not accessible outside of the Google Assistant environment? Any help would be much appreciated.
The Actions on Google / Actions Builder platform is not designed to be used outside of the Google Assistant environment. If you want a way to programmatically match intents or call an API, you should use Dialogflow and their APIs.

Forward user after authentication of Google Device

I have users that link their Google suite account using the OAuth2ForDevices approach. After linking the account to the device I would like to forward the user to another page with instructions instead of leaving them at the generic google page "Success! Device connected".
This is the current flow:
1) Grab device_code and user_code from POST to URL: https://accounts.google.com/o/oauth2/device/code
curl -X POST \
https://accounts.google.com/o/oauth2/device/code \
-H 'cache-control: no-cache' \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'client_id=<hidden>&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar'
response
{
"device_code": "ab-cdef...",
"user_code": "ABCD-ABCD",
"expires_in": 1800,
"interval": 5,
"verification_url": "https://www.google.com/device"
}
if i append parameters like foo=bar or forward_url= the response is still the same as above.
redirect_uri=http://localhost:8080 it results in an error, so this parameter is obviously recognised.
{
"error": "invalid_request",
"error_description": "Invalid redirect URI"
}
The problem does not seem to be the URL since the following request works fine: i managed t
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<client_id>&redirect_uri=http://localhost:8080&scope=https://www.googleapis.com/auth/calendar
2) Let user confirm verification_url (https://www.google.com/device)
3) "Success! Device connected"
I have tried with a bunch of domains and URL:s that has been confirmed in both google search console and added to domain verification in https://console.cloud.google.com
Worth mentioning*: I noticed that Google Cloud Platform behaves in a strange way, removing earlier verified domains -- when I'm adding new domains: https://console.cloud.google.com/apis/credentials/domainverification?project=&pli=1&authuser=1
My theories:
1) It's simply not possible to add a redirect_uri when using the OAuth2ForDevices approach.
2) There is a bug* in Google Cloud Platform that displays me domains but this is cached data.
*Buggy?? Google

Uber GET requests 403

I am trying
curl -X GET -H "Authorization: Bearer <TOKEN>" "https://api.uber.com/v1.2/requests/<REQUEST_ID>"
and response is 403
{"message":"Forbidden","code":"forbidden"}
But the https://developer.uber.com/docs/riders/guides/scopes says that
The good news is you currently have access to these scopes when authorizing your own account or those of the developer accounts you list in your application dashboard (Limited Access). This allows you to start building an app immediately.
I've got token via OAuth using my own account
I've set param "scope=request" to https://login.uber.com/oauth/v2/authorize
And I've set "scope=request" when did https://login.uber.com/oauth/v2/token
Also I've trying to do request to https://sandbox-api.uber.com, it responds
{ "message": "cannot find trip", "code": "not_found" }
But I think it's ok, because sandbox doesn't contain my own account data, right?
Where is my fault could be?

AWS api gateway not working same after Deploying API

I have deployed a basic AWS API, Below are the screen shots.
now when i run Test from above and pass parameter shown in Query String of Method Request i will get the following response.
Request: /searchpatents?name=fsf&test=sfsf
Response against above request
{
"name": "fsf",
"sample": "sfsf",
"controller": "awsapi",
"action": "index",
"awsapi": {
"name": "fsf",
"sample": "sfsf"
}
}
Which shows that i can use the name and sample parameter on my HTTP endpoint.
Now i have deployed this api by clicking Deploy API button and sends HTTP request via curl and by POSTMAN after exporting it from AWS stage panel, I am not receiving name and test params.
My Integration Request is as below
Making a GET request with a body is non-standard, and API Gateway is ignoring the body in a GET request. Please try to using POST/PUT for a request with a body.