MongooseIM REST API's not working for POST requests - api

Have anyone tried the MongooseIM 2.0.0 Bets services to hit web services.
I am able to to the GET calls as defined in this Swagger site link but unable to get the POST request as it gives me error for the same data that I use with my IP address instead of localhost.
Here in my Mongoose Im error response.
] emulator Error in process <0.4026.0> on node mongooseim#localhost
with exit value:
{{nocatch,[{reason,{error,{3,invalid_json}}},{mfa,{mongoose_api_admin,from_json,2}},{stacktrace,[{jiffy,decode,2,[{file,"src/jiffy.erl"},{line,68}]},{mongoose_api_common,parse_request_body,1,[{file,"src/mongoose_api_common.erl"},{line,169}]},{mongoose_api_admin,from_json,2,[{file,"src/mongoose_api_admin.erl"},{line,114}]},{cowboy_rest,call,3,[{file,"src/cowboy_rest.erl"},{line,976}]},{cowboy_rest,process_content_type,3,[{file,"src/cowboy_rest.erl"},{line,777}]},{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,442}]}]},{req,[{socket,#Port<0.35385>},{transport,ranch_tcp},{connection,keepalive},{pid,<0.4026.0>},{method,<<"POST">>},{version,'HTTP/1.1'},{peer,{{118,200,26,4},1036}},{host,<<"ec2-54-111-111-111.ap-southeast-1.compute.amazonaws.com">>},{host_info,undefined},{port,8090},{path,<<"/api/messages">>},{path_info,undefined},{qs,<<>>},{qs_vals,undefined},{bindings,[]},{headers,[{<<"host">>,<<"ec2-54-111-111-111.ap-southeast-1.compute.amazonaws.com:8090">>},{<<"user-agent">>,<<"curl/7.49.1">>},{<<"content-type">>,<<"application/json">>},{<<"accept">>,<<"application/json">>},{<<"content-length">>,<<"208">>}]},{p_headers,[{<<"content-type">>,{<<"application">>,<<"json">>,[]}},{<<"if-modified-since">>,undefined},{<<"if-none-match">>,undefined},{<<"if-unmodified-since">>,undefined},{<<"if-match">>,undefined},{<<"accept">>,[{{<<"application">>,<<"json">>,[]},1000,[]}]}]},{cookies,undefined},{meta,[{media_type,{<<"application">>,<<"json">>,[]}},{charset,undefined}]},{body_state,waiting},{buffer,<<"{
\ \n \"caller\":
\"+6512345699#ec2-54-111-111-111.ap-southeast-1.compute.amazonaws.com\", \ \n \"to\":
\"+6512345678#ec2-54-111-111-111.ap-southeast-1.compute.amazonaws.com\", \ \n \"body\": \"Hi Rabbit!\" \ \n
}">>},{multipart,undefined},{resp_compress,false},{resp_state,waiting},{resp_headers,[{<<"content-type">>,[<<"application">>,<<"/">>,<<"json">>,<<>>]}]},{resp_body,<<>>},{onresponse,undefined}]},{state,{http_api_state,[<<"GET">>,<<"POST">>,<<"POST">>,<<"GET">>,<<"POST">>,<<"GET">>,<<"POST">>,<<"POST">>,<<"POST">>,<<"GET">>,<<"GET">>,<<"DELETE">>,<<"DELETE">>,<<"POST">>,<<"DELETE">>,<<"POST">>,<<"PUT">>],[],undefined,<<"messages">>,undefined,admin,[]}}]},[{cowboy_rest,process_content_type,3,[{file,"src/cowboy_rest.erl"},{line,777}]},{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,442}]}]}
2016-11-02 05:25:37.428 [error] <0.4026.0> Ranch listener
'ejabberd_cowboy_166.36.16.166_8090' terminated with reason:
{nocatch,[{reason,{error,{3,invalid_json}}},{mfa,{mongoose_api_admin,from_json,2}},{stacktrace,[{jiffy,decode,2,[{file,"src/jiffy.erl"},{line,68}]},{mongoose_api_common,parse_request_body,1,[{file,"src/mongoose_api_common.erl"},{line,169}]},{mongoose_api_admin,from_json,2,[{file,"src/mongoose_api_admin.erl"},{line,114}]},{cowboy_rest,call,3,[{file,"src/cowboy_rest.erl"},{line,976}]},{cowboy_rest,process_content_type,3,[{file,"src/cowboy_rest.erl"},{line,777}]},{cowboy_protocol,execute,4,[{file,...},...]}]},...]}
in cowboy_rest:process_content_type/3 line 777

This was probably answered here: https://github.com/esl/MongooseIM/issues/1055 already. Am I right?

Related

How to query SFTP server with Karate via API?

The app that I am trying to test has an SFTP server that can be queried via API. Swagger shows the following sample cURL request to get domain files information, and I am having a hard time making this call with Karate:
curl -X GET -H 'Accept: application/json' 'https://{host}:{port}/api/{clientId}/'
I do the following where baseUrl is defined as https://sftp.mydomain.com:22 where 22 is the port number that I can successfully use to connect to the SFTP server via Cyberduck:
Feature:
Background:
* url baseUrl
* def moduleBase = '/api/12345/'
Scenario:
* path moduleBase
When method get
Then status 200
The error that I get is this:
ERROR com.intuit.karate - src/test/java/mytest.feature:9
When method get
http call failed after 815 milliseconds for url: https://sftp.mydomain.com:22/api/12345/
What am I doing wrong?
Clearly it may not be HTTP so I don't think Swagger and all is legit.
Maybe you can just delegate to the OS. Refer: https://stackoverflow.com/a/64352676/143475

api fetching works in chrome brower, but doesn't work in terminal using "curl"

I'm trying to use open weather API, I just created an account and got my API key, after I wrote https://api.openweathermap.org/data/2.5/weather?q=London&appid=<--myapikey-->
in zsh, it returns:
[1] 12567 zsh: no matches found:
https://api.openweathermap.org/data/2.5/weather?q=London
jack#jackengtwistios-Mac-mini node-andrew % [1] + exit 1 curl
https://api.openweathermap.org/data/2.5/weather?q=London
in bash:
[1] 12715 jackengtwistios-Mac-mini:node-andrew jack$ {"cod":401,
"message": "Invalid API key. Please see
http://openweathermap.org/faq#error401 for more info."}
but in chrome brower it just returns the expected result:
{"coord":{"lon":-0.1257,"lat":51.5085},"weather":[{"id":800,"main":"Clear","description":"clear
sky","icon":"01d"}],"base":"stations","main":{"temp":279.99,"feels_like":279.99,"temp_min":278.87,"temp_max":280.86,"pressure":1017,"humidity":72},"visibility":10000,"wind":{"speed":0.45,"deg":331,"gust":2.24},"clouds":{"all":7},"dt":1637851503,"sys":{"type":2,"id":2019646,"country":"GB","sunrise":1637825718,"sunset":1637856008},"timezone":0,"id":2643743,"name":"London","cod":200}
OP shows that this URL works in Chrome:
https://api.openweathermap.org/data/2.5/weather?q=London&appid=<--myapikey-->
But this is what is being used in cURL
curl https://api.openweathermap.org/data/2.5/weather?q=London
It's missing the appid parameter

Found error 'CRASH REPORT Process' on RabbitMQ in every 10 mins

I found error on RabbitMQ in every 10 mins. Please help me to investigate this problem.
Error message.
021-09-09 13:25:30.084 [error] <0.14464.32> CRASH REPORT Process <0.14464.32> with 0 neighbours crashed with reason: no function clause matching rabbit_mgmt_wm_node:find_type(rabbit#controller1, []) line 79
2021-09-09 13:25:30.085 [error] <0.14457.32> Ranch listener rabbit_web_dispatch_sup_15672, connection process <0.14457.32>, stream 1 had its request process <0.14464.32> exit with reason function_clause and stacktrace [{rabbit_mgmt_wm_no
I had the same issue with Zabbix monitoring the RabbitMQ server every minute which generated a crash-error with the same frequency.
The URL used by Zabbix to monitor contained a domain part to the node name ie. rabbit#my_host.zzz.aws instead of the actual node name as displayed by the console: rabbit#my_host. this explains why rabbit_mgmt_wm_node:find_type failed and crashed.
This was verified using curl as shown below:
curl -v -u user:passwd 'http://127.0.0.1:15672/api/nodes/rabbit#my_host?memory=true'
which returned a valid response, HTTP/1.1 200 OK, when the node name matched and the crash/error when it did not.
please refer to this thread:
https://groups.google.com/g/rabbitmq-users/c/N0EgrLn55XQ

Node-RED Handle error from node that throws no standardexception

I want to use the Pushover Node to send notifications. I'm already using it via curl for some time and very seldom some messages aren't sent. Thats why I have in bash
echo "$curlOutput" | grep -qP '{"status":1'
if [ ! $? -eq 0 ]
then
echo "$2" | mail --append "Content-Type: text/plain; charset=UTF-8" -s "$1" name#company.com
fi
to capture the error and then send the message via email.
Now I want to do something similiar in Node-Red. For testing purposes if simulated a network error via sudo iptables -A OUTPUT -d 104.20.0.0/16 -m comment --comment "Pushovertest" -j REJECT
That successfully blocks. In node-red-log I see
18 May 13:46:24 - [error] [pushover:252a17dc.1239d8] Error: connect
ECONNREFUSED 104.20.125.71:443
Now look at this Node-RED flow
The error is displayed in the debug window and comes from pushover node. The catch node doesn't catch the expection, obviously because pushover doesn't use the exception framework https://developer.ibm.com/recipes/tutorials/nodered-exception-handling-framework/
First test passed: There is an error logged. But how can I react to this error within Node-RED to do something else in this case?
I'll guess from looking at the source that the error is coming from line 103
of the 57-pushover.js file.
The call to node.error() on this line is not pushing the incoming msg object so it won't be passed to the catch node. There are 2 signatures for the node.error() function, the first just takes the error message, the second takes the error message and the incoming msg object, only the second forwards the error and msg object is passed to the catch node.
Please feel free to submit a pull request to update this node.

NiFi- how to http post a PDF document

I wanted to use NiFi's posthttp/invokeHttp processor to post a PDF to an API.
But considering the following cURL request to replicate in NiFi:
curl -X POST "http://ipaddress:port/api/" -H "accept: application/json" -H
"Content-Type: multipart/form-data" -F "pdf_file=#sample.pdf;
type=application/pdf"
Which property takes the -F information in nifi attributes?
Configuration for invokehttp right now:
error:
"400 Bad Request: The browser (or proxy) sent a request that this server could not understand."
Configration for posthttp right now:
error:
server logs: readv() failed (104: Connection reset by peer) while reading upstream
In older version of nifi you will have to use your own script to build a multipart request and then use invoke to create post request. You can refer to this post for a ExecuteGroovyScript example.
https://stackoverflow.com/a/57204862
Since Nifi 1.12 you can directly use invokeHTTP by setting content-type
https://stackoverflow.com/a/69284300
When you use PostHttp/InvokeHttp you wouldn't be referencing an external file, you would be sending the content of the flow file. So you would first need to bring sample.pdf into NiFi by using GetFile or ListFile/FetchFile and then flow file coming out of those processors represents the PDF, and you would route that flow file to InvokeHttp which would POST the content of the flow file (the pdf).