Zabbix API Error when Calling from Cherwell - api

I am looking at getting Cherwell talking to Zabbix but stumbling at what I understand is the easiest starting point. I have a user setup in Cherwell as part of the webservice which I have confirmed I can log into Zabbix with.
As part of the web call I am performing the basic Zabbix version check.
{
"jsonrpc": "2.0",
"method": "apiinfo.version",
"params": {},
"id": 1
}
I am getting a -32600 error, Invalid Request, data: the received JSON is not a valid JSON-RPC request.
From what I have read you should be able to do this even if you are not authenticated.
I am though getting back a result code of 200 which means the connection is solid but just not returning what I am expecting.
Thanks

That error usually means the double quotes are missing, missplaced, or escaped in a wrong way. The code by itself is fine.
#API_URL=https://.../zabbix/api_jsonrpc.php
#CONTENT_TYPE=Content-Type: application/json-rpc
{
"jsonrpc": "2.0",
"method": "apiinfo.version",
"id": 1,
"params": {}
}

Related

Rest API for Authentication with nHost

So I know there's several SDK packages for many languages available for nHost, however I need to create my own interface to the system since the language I'll be using isn't typical.
I basically just need to know how to interact with authentication endpoints, send a users un/pw and recieve a JWT token. I've been successfully able to do this with aws Cognito, but I'd like to explore this instead.
I'm also not sure if I'm using the right base url, here's my thought so far:
https://kbvlufgpikkxbfkzkbeg.nhost.run/auth/login
So I would POST to there with some json in the body with the un/pw stuff, and the response should be the jwt token right?
I get a "resource does not exist" response from the above, however, so obviously I'm not forming the url correctly in the first place.
Thanks for the help!
Nhost supports multiple sign-on methods.
For example, using the email+password method, you would send:
POST https://xxxxxxxxxxxxx.nhost.run/v1/auth/signin/email-password
{"email":"foo#example.com","password":"bar"}
and the response:
{
"session": {
"accessToken": "somejwt....",
"accessTokenExpiresIn": 900,
"refreshToken": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"user": {
"id": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"createdAt": "2022-09-17T19:13:15.440221+00:00",
"displayName": "foo#example.com",
"avatarUrl": "",
"locale": "en",
"email": "foo#example.com",
"isAnonymous": false,
"defaultRole": "user",
"metadata": {},
"emailVerified": true,
"phoneNumber": null,
"phoneNumberVerified": false,
"activeMfaType": null,
"roles": [
"user",
"me"
]
}
},
"mfa": null
}
The JWT is short-term, when it expires, the refresh token is used to get a new one.
The Nhost JavaScript SDK handles it automatically for you, that's a big benefit to the platform (in addition to being integrated with Hasura). If you are trying to port it to another unsupported language, you'd have to reimplement it. Probably by reading the library and/or running one of their sample client application and reverse-engineering the HTTP over the wire.

Strapi API register returning a 400 error

I’ve been creating a web app with a login and a registration function and so far everything has been going great. I managed to connect the app to the api/auth/local api endpoint and send some nice post requests.
Now, I’ve been trying to send requests to the http://localhost:1337/api/auth/local/register endpoint and without any success. I’ve been doing this according to:
https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#registration
I keep getting a 400 error:
{
"data": null,
"error": {
"status": 400,
"name": "ApplicationError",
"message": "An error occurred during account creation",
"details": {
}
}
}
If I try to send a request with an email that’s already registered in strapi, the response will give me the correct error:
{
"data": null,
"error": {
"status": 400,
"name": "ApplicationError",
"message": "Email is already taken",
"details": {
}
}
}
In the public and authenticated user roles, I’ve allowed every single one of them, for now.
Enable confirmation emails are set to false.
Email confirmation
Public user permission
For the headers, I’m using Content-type : application/json
the raw json body I'm posting:
{
"email": "manager1#strapi.io",
"password": "testtest1",
"username": "manager1"
}
This is my first project with strapi and so far it went pretty well. I’m not sure if I’m missing out on something or if I’m doing something else wrong.
Any help is appreciated!
I figured it out, it wasn’t as complicated as I expected.
In the user I had different fields, like firstName, lastName etc. All of these fields were required.
I made the fields not required, and now it works.

kucoin websocket api, how to "subscribe" to their public channel, they say no authorization required, but they ask for a token :(

The question is about kucoin websocket public channel (not trades) just last trades
I just want a live feed of trades like other crypto exchanges...
but when I want to connect to "wss://ws-api-futures.kucoin.com/endpoint" I get WebSocketError: Received unexpected status code (401 Unauthorized)
the documentation https://docs.kucoin.com/futures/#create-connection lack explications :(
normally with other exchanges I can just do this in javascript
bybit_market_ws = new WebSocket("wss://stream.bybit.com/spot/quote/ws/v2");
bybit_market_ws.onmessage = event => bybit_trades(event.data);
bybit_market_ws.onopen = event => bybit_market_ws.send(JSON.stringify({"topic":"trade","params":{"symbol":"BTCUSDT","binary":false},"event":"sub"}));
function bybit_trades (jsonx) { console.log(JSON.parse(jsonx)); }
so how can I do that with kucoin websocket ?
according to the documentation i would need a "public token"...
but there is no explication on how to get that token :(
does someone knows how I would retrieve the last trades via websocket (public) channel ?
Note that the following steps may be changed when the API is updated.
All information can be found at https://docs.kucoin.com/#apply-connect-token
Get the public token
Send a empty http POST (GET will not work) message to https://api.kucoin.com/api/v1/bullet-public.
Response:
{
"code": "200000",
"data": {
"token": "2neAiuYvAU61ZD...",
"instanceServers": [
{
"endpoint": "wss://ws-api.kucoin.com/endpoint",
"encrypt": true,
"protocol": "websocket",
"pingInterval": 18000,
"pingTimeout": 10000
}
]
}
}
Connect to the Websocket
With the data of the repsonse above:
websocket: endpoint + "?token=" + token
Example: wss://ws-api.kucoin.com/endpoint?token=2neAiu....
Get all supported trading pairs
send a http GET message to https://api.kucoin.com/api/v1/symbols
{
"code": "200000",
"data": [
{
"symbol": "REQ-ETH",
"name": "REQ-ETH",
"baseCurrency": "REQ",
"quoteCurrency": "ETH",
...
},
{
"symbol": "BTC-USDC",
"name": "BTC-USDC",
"baseCurrency": "BTC",
"quoteCurrency": "USDC",
...
},
...
Get trading data
When the websocket connection is established send a http POST message:
{
"type": "subscribe", //subscribe or unsubscribe
"topic": "/market/ticker:BTC-USDT,BTC-USDC"
}
maybe this answer will not please you at all, but i will try, most of the people who work from the API in KuCoin do it with python, in fact the SDK for Nodejs is out of date, your best bet is to ask in the telegram channel https://t.me/KuCoin_API, there are KuCoin engineers who always help, although most of them use python, there is also the academy channel https://t.me/kucoin_learning, where there are examples, in short I can only mention references because I was also where you are, and the best I could do was that and review the SDk code and from there intuit and create my own adjustments
PD: the datafeed.js file is your best option, check it out https://github.com/Kucoin/kucoin-futures-node-sdk/blob/master/src/lib/datafeed.js

HTTP 500 on Podio GET item

When fetching GET https://api.podio.com/item/1259778758 (other items work fine), I get the following error:
HTTP 500
with response body:
{
"error_parameters": {},
"error_detail": null,
"error_propagate": false,
"request": {
"url": "http://api.podio.com/item/1259778758",
"query_string": "",
"method": "GET"
},
"error_description": "An unexpected error occured during execution",
"error": "unexpected"
}
I assume this is due to some field value, but cannot figure this out. Can you please check an fix this?
Additional notes:
It is not possible to open this item in the browser as well
The filter operation in the API fails as well when this item is in the result.
It sounds like this should be escalated with Podio technical support.

JSON RPC 2.0 standard responses

I am currently looking into implementing some JSON RPC 2.0 responses in my code. However, I'm a little unclear on what are the standard practices of using it:
1) When the user sends a request with invalid parameters, should I just return verbatim default error message
{"jsonrpc": "2.0", "error": {"code": -32602, "message": " Invalid params"}, "id": "1"}
Or can the message be more specific, like:
{"jsonrpc": "2.0", "error": {"code": -32602, "message": " Invalid params: invalid username"}, "id": "1"}
Or should such custom messages have their own error code?
2) If the user say, requests data from the database and the response is "data is not present", as in we encountered no errors but still didn't return anything, should that be returned as a JSON RPC error, or should it be more of response indicating data wasn't found? In other words, is the convention in JSON RPC to use errors as normal return conditions like in Google Go, or is it more akin to "something really messed up" panics?
According to the specification (http://www.jsonrpc.org/specification#error_object) you must use the optional property data for your additional information about the error, so, in your case the response must be:
{"jsonrpc": "2.0", "error": {"code": -32602, "message": " Invalid params", "data":"invalid username"}, "id": "1"}
You can create your own personal error codes in the range -32000 to -32099, but I would do it only when necessary, that is, unless your client application should behave in this case ("invalid username") different than in any other -32602 case.
That is up to you. It is a design question with a broader scope than JSON-RCP. You can find some opinions at this post: when-to-throw-an-exception