How to change Rocket.Chat User Presence to online via RestApi - rest

I work with Delphi 10.2 and Rocket Chat. How can I set the User Presence from offline to online when the user logs in. The login via Delphi and Postman is success. The answer from docs is to make it via method call but I don't know how.
{
"msg": "method",
"method": "UserPresence:setDefaultStatus",
"id": "42",
"params": ["online"]
}

Looks like you are looking at the docs for the real time api. If you aren’t familiar with it or only need a one off action I would suggest just using the REST API.
curl -H "X-Auth-Token: 9HqLlyZOugoStsXCUfD_0YdwnNnunAJF8V47U3QHXSq" \
-H "X-User-Id: aobEdbYhXfu5hkeqG" \
http://localhost:3000/api/v1/users.setStatus -d '{"status": "busy"}'
This end point is actually new I think added in Rocket.Chat 1.2
Of course make sure to authenticate before hand. More info about that can be found there in the docs as well.

Related

Contacting Specific Cloud Controller API

The root of my problem is restarting a cloud_controller app with a REST call.
I'm trying to avoid making calls to pull all the necessary details from the instance, destroying it and recreating it, since I'm trying to restart a NodeRED instance that has a new flow in the cloudant db it's building itself from.
To handle this, I'm working to call a cloud controller V3 POST /v3/apps/:guid/actions/restart
Specifically, I'm looking to contact cloud_controller version: 3.63.0 instead of version: 2.128.0:
When I run cf curl / , it shows there are two cloud_controller APIs in the container I'm using:
C:\Users\RHQUB82>cf curl /
{
"links": {
"self": {
"href": "https://api.us-south.cf.cloud.ibm.com"
},
"cloud_controller_v2": {
"href": "https://api.us-south.cf.cloud.ibm.com/v2",
"meta": {
"version": "2.128.0"
}
},
"cloud_controller_v3": {
"href": "https://api.us-south.cf.cloud.ibm.com/v3",
"meta": {
"version": "3.63.0"
}
}, ...
I've tried to ask the IBM support desk to help me make REST calls specifically to the version 3.63.0 cloud_controller API, and the application UI seems able to contact it with a Restart button, but there doesn't seem to be a way to successfully get in contact with them, and I'm not certain how comfortable they are revealing the inner workings of Bluemix.
I've confirmed the POST request I'm planning to make is in version:3.63.0.
There's nothing specific to IBM environment here. It's just v3 of the Cloud Controller API, which is documented here.
http://v3-apidocs.cloudfoundry.org/version/3.63.0/
According to the information you posted, you would need to send requests to https://api.us-south.cf.cloud.ibm.com/v3. If you're using cf curl, it will do this automatically. You would just need to cf curl /v3/... and it'll do the rest.
To your question regarding restarts, that's documented here.
http://v3-apidocs.cloudfoundry.org/version/3.63.0/#app-restart
As it's documented, you could do something like this:
curl "https://api.us-south.cf.cloud.ibm.com/v3/apps/[guid]/actions/restart" \
-X POST \
-H "Authorization: bearer [token]"
Hope that helps!

Keycloak impersonation API not implemented

I've been trying to use the Keycloak Impersonation API (semi-recent addition) to get an access token for another user. I have created a semi-successful CURL request based on the docs and another StackOverflow question. The CURL request (below) returns a 501 Not Implemented and I am trying to figure this out. If it would be another error I would assume I am doing something incorrectly, but this appears to be at least partially correct.
curl --verbose -X POST "http://localhost:8081/auth/realms/master/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
-d "client_id=admin-cli" \
-d "requested_subject={TARGET_USER_ID}" \
-d "subject_token={USER_MANAGER_TOKEN}"
My workflow so far has been to get the Keycloak master realm "admin" user's access token (successful) and use that in the impersonation request, along with the target user's Keycloak ID. Am I doing something wrong or missing a step?
I haven't changed any Keycloak permissions, is this required?
From my understanding and the documentation, impersonation is currently supported and enabled by default in Keycloak v5 - Sever Installation. However, another article (Keycloak v5 - Token Exchange) seems to indicate that the feature is disabled by default; could this be why I am getting the 501 Not Implemented?
EDIT: #qdivision mentioned that the Token Exchange needs to be enabled for this to work. However, we are using the jboss/keycloak Docker image and I am wondering where I should add the profile.properties file to enable this feature?
Impersonation is enabled by default, Token Exchange is not.
To enable start the server with -Dkeycloak.profile=preview or -Dkeycloak.profile.feature.token_exchange=enabled as mentioned in the docs
https://www.keycloak.org/docs/latest/securing_apps/index.html#_token-exchange

running a rundeck job from a rest api

I would like to allow anyone to trigger a job I've created in Rundeck.
I can't understand from the API documentation how to do that.
Any one knows, and can give simple examples (my understanding of the subject is minimal to none)?
What I've found is of the sort:
POST /api/1/job/[ID]/run
In order to use the Rundeck API, you need to authenticate first.
Authentication can be done in two different ways:
Using a Token
Using a username and a password
Here is an example of running a Rundeck job using its API (Token based authentication)
curl -X POST http://rundeck_server:port/api/19/job/87bdc26ce-9893-49bd-ad7a-97f4c4a39196/run?authtoken=AVy8jZdcpTYOyPcOVbfcfOQmB6b92zRu --header "Content-Type:text/xml"
Explanation:
19: the API version or Rundeck installation version (19 matchs
Rundeck 2.8.2)
87bdc26ce-9893-49bd-ad7a-97f4c4a39196: Job UUID
run: Runs a job
PS: To obtain an API Token, you must first log in to the Rundeck GUI using a user account. Click on your username in the header of the page, and you will be shown your User Profile page. From this page you can manage your API Tokens.
To update the answer above, this is an example of running a job and feeding it arguments
You will need to replace hostname/API version/job UID/token
Also the current version can be used with JSON only
curl -X POST https://rundeck-hostname.com/api/41/job/7087d3b7-e454-4983-abd5-a211d21d6f27/run?authtoken=[redacted] -H "Accept: application/json" -H "Content-Type: application/json" -d '{
"options": {
"optionName":"optionValue",
}
}
'
And if you need additional arguments for running a job you can find the updated documentation at https://docs.rundeck.com/docs/api/rundeck-api.html#running-a-job

JIRA REST API get all users

I'm trying to get all users from JIRA REST API. I need to save all users to my Database from my own java client. Is it possible to do that ?
If so how we going to do that?
At present time:
for Jira Cloud:
to get all (active + inactive) users:
GET /rest/api/2/users/search?query
to get all active users:
GET /rest/api/2/user/search?query
for Jira Server:
to get all (active + inactive) users:
GET /rest/api/2/user/search?username=.&includeInactive=true
to get all active users:
GET /rest/api/2/user/search?username=.
There seems to be an undocumented way:
Use the "Find user" api
https://docs.atlassian.com/jira/REST/latest/#api/2/user-findUsers
For the username query use %
EG:
/rest/api/2/user/search?username=%
You can get all users that are assignable to a specific project. If everyone is assignable you will get all users.
/rest/api/2/user/assignable/search?project=PROJECT
Curl:
curl -D -u USERNAME:PASSWORD -X GET -H "Content-Type: application/json" https://company.atlassian.net/rest/api/2/user/assignable/search?project=PROJECT
This worked for me:
https://company_name.altassian.net/rest/api/3/users/search?
It will return something like this:
[
{
"accountId": "id",
"accountType": "app",
"avatarUrls": {},
"displayName": "Slack",
"active": true
},
{
"self": "profile_link of ther user",
"accountId": "id",
"accountType": "atlassian",
"avatarUrls": {},
"displayName": "**Real user**",
"active": true,
"locale": "en_US"
}
]
Before saving to DB you'll have to check the accountType:
if (accountType == 'altassian') {
then do push; // or whatever
}
I know it's an old thread but if anyone is searching for this now, this works for me at the moment:
GET /rest/api/latest/user/search?query=+&maxResults=1000
Thanks ;)
One possible way to get all of the users in your JIRA instance is to use the Crowd API's /rest/usermanagement/1/search endpoint:
curl -X GET \
'https://jira.url/rest/usermanagement/1/search?entity-type=user&start-index=0&max-results=1000&expand=user' \
-H 'Accept: application/json' -u username:password
Do note that you'll need to create a new JIRA User Server entry to create Crowd credentials (the username:password parameter above) for your application to use in its REST API calls:
Go to User Management.
Select JIRA User Server.
Add an application.
Enter the application name and password that the application will use when accessing your JIRA server application.
Enter the IP address, addresses, or IP CIDR block of the application, and click Save.
There is no direct method to get all users in Jira Rest API. You might have to use Search function(Which requires passing in atleast one letter to search) or Groups functions, if you have users readily grouped in Jira application.
Go through their documentation for better reference.
https://docs.atlassian.com/jira/REST/latest/#d2e2
https://docs.atlassian.com/jira/REST/latest/#d2e808
You can use simple JDBC scripts to some advanced ones for writing users list to database, through your java client.
Hope this helps!
I also suffered with this problem for a long time. I had a task search by project completed tasks by user. Answer:
https://developer.atlassian.com/rest/api/2/search?jql = project = yourProject + AND + status = done + AND + assignee= yourUser

Bitbucket services api to create POST service

Does anyone know the parameters to create a POST service through the BitBucket API?
Currently the documentation is missing and there is an open ticket to write it. It follows the same format as the rest of the API, hoping someones figured it out.
So far the only parameter I can create is the type:
curl --user name:pw https://api.bitbucket.org/1.0/repositories/{account}/{repository}/services --data 'type={POST/Twitter/AgileZen/etc}'
Successfully creates an empty POST service.
Here's a link to the docs in case it helps.
It's kinda shoddy that we failed to document that properly. Anyway, here's how you add a POST service that posts to google.com:
$ curl -X POST https://username:passwd#bitbucket.org/api/1.0/repositories/evzijst/interruptingcow/services \
-d type=POST -d URL=http://google.com
{
"id": 507781,
"service": {
"fields": [
{
"name": "URL",
"value": "http://google.com"
}
],
"type": "POST"
}
}
The way this endpoint works is that you always specify the "type" parameter which must contain the name of the service (as presented in the dropdown menu) and then configure it by passing additional post parameters.
Each service has its own configuration parameters. You can find out by simply adding the service on a repo and looking at the fields. Your parameters must match the available fields:
Individual parameters can be modified by doing a PUT.
This is documented; just got lost in the shuffle when I revised everything:
https://confluence.atlassian.com/display/BITBUCKET/services+Resource
You can also test it out in our REST browser:
http://restbrowser.bitbucket.org/