I am using Grafana with infinity datasource. From infinity datasource, it communicates to the spring boot REST API to get the details.
I want to show the custom message when any issue occurs on the Grafana webpage.
When I use the curl command, it displays a custom error message like the one below.
curl -X POST http://127.0.0.1:8000/v1/defReport -H 'Content-Type: application/json' -d '{select * from device}'
{"message":"Add entry for host in pg_hba.conf file in Database","errorCode":"500"}%
I get the same response from Postman.
But in the Grafana, It says "error getting data frame. 500". What is the way to get the custom error message when using Grafana?
Related
I have a lambda running on AWS that processes a JSON file. I'd like to pass that JSON file from the command line using curl through a REST interface configured on an API gateway, e.g.
curl -X POST -H "x-api-key: MyAPIKey" -H "Content-Type: application/json" -d #myFile.json https://my-api.us-east-1.amazonaws.com/default/MyLambda
I've created an API gateway, and added it as a trigger for the lambda, but when the request method is triggered, the content of the JSON file has been added to the "body" attribute of a JSON object.
Is it possible to pass the file directly to the lambda?
If you are getting the request in the event.body, it implies that you are using the Lambda Proxy integration.
What you are looking for is known as non-proxy integration or Custom Integration. More details on how to set that up here. Uncheck this option. Then you will have to configure the request and response mapping templates.
If the json looks like the following -
{
"attr1": "v1",
"attr2": "v2"
}
then your mapping template for application/json will look like this -
#set($inputRoot = $input.path('$'))
{
"attr1": "$inputRoot.attr1",
"attr2": "$inputRoot.attr2",
}
Then in the Lambda function, attributes can directly be accessed as event.attr1, event.attr2 etc.
Then you can use the same cURL command to call the API Gateway.
I have a 3rd party REST, which I am successfully able to call like this using CURL (shell). This API return JSON. I tried calling same API, by changing content type to application/x-www-form-urlencoded but it doesn't work. I think I am forced to use content-type: multipart/form-data
curl --request POST --url https://************************* --header 'Authorization: Bearer ********' --header 'content-type: multipart/form-data; ' --form cluster_id=0717-035521-puny598 --form start_time=1534357800000 --form end_time=1534444199999 --form order=ASC --form limit=500
Now I want to call same API using InvokeHTTP processor (NiFi). So I configured it as follows. But I am not able to do a successful call. (it is not a proxy issue).
Following is how I am creating POST body (by FF)
I have tried replacing "enter" by \r\n etc, or changing body as name1=val1&name2=val2&.... etc. nothing worked.
This is the response I am getting.
[
I am able to run CURL (shell, from same server where Nifi is running). Also I am able to access url via postman.
[
finally, it worked. flow is somewhat like this.
GenerateFlowFile->UpdateAttribute->AttributesToJSON->InvokeHTTP
Only change, I made to InvokeHTTP. reverted content-type back to ${mime.type}.
I was struggling with this for a few hours. I've got a backend API that has
ResponseEntity<ByteArrayResource> post (#RequestPart("file") MultipartFile file) and a NiFi processor that sends XLSX data to this. I was getting the same issue... The key for me were the bottom two properties:
FlowFile Form Data Name -> file (this is the name of the variable in the API call)
Set Flowfile Form Data File Name -> true
The reason was that I was logged in to WP.
Looking for a reason here: WooCommerce REST API Authentication fails when logged in
I am trying to connect to Woocommerce REST API using Ajax (to read product data)
The following URL ...
https://example.com/wp-json/wc/v1/products/1744?consumer_key=ck_xxx&consumer_secret=cs_xxx
... gives me this error:
{"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot view this resource.","data":{"status":401}}
I also tried the same using CURL like:
curl https://example.com/wp-json/wc/v1/products/1744 \
-u ck_xxx:cs_xxx
And got the same error.
What could be wrong here?
The key is read only.
I am quite sure the error means that everything is ok but there's an issue with authentication.
Entering exactly the same information into Advanced REST Client Chrome extension gives me exactly what I am looking for. Why is it not working with CURL or Ajax?
Even just pasting the URL at http://onlinecurl.com/ gets me 200 OK
EDIT: Got the CURL working like this:
curl -XGET 'https://example.com/wp-json/wc/v1/products/30552?consumer_key=ck_xxx&consumer_secret=xxx'
Have implemented oauth2 and it works fine as long as I am using clients.inMemory in my authorization server config. When i change it to clients.jdbc, and provide the datastore, the first step of getting a oauth2 token succeeds. The second step of using that token always fails. Even though for the in memory code snippet, both steps work. so with jdbc, i am unable to reach my rest end point. I get error. The following works
curl -u ksclient:top_secret -X POST http://localhost:8080/oauth/token -H "Accept:application/json" -d "username=mickey&password=cheese&grant_t
ype=password"
The result:
{"access_token":"4e6a6ff2-87e9-428d-9a80-13f0300a7344","token_type":"bearer","expires_in":43016,"scope":"read write"}
Then the second step of using it fails
curl http://localhost:8080/oauth2/hello -H "Authorization: Bearer 4e6a6ff2-87e9-428d-9a80-13f0300a7344"
The error:
{"error":"invalid_token","error_description":"Invalid access token: 4e6a6ff2-87e9-428d-9a80-13f0300a7344"}
What is interesting that on the mysql side the table for "oauth_client_details" does have the data whereas the table for "oauth_client_token"/"oauth_access_token" never has any records.
Here is the link to my code
https://github.com/ksachdev1/springbootlearning
I am new to Spring and very new to Spring Oauth2 Security. I have searched a lot about how to request the following link in web browser(In Firefox Rest Client plugin).The following request is curl and working perfectly fine in terminal through this command.
I am getting the problem while giving basic authorization. So How we can interact with basic authorization given below as -vu myapp:123456.
curl -X POST -vu myapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=sunit&username=sunit&grant_type=password&scope=read%20write&client_secret=123456&client_id=myapp"
I used wireshark for capture the request and ended the same request to fb just to connect because I don't have a local server running... you can see that is a post request with the body in encoded URL...