Trying to connect Google Oath2 in Postman - google-apps-script

We have a G Suite for Education. I want to create a new gmail user for each of our students.
I enabled Gmail as told in this documentation and downloaded the credentials.json file.
I than opened POSTMAN and created a post request for this URL:
https://accounts.google.com/o/oauth2/v2/auth
I used the parameters from credentials.json:
client_id: (as in json file)
response_type: code
scope: openid%20email
redirect_api: http://localhost
The response is html of the login page.
I tried token, id_token instead of code but response says unsupported_response_type.
What I try to do is to use the following request to create user, which says login required.
POST https://www.googleapis.com/admin/directory/v1/users
Am I on the wrong way?

Related

RapidMiner : Can't get JWT Token

I am refering below document to get JWT Token .
However when I call the API /api/rest/tokenservice it doesn't return the token but returns a web interface asking for login . How can I get JWT Token
REST API Url :
https://docs.rapidminer.com/9.10/hub/rest-api/index.html
Response of postman:
In order to query the internal tokenservice endpoint, you need a valid "session". In the native installation method, you can use basic auth as "session" as outlined in the documentation.
curl -u user:pass "http://localhost:8080/api/rest/tokenservice"
{
"idToken": "the-valid-token",
"expirationDate": "the-exp"
}
However, for this to work when you've deployed RapidMiner AI Hub with Keycloak (and docker), you need to 1. enable basic auth for Keycloak, 2. access the route by first having a valid "login session" (cookie name is RM_SERVER_JSESSIONID) or 3. use a valid Keycloak token.
Enable basic auth in Keycloak
rm-server-homedir/configuration/keycloak/keycloak.json
{
...
"enable-basic-auth": true,
...
}
Valid cookie value
Login via web interface, open the browser's developer tools and use the very same RM_SERVER_JSESSIONID cookie value inside the REST request issued to the /api/rest/tokenservice endpoint.
Not sure what you like to achieve, e.g. schedule a process via REST, I like to outline that you can easily add a process and trigger via Web Service. The triggered process could make use of the Admin Tools extension. You still need to enable Keycloak's basic auth though if you like to trigger it from "outside". A guide how to use the extension can be found here.
Valid Keycloak token
Retrieve a valid Keycloak access token (from Keycloak's token endpoint, e.g. via OpenID Connect) and query the
/api/rest/tokenservice endpoint with Authorization: Bearer .
Disclaimer: This answer is used with permission of the original author from the RapidMiner community.

Trestle Request unsuccessful. Incapsula incident WebApi error

I'm working with Trestle which is real estate MLS service to get property data etc. I have followed their WebApi docs but I'm getting this error whenever I hit their api it looks like their server thinks that request is from some BOT. Even they recommend using Postman to test api:
Its been 3 days and still cant find any fix. Any help?
You do not seem to be following this documentation correctly.
https://docs-trestle.corelogic.com/GettingStarted/WebAPI
At the moment you are entering the token URL (https://api-prod.corelogic.com/trestle/oidc/connect/token) in the main Postman request URL field. The documentation states that you should use the Get New Access Token button on the Authorization tab of a request. You are entering the token URL in the main Postman request URL field.
This is a default flow for oAuth 2.0 requests in Postman.
https://learning.postman.com/docs/postman/sending-api-requests/authorization/#oauth-20
Example:
This could be your request to retrieve data:
https://api-prod.corelogic.com/trestle/odata/$metadata
On the Authorization tab you should select oAuth 2.0; select Get New Access Token and you will see a view which gives you the functionality you are looking for.
When successful, you will get a pop-up which you need to accept in order to use the API.

Testing Google Script with PostMan

I have created a Google Script and published it as a web app, very much like this post has.
However, I would like to call my extremely simple doGet method using Postman. The web app is published with anonymous access and execution permission as me.
I was expecting to be able to paste the URL into Postman, set the GET verb and hit Send - and to see the same result I see in the browser. I do not.
What am I doing wrong?
[UPDATE] Responding to comment by themaster
I have created a Google Apps Script called devices in my Google Drive. I've added this function:
function doDelete(e) {
return HtmlService.createHtmlOutput('{"test":"yes"}');
}
Simple, I know, but should respond to a DELETE request with:
{
"test": "yes"
}
I then hit Save, followed by Deploy > Publish as web app... with the following options:
Project version: new
Execute the app as: me
Who has access: Anyone, even anonymous
I hit Update and get a URL like this:
https://script.google.com/macros/s/ABcdefgHInmLDGiHmpGmXkXIxMjsh0s61sKZ9ov6OOSpkb--1quTtfM/exec
If the function is named doGet and I paste the URL into the browser, I see this JSON mentioned above.
If I leave the function named doDelete and I make a DELETE request from Postman, I get this:
Could not get any response There was an error connecting to
https://script.google.com/macros/s/ABcdefgHInmLDGiHmpGmXkXIxMjsh0s61sKZ9ov6OOSpkb--1quTtfM/exec.
Why this might have happened: The server couldn't send a response:
Ensure that the backend is working properly Self-signed SSL
certificates are being blocked: Fix this by turning off 'SSL
certificate verification' in Settings > General Proxy configured
incorrectly Ensure that proxy is configured correctly in Settings >
Proxy Request timeout: Change request timeout in Settings > General
If I change the function to doGet, republish and call it with a GET request from Postman, I get the same result.
[EDIT] Clarification
If I make the Postman call using GET and have the doGet function setup to call an IFTTT webhook, the webhook does fire. I can also make it fire using the doPost and a POST request in Postman.
However, if I use doDelete with a DELETE request in Postman, the IFTTT webhook does not get called.
Regardless of the verb used in Postman I do not get a response - only the message quoted above.
[EDIT] Response to #sourabh-choraria question
My code currently is just this:
function doGet(e) {
return HtmlService.createHtmlOutput('{"valid":"no"}');
}
Published with the process described above, I get this when calling with Postman:
Could not get any response
I am making that request as a GET without any headers.
Currently, Google Apps Script's Web Apps only support the following HTTP methods, as per their requirements for web apps -
GET via doGet()
POST via doPost()
While not explicitly stated in the reference doc that PUT, DELETE, UPDATE etc. are unsupported, there is no way to execute those HTTP methods via Web Apps in Apps Script.

Send mail via SendGrid API?

I am trying to send an email in my Angular app via SendGrids API.
I am posting to this URL: https://api.sendgrid.com/api/mail.send.json
With this raw data, to test;
{
"api_user":"MyUser",
"api_key":"MyPass"
}
But i get an error back, "Permission denied, wrong credentials"
If i however, set the same api_user and api_key as part of the URL, like so https://api.sendgrid.com/api/mail.send.json?api_user=MyUser&api_key=MyPass, it works.
But as i can have a fairly large portion of data to post (html email body), sending with URL's is not optimal, and it should be part of the post body.
The docs does not reveal much: https://sendgrid.com/docs/API_Reference/Web_API/mail.html
What am i missing?

gmail API : Cannot access the list of messages I requested

So what I'm trying to do is to fetch data from gmail API using unix's shell (curl).
I simply copied this from the json generator to be able to play with the json when I used with curl.
GET https://www.googleapis.com/gmail/v1/users/somebody%40gmail.com/messages?
maxResults=5&includeSpamTrash=false&key={YOUR_API_KEY}
Then I changed the API_KEY by what I was able to generate in my developer console. However, I cannot get the desired json when I put the link in my browser, or curl it in my shell. How do I generate the right key? Because I already generated from all of the choices in the Credentials.
Thanks!
What you generate in the Console is the Client ID and Client secret, which are used when you redirect your users to Google. Upon accepting, Google then redirects the user to the url you specify in the console with a code. This code is then finally used to retrieve the Access Token which you should use as {YOUR_API_KEY}.
Go to Google OAuth 2.0 Playground, and use the Gmail API v1 scopes, and retrieve the access token and use it in your shell.