How to run a rundeck job like a rest call from application? - api

I created a simple job of mkdir in rundeck.Now I wanted to run that job some node application.So how can I get the api for the job so that I can call that rest call from my application and run the job.
I just tried a post call for this from my postman but didnt worked.
http://rundeckhost:4440/api/1/job/uuid/run
Gave the following error:
(unauthenticated) is not authorized for: /api/1/job/ec0852b7-222a-4372-ad4b-808892777019/executions
Can someone point me to any references or any info on how can we run the job through a rest call from our application.Basically how to get the rest url for the job to run?

You have one of two ways to authenticate: http://rundeck.org/docs/api/#authentication
For your purpose it will probably be easier to use the authtoken type. See here for your choices for authtoken types: http://rundeck.org/docs/administration/access-control-policy.html#api-token-authorization
Roughly, you will do something like this:
curl -H "X-Rundeck-Auth-Token: $API_TOKEN" \
--data-urlencode "${NODEFILTER:-}" \
--data-urlencode "argString=${JOB_OPTIONS:-}" \
-X POST "${RD_URL}/api/12/job/$JOB_UUID/run"

Related

Gitlab API: Job is not retryable

I want to automate building and deploying of projects. In this regard, I want to use GItlab API to retry particular jobs in Gitlab Pipeline.
The API call I make as follows:
curl --request POST --header "PRIVATE-TOKEN: xxx" "https://gitlab.example.com/api/v4/projects/1/jobs/1/retry"
My Job otherwise can be triggered manually and my gitlab-ci.yml file looks like this:
execute_octoDeploy:
tags:
- windows
stage: build
when: manual
script:
- .\BuildScripts\octodeploy.ps1
I get 403 error, which according to https://docs.gitlab.com/ee/api/README.html means that I am not authorized.
Whereas I have all the rights of the project and I am the owner of the same.
To add:
I can trigger other non-manual jobs but not this.
I also referred:
https://gitlab.com/gitlab-org/gitlab-ce/issues/22824
What might be wrong? How can I solve this?
I seem to have found the solution for this:
You need to add scope of the jobs in the API call
Also Retry method will work only when you have canceled your job in that pipeline.
You can try:
curl --header "PRIVATE-TOKEN: xxxxx" 'https://gitlab.example.com/api/v4/projects/1/jobs?scope[]=pending&scope[]=running'
and then specify if you want to play/retry a job.

Not able to download log files using following API

We are not able to download log files. Once run below command, it is getting unable to parse object filter.
curl -X GET -u : -g https://api.service.softlayer.com/rest/v3/SoftLayer_Event_Log/getAllObjects.json
I'm able to retrieve the Event Logs through SoftLayer's private network, I used the same request:
curl -X GET -u $user:$apiKey -g https://api.service.softlayer.com/rest/v3/SoftLayer_Event_Log/getAllObjects.json
According to the exception, it seems that you are sending something else in the request.
Are you able to make others api calls? can you try again please? Did you have success before with this request?
Also, can you try with the public endpoint: https://api.softlayer.com instead of https://api.service.softlayer.com

How to make Twitter API call through curl in unix

I would like to pull the data from Twitter REST API. I have created the consumer key, secret and Access token, secret. I have tried with "Test OAuth", it generates a CURL command but if I change any one parameter then it is giving the below error.
Message: {"errors":[{"code":32,"message":"Could not authenticate you."}]}
Now I would like to call the twitter API using CURL in shell script for different screenNames.
I want a sample command some thing like mentioned below
curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'count=2&screen_name=aswin' APIKEY:"xxxxxx",Acesstoken:"yyyyyyyy"
Thanks in advance.
Regards,
Aswin
I found the answer.
curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' \
--data 'count=2&screen_name=twitterapi' \
--header 'Authorization: OAuth oauth_consumer_key="AAAAAAAAAAAAAAAAAAAA", oauth_nonce="BBBBBBBBBBBBBBBBBBBBBBB", oauth_signature="CCCCCCCCCCCCCCCCCCCCCCCCCCC", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1471672391", oauth_token="DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", oauth_version="1.0"'
Since your specific query doesn't require a user context you can use Application only authentication to make this request. The bearer token won't change per request so it should allow you to keep using curl.
https://dev.twitter.com/oauth/application-only
n.b. it won't work for all endpoints, but should for the case you listed.
Because most twitter requests require calculating the oauth signature, you should either write a client yourself or reuse an existing command line client.
https://github.com/twitter/twurl
https://github.com/sferik/t
https://github.com/yschimke/oksocial/wiki (Mac focused/cross service)
As you saw any change to the request will generally invalidate the query, and even time is one of the inputs.

Confluence REST API Authorization Failure

I am trying to use the Confluence REST API to create a page. I am using the curl example off of the documentation found HERE. Every time I try to run a terminal command using this curl I get a response that says 'HTTP Status 401 - Basic Authentication Failure - Reason : AUTHENTICATION_DENIED'. I see that someone else had a similar issue regarding their C# code, but there was never a resolution given. Hopefully someone with experience will be able to tell me what I am doing wrong. My curl is listed below with the sensitive parts replaced in <> format.
curl -u <USER>:<PASSWORD> -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"new page","space":{"key":"<PAGEKEY>"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}' https://<SERVER>/wiki/confluence/rest/api/content/ | python -mjson.tool
I was finally able to resolve this. Through a combination of the answer here How to create new page in Confluence using their REST API? and using a login that had the appropriate permissions.

Create an ajax call

i've never used an ajax call,can anybody suggest me to create a jquery ajax call using this api (parse.com),what is H,G?:
curl -X GET \
-H "X-Parse-Application-Id: qS0KLMx5h9lFLGJIpj9qyhM9EEPiTS3VMk" \
-H "X-Parse-REST-API-Key: nh3eoUo9GF2gMhcKJIfIt1Gm" \
-G \
--data-urlencode 'username=cooldude6' \
--data-urlencode 'password=p_n7!-e8' \
https://api.parse.com/1/login
curl is a tool for sending HTTP requests. The -H flag sets a header and -G specifies that the data should be transmitted as a URL query parameter rather than content body. In this case, your command sends an HTTP GET command with the custom headers "X-Parse-Application-Id" and "X-Parse-REST-API-Key". This request was sent to https://api.parse.com/1/login?username=cooldude6&password=p_n7!-e8.
You don't need to become a CURL expert to use Parse; the REST API helps you understand how the Parse API works across the wire, but there are both first and third party APIs for just about every language you would need.
P.S. The Parse docs page helps you by pre-filling the value of X-Parse-Application-Id and X-Parse-REST-API-Key with keys from your actual app. By posting these keys online, others can write code that will look like your app to Parse. Though best practices would suggest you secure your app so that it's OK for these keys to leak (e.g. by setting class-level permissions), you may consider deleting & recreating a new app since it sounds like you are just starting development.