Using Metabase API behind google oauth - google-oauth

I have a Metabase Docker image running locally that is routed to the URL:
https://metabase.example.com
I am trying to. do a curl on this to grab a Metabase token to use the Metabase API; however, this URL is hidden behind Google oauth, so I believe I need to first get a google oauth token for the test#company.com service account I am using which I can then pass to the curl request below.
curl --location --request POST 'https://metabase.example.com/api/session/google_auth' \
--header 'Content-Type: application/json' \
--data-raw '{"username": "test#company.com", "password": "password123"}'
Is there a simple way I can grab this Google Oauth token via CURL to then use in the above curl statement for metabase?

Related

Works in curl (and Rested API Client) but not in Postman?

I am able to login my local (and remote server) with the following curl (which I generated using Postman)... and I can login successfully using another API Client (Rested) with the same params/headers/body that I am trying to use in Postman. I've turned off "SSL cert verification" and "Send Postman Token header" in settings (per other Stack Overflow answers).. but still getting an unauthorized response from server when using Postman (but not when using curl or Rested)
curl:
curl -X POST \ http://localhost:8080/api/user/login \ -H 'Accept:
application/json' \ -H 'Content-Type: application/json' \ -d '{
"email": "email#example.com",
"password": "examplemail**" }'
And here is my log..
I just solved my own Q.. and posting this answer because I've seen other questions re: curl working but postman not on SO and Postman communities. My solution was to check the Content-Length header and Connection headers. They were auto populating anyway, so after 'accepting' them as headers, the Postman request worked. Here is a screenshot of the headers that worked.

THINGSBOARD REST API CALL Node

Please be kind and tell me how to execute the following CURL command with REST API Call node from Thingsboard 2.5.2:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"username":"tenant#thingsboard.org", "password":"mypassword"}' 'http://127.0.0.1:8080/api/auth/login'
How can I send the -d '{"username":"tenant#thingsboard.org", "password":"mypassword"}' to the REST API CALL node ?
Thank You !
As described on the documentation page, the first step is indeed to POST on /api/auth/login providing a username and password in order to retrieve a JWT token. This is the first step you described in your curl call.
Then, for further calls to other API endpoints, you must send a X-Authorization HTTP header with the Bearer: $TOKEN as a value.
Note that if you want to interact with the Thingsboard administration API with Java or Python, clients are available to abstract this.

How to use a Circuit Bot to publish a message in Circuit Conversation via Rest API Message

I am trying to make post a message in a circuit conversation through a Circuit Bot via Rest API call. Please help.
You have two options:
Use an incoming webhook. This is very simple and does not require OAuth as the webhook url includes token and the specific conversation. Anyone with this url can post to a conversation. There are both option, posting as yourself, or posting as a bot. If you want to post as a bot, then you first need to create a webhook bot using the "Manage Application > Custom Apps" page. For more information see https://www.circuit.com/unifyportalfaqdetail?articleId=164448 and other webhook articles on these FAQ pages.
Here is s curl example to post a message on an incoming webhook url.
curl https://circuitsandbox.net/rest/webhooks/incoming/9999999-0b95-4088-b272-5bef80f8e68e -H "Content-Type: application/json" -d '{"text":"hello world"}'
Create an actual OAuth 2.0 bot via "Manage Application > Custom Apps" and use the regular REST API (https://circuitsandbox.net/rest/v2/swagger/ui/index.html). There are several REST examples on github. See https://github.com/circuit/circuit-REST-bot for a simple REST bot example.
This is done in two steps :
use the authentication endpoint to obtain a token for your bot
use the messages endpoint (and the token from step 1) to publish the message
Assuming you already have :
a bot (client id, client secret)
conversation ID (the bot must be a participant of it)
Step 1 : Getting the token
curl -X POST
https://<circuitBaseUrl>/oauth/token \
-H 'Authorization: Basic <base64-encode(<clientId>:<clientSecret>)>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&scope=WRITE_CONVERSATIONS'
Get the access_token from the response
Step 2 : Use the REST API to post
curl -X POST \
https://<circuitBaseUrl>/rest/v2/conversations/<conversationId>/messages \
-H 'Authorization: Bearer <access_token>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Host: beta.circuit.com' \
-d content=hello%20from%20postman
Welcome to the Circuit Developer Community ;-)

Dialogflow API bearer token

How to I get a bearer dev-token for a Dialogflow v2 api call? I would like to run this command from my command-line interface on Mac osx. An example request is below:
curl -X GET "https://dialogflow.googleapis.com/v2/projects//agent/intents/?intentView=INTENT_VIEW_FULL" -H "Authorization: Bearer "
There is a request example.
curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://dialogflow.googleapis.com/v2/projects/{your-project-id}/agent/sessions/{session-id}>:detectIntent:detectIntent" \
--data "{'queryInput':{'event':{'name':'MY_CUSTOM_EVENT','parameters':{'parameter-name-1': 'parameter-value-1','parameter-name-2':'parameter-value-2',},'languageCode':'en-US'}}}"
For more requests to make, refer to API reference
According to Setting up authentication, if you want to use v2 API call, you have to
Create the Service Account key.
Download the JSON key file.
Install and initialize the Cloud SDK.
Add an environment variable GOOGLE_APPLICATION_CREDENTIALS (which the value is the path point to the JSON key file) to your shell.
You can test whether the Cloud SDK and variable is set up correctly by executing echo $(gcloud auth application-default print-access-token) in your console.
Then you should be able to make the request.
After making your request, you can navigate to the History tab in the Dialogflow console to check whether the request was successfully sent.

How can I obtain a Mule ARM registration token to be used to register a server into AMC

I was reading at
https://anypoint.mulesoft.com/apiplatform/anypoint-platform/#/portals/organizations/ae639f94-da46-42bc-9d51-180ec25cf994/apis/38784/versions/127446/pages/182856
because I want to automate Anypoint Runtime Manager enablement on lots of servers.
My plan is to use REST to get the proper registration token to be used to register a server into AMC. There are directions on the page:
To register a server you must first authenticate against the Anypoint Platform Authentication Manager and get an authentication token, with this token you need to obtain a registration token to be used to register a server into AMC.
I understand the first part and can get the authentication token, but I can't find a reference to how to get the registration token.
How can I get this token?
Thanks!
have you seen the Obtain the Server Registration Token part in the documentation?
take a look here, if you want to obtain a registration token by calling the REST API. There is a API endpoint called /servers/registrationToken
You can also get a registration token with the new anypoint-cli v2.x. This will combine several REST API calls for you. The command is:
runtime-mgr server token
You can type this in the interactive shell, or add this to the end of a stand-alone call from your favorite scripting environment. For example, if you have created a profile with your ANYPOINT_USERNAME, ANYPOINT_PASSWORD, and ANYPOINT_ORG, and ANYPOINT_ENV, you can then call:
anypoint-cli runtime-mgr server token
You can find the docs and installation instructions here: docs.mulesoft.com/runtime-manager/anypoint-platform-cli#runtime-mgr-server-token.
If you want to do this directly with the REST API, you'll have to make several calls:
POST a core services access_token from
anypoint.mulesoft.com/accounts/login
with the username and password in the BODY as a JSON object.
curl -X POST \
anypoint.mulesoft.com/accounts/login \
-H 'content-type: application/json' \
-d '{
"username":"yourUserName",
"password":"yourPassword"
}'
Store the response as a variable (let's call it {{access_token}}.
Copy this access_token in the header for every other API call: Key: Authorization, Value: bearer {{access_token}}
Obtain or store the organization ID in which you want to register the server. There's several ways to do this. The value is available via a GET request to
anypoint.mulesoft.com/accounts/api/me
curl -X GET \
anypoint.mulesoft.com/accounts/api/me \
-H 'authorization: bearer aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
You might want to use the JQ libraries to parse the organizationID from this JSON response.
Get the environment ID for the environment in which you want to register the Mule runtime (server) from a GET request to:
anypoint.mulesoft.com/accounts/api/organizations/{{organizationId}}/environments
curl -X GET \
https://anypoint.mulesoft.com/accounts/api/organizations/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb/environments \
-H 'authorization: bearer aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' \
-H 'content-type: application/json'
Make a GET request to
anypoint.mulesoft.com/hybrid/api/v1/servers/registrationToken
With the headers X-ANYPNT-ORG-ID and X-ANYPNT-ENV-ID set:
curl -X GET \
anypoint.mulesoft.com/hybrid/api/v1/servers/registrationToken \
-H 'authorization: bearer aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' \
-H 'x-anypnt-env-id: cccccccc-cccc-cccc-cccc-cccccccccccc' \
-H 'x-anypnt-org-id: bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
This will return a registration token.
Then use this registration token with the amc_setup -H command
amc_setup -H {{registration_token}} Server-Name