Thingsboard RestApi - returns 500error - thingsboard

I am working to get data from the Things board ( version 2.3.2) using REST API. The Thingsboard server is installed on AWS instance. When I use the Swagger UI, on my instance, to get the attributes of my device/asset, I always get the following error:
{
"timestamp": "2019-06-28T14:33:26.909+0000",
"status": 500,
"error": "Internal Server Error",
"message": "No message available",
"path": "/api/plugins/telemetry/ASSET/b3f29330-890d-11e9-ab17-81c76d54ccfd/keys/attributes"
}
The /var/log/thingsboard/thingsboard.log file shows a Java null pointer exception:
2019-06-28 14:33:26,908 [http-nio-0.0.0.0-8081-exec-24] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in conte
xt with path [] threw exception
java.lang.NullPointerException: null
at org.thingsboard.server.service.security.model.token.JwtTokenFactory.parseAccessJwtToken(JwtTokenFactory.java:113)
at org.thingsboard.server.service.security.auth.jwt.JwtAuthenticationProvider.authenticate(JwtAuthenticationProvider.java:42)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:175)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:200)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$AuthenticationManagerDelegator.authenticate(WebSecuri
tyConfigurerAdapter.java:503)
I get the same error when I use any of the REST API. Please note that there are no authentication/token issues.
I did not find any references in the documentation or github issues. Is there something else that I should be doing or is this a bug?

I have the same problem when I using /api/device API for creating device.
I used the value of key "refreshToken" in authentication header . I replaced it with the value of the key "token" and every thing works fine.
NOTE : when you call this API for getting JWT-token :
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"username":"tenant#thingsboard.org", "password":"tenant"}' 'http://THINGSBOARD_URL/api/auth/login'
it gives you two things:
{"token":"$YOUR_JWT_TOKEN", "refreshToken":"$YOUR_JWT_REFRESH_TOKEN"}
you should use "$YOUR_JWT_TOKEN" .

Related

Create organizationalBrandingProperties

I'm trying to create Organizational branding via Graph API
Unfortunately it doesn't work as documented
curl --fail-with-body --silent --show-error --oauth2-bearer TOKEN -X PUT -H 'Content-Type: application/json' -d #- https://graph.microsoft.com/v1.0/organization/7c9674e7-ad41-482b-af13-fff7ba1c38f6/branding <<< '{
"backgroundColor":"#FFFF33",
"signInPageText":"Welcome",
"usernameHintText":"hint"
}'
{
'error': {
'code': 'Request_BadRequest',
'message': 'Specified HTTP method is not allowed for the request target.',
'innerError': {
'date': '2021-04-21T12:59:57',
'request-id': 'a5ce577c-d0a9-4888-9999-521d7ba452b1',
'client-request-id': 'a5ce577c-d0a9-4888-9999-521d7ba452b1'
}
}
neither PATCH works:
curl --fail-with-body --silent --show-error --oauth2-bearer TOKEN -X PATCH -H 'Content-Type: application/json' -d #- https://graph.microsoft.com/v1.0/organization/7c9674e7-ad41-482b-af13-fff7ba1c38f6/branding <<< '{
"backgroundColor":"#FFFF33",
"signInPageText":"Welcome",
"usernameHintText":"hint"
}'
{
"error": {
"code": "Request_ResourceNotFound",
"message": "Resource '7c9674e7-ad41-482b-af13-fff7ba1c38f6' does not exist or one of its queried reference-property objects are not present.",
"innerError": {
"date": "2021-04-21T13:07:43",
"request-id": "c2c7056b-0043-40cb-82b8-6d262f190005",
"client-request-id": "c2c7056b-0043-40cb-82b8-6d262f190005"
}
}
I tried opening an Azure support request but they told me
The AAD Developer queue is experiencing a very high number of requests.
Please expect a delay in the assignation as the cases are assigned considering case severity, time in queue, customer service level and business impact.
Since Azure support has proven to be useless yet again, maybe somebody here would be able to help me? :)
Based on my test, I have the same error when I use PUT method.
But PATCH works fine for me.
id should be the organization id or tenant id.
Please get the id first with
GET https://graph.microsoft.com/beta/organization/
Then use the id for PATCH method:
PATCH https://graph.microsoft.com/v1.0/organization/{id}/branding
Content-Type: application/json
Content-Language: en-US
{
"backgroundColor": "#FFFF33",
"signInPageText": "Welcome",
"usernameHintText": "hint"
}
Update:
Application token is not supported for this endpoint. See Permissions.
Microsoft support finally responded (after 2 months!) with
Application Permission are currently not supported on this
endpoint, meaning that you will need an on-behalf of user token with
Delegated permissions to use this endpoint.
Since your goal was to automate this process, one workaround that
sometimes is feasible is to have a dedicated user in your tenant to
perform those actions, and that will authenticate with ROPC flow. This
flow allows to directly send the credentials information (username and
password) and because of that does not require an UI or interaction.
There is currently a known issue regarding the GET and PATCH method for the branding endpoint that is already reported and the fix
is in progress. This issue will cause an 404 error mentioning that the
tenant resource is not found.
Issue seems to be with locale being used, If you wish to get/update
the default branding, can you please try to include an header with
Accept-language as 0 (shown in the below image), if you want to get
branding for any other locale, you’ll need to pass the valid ISO-639
locale.

calling activities:list fails on using parameter `mine=true` (Youtube Data API V3)

I have been trying to use the API to retrieve my activities but I'm receiving the following JSON error.
{
"error": {
"code": 403,
"message": "The request is not properly authorized.",
"errors": [
{
"message": "The request is not properly authorized.",
"domain": "youtube.activity",
"reason": "forbidden"
}
]
}
}
, although I use https://www.googleapis.com/youtube/v3/activities?mine=true&key={my_api_key}&part=contentDetails and I use OAuth2 client to get an access token which I use on calling the API.
I tried to use the samples but I'm receiving the same error.
Is this a bug or I'm doing something wrong?
More details
I use the given link in postman with the GET method and I put a valid access token in the token field with TYPE=OAuth2 and Prefix=Bearer
According to the official specification of the Activities.list API endpoint, for to be able to use its mine request parameter, you have to issue the call to the endpoint while passing to it proper credentials:
mine (boolean)
This parameter can only be used in a properly authorized request. Set this parameter's value to true to retrieve a feed of the authenticated user's activities.
Therefore, using an API key is not sufficient (neither is required when issuing a properly authorized request).
Do note that the JSON error response obtained from the API agrees entirely with the specification quoted above.
According to the official (programming language agnostic) procedure, for to obtain a valid fresh access token from the API, issue a simple curl instance as follows:
$ curl \
--data 'grant_type=refresh_token' \
--data-urlencode "client_id=$CLIENT_ID" \
--data-urlencode "client_secret=$CLIENT_SECRET" \
--data-urlencode "refresh_token=$REFRESH_TOKEN" \
https://oauth2.googleapis.com/token
Above, $CLIENT_ID and $CLIENT_SECRET are the values of the corresponding properties of your client secrets JSON file you've got from Google's developers console. The $REFRESH_TOKEN is your (long-lived) refresh token you've obtained upon running a successful OAuth2 authentication/authorization flow.
The output obtained from curl when successful would look like:
{
"access_token": "...",
"expires_in": 3599,
"scope": "...",
"token_type": "Bearer"
}
A call to the Activities.list endpoint as yours above using curl is immediate:
$ curl \
--header "Authorization: Bearer $ACCESS_TOKEN" \
'https://www.googleapis.com/youtube/v3/activities?mine=true&part=contentDetails&maxResults=25'
The parameter $ACCESS_TOKEN above is your freshly obtained valid access token; the output of curl would look like:
{
"kind": "youtube#activityListResponse",
"etag": "...",
"items": [
{
"kind": "youtube#activity",
"etag": "...",
"id": "...",
"contentDetails": {
...
}
},
...
],
"pageInfo": {
"totalResults": ...,
"resultsPerPage": 25
}
}
For to run the above curl commands on a Windows machine under CMD.exe -- assuming that you've substitued the $-variables yourself manually --, do replace the backslash character at the end of each line above with the caret character, ^. The percent character % should be doubled, i.e. should be replaced with %%, and the single quote characters ' should be replaced with double-quote characters ".

Monitoring connectivity for Slack and PagerDuty

We are using PRTG to monitor a number of internal resources, and we have set it up to alert us on a Slack channel and/or via PagerDuty (depending on severity) using their respective APIs. Considering that Slack and PagerDuty are external to us, we would also like to monitor whether our PRTG instance can access them -- basically, a form of self-monitoring or Who Watches the Watchmen?
So far the only reliable method we've found for Slack is to post an actual message to a private "testing" Slack channel, e.g. (Slack URL details redacted):
POST https://hooks.slack.com/services/XXX/YYY/ZZZ
Content-Type: application/json
{ "text": " ", "channel": "#prtg-webhook-test" }
Similarly, PagerDuty's Events API appears to be POST only, and the valid actions are limited to trigger, acknowledge, and resolve:
POST https://events.pagerduty.com/v2/enqueue
Content-Type: application/json
Is there a good way to test HTTPS connectivity without posting an actual Slack message / creating an actual PagerDuty alert? I couldn't find anything in documentation for either service, or a creative way to create an appropriate sensor in PRTG.
For Slack you might rather want to make an call to the API, not to a webhook.
I would recommend using auth.test, since its one of the few methods that has no rate limit.
Also, for the whole Slack service you can see the current status on this official webpage.
For pure connectivity, you can do a POST against the Events API with an empty payload, and you'll get an error message back:
curl --location --request POST 'https://events.pd-staging.com/v2/enqueue' \
--header 'Content-Type: application/json' \
--data-raw '{}'
{
"status": "invalid event",
"message": "Event object is invalid",
"errors": [
"'event_action' is missing or blank",
"'routing_key' must be provided in the body, or provided in the headers using 'x-routing-key'"
]
}
If you'd also like to validate your routing key, you can send an acknowledge event with a dummy dedup_key:
curl --location --request POST 'https://events.pd-staging.com/v2/enqueue' \
--header 'Content-Type: application/json' \
--header 'Cookie: uid=rBGA1lymclmSzRCsAwO3Ag==' \
--data-raw '{
"routing_key": "<your_routing_key>",
"event_action": "acknowledge",
"dedup_key": "something_that_will_never_match_an_open_incident"
}'
{
"status": "success",
"message": "Event processed",
"dedup_key": "something_that_will_never_match_an_open_incident"
}
Note that this will not show up anywhere in the PagerDuty UI, but that could be what you'd want anyways.

Youtube API V3, search , publishedAfter, invalidSearchFilter

I'm just trying to make a search over youtube for my own videos that publisher after X date
However when i use publishAfter parameter, it's giving invalidSearchFilter error even of i set type parameter as video.
Error description is like this:
The request contains an invalid combination of search filters and/or restrictions. Note that you must set the type parameter to video if you set either the forContentOwner or forMine parameters to true. You must also set the type parameter to video if you set a value for the eventType, videoCaption, videoCategoryId, videoDefinition, videoDimension, videoDuration, videoEmbeddable, videoLicense, videoSyndicated, or videoType parameters.
You can reproduce this error from: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&forMine=true&publishedAfter=1970-01-01T00%253A00%253A00Z&type=video&_h=11& (after login via oauth 2.0)
Any idea what can i do in this situation?
I used the link that you provided. The problem is not the date. The problem is the conflicting search restrictions that you used. To make your search work, leave the "forMine" parameter empty so it doesn't conflict with your date filters and possibly the 'q' parameter as well. Do that and it will work.
Also, you have to specify the channelID to specify it's yours. Give it a try
I am trying to work on a task to retrieve all the videos from our own channel, my problem with using forMine filter was, I was passing channelId filter alongside forMine filter (which actually does not make sense, if I am saying to get my own data then I should not pass channel id explicitly, so I blame myself for that), which was returning as an error saying that Request contains an invalid argument.
Here is what my request was when it was causing the error:
curl --location -g --request GET 'https://youtube.googleapis.com/youtube/v3/search?part=snippet,id&channelId=[Channel ID]&forMine=true&order=date&type=video&key=[API KEY]&maxResults=25' \
--header 'Authorization: Bearer [ACCESS TOKEN]' \
--header 'Accept: application/json'
And this was the JSON return:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
As soon as I removed the channelId query parameter, the error went away.

Failed to exchange a code for an access token for creating zendesk instance in cloud element through API

Please help to create zendesk instance in cloud element by 3rd party api call
Created Zendesk account Created & configure as per in Link
Succesfully got Elements OAuth Information
{
"oauthUrl": "https://yoursubdoamin.zendesk.com/oauth/authorizations/new?response_type=code&client_id=zendesk_unique_identifier&redirect_uri=http://www.my_cool_app.com/auth&scope=read write&state=zendesk",
"element": "zendesk"
}
Getting error in API
curl -X POST
-H 'Authorization: User <INSERT_USER_SECRET>, Organization <INSERT_ORGANIZATION_SECRET>'
-H 'Content-Type: application/json'
-d #instance.json
'https://api.cloud-elements.com/elements/api-v2/instances'
instance.json
{
"element": {
"key": "zendesk"
},
"providerData": {
"code": "Code on Return the URL"
},
"configuration": {
"oauth.api.key": "<INSERT_ZENDESK_UNIQUE_IDENTIFIER>",
"oauth.api.secret": "<INSERT_ZENDESK_CLIENT_SECRET>",
"oauth.callback.url": "https://www.my_cool_app.com",
"zendesk.subdomain": "<INSERT_ZENDESK_SUB_DOMAIN>"
},
"tags": [
"<INSERT_TAGS>"
],
"name": "<INSERT_INSTANCE_NAME>"
}
Getting error "Failed to exchange a code for an access token"
This might be because, you might not have registered an app with zendesk to get back the access token. This can also happen if your element in Cloud Elements is corrupted, make sure you are using the inbuild element instance. Still if you are facing the issue, please mention the steps you followed

Resources