Fetch a specific ID using Rally REST and curl - perl

I am new to rally REST. I have used curl/perl/REST api for RTC, so am familiar with it but learned mostly by using examples. I need to be able to fetch a specific ID and the Name associated with it accessing it through curl and perl scripting. For example DE46835 Name:This is my defect. I haven't found any examples to fetch just a known ID. Can you point me to any documentation for this or provide an example how to do this.

If you know the FormattedID you should be able to query using a URL like this:
https://rally1.rallydev.com/slm/webservice/v2.0/defect?query=(FormattedID = "DE46835")
The full web service api documentation is available here:
https://rally1.rallydev.com/slm/doc/webservice/

Thank you for the answer. I was able to figure it out and get it to work.
Here is what I did.
$cmd = "curl -k -u \"${user}:${password}\" \"${url}\" -c ${cookies} -o ${auth}";
system($cmd);
Then
$cmd = "curl -k \"$url\" -o ${return} -b ${cookies}";
where $url=https://rally1.rallydev.com/slm/webservice/v2.0/defect?query=(FormattedID = "DE46835")

Related

Can/How to use project configuration keys as job parameters in Rundeck

I'm using the API to add some project configuration keys and would like to use them as job parameters. Is this possible? If so, how can I do it? I've looked in the official documentation but am not seeing much.
Indeed, that is achievable, from the documentation, you will need to update the project’s configuration with a “Project global execution variable” key and value, then that variable will be available in all execution contexts as ${globals.X} and can be referenced in scripts and commands. You can send the project’s configuration key as JSON, xml or plain text via curl or as a file directly via the RD CLI. e.g:
If you use the “rd” cli, you need to create a file, which can be a .properties, JSON or YAML file. We will create a JSON file named test.json, that contains the following ‘KEY’ and ‘VALUE’:
{ "project.globals.test" : "testvalue" }
Then, you can update the project configuration with this rd command syntax:
rd projects configure update -f [/path/to/test.json] -p [project_name]
That will update your projects configuration. Then you can reference it as follows:
Via bash: $RD_GLOBALS_TEST
Via command: ${globals.test}
In a script content: #globals.test#
Alternatively, you could use the API directly with curl. For this example I’m using an API token to authenticate with Rundeck’s API and sending the same key and value, but as xml:
curl -H "X-Rundeck-Auth-Token: INSERT_TOKEN" -H "Content-Type: application/xml" -d '<property key="project.globals.test" value="valuetest"/>' -X PUT http://[RD_HOST]:[PORT]/api/23/project/[PROJECT_NAME]/config/[KEY]
Hope it helps.

When using oauth to ask permission for Facebook app, does not take in consideration what's in scope

So basically I need my app to allow different permission so I can test it.
But when using the link
"https://www.facebook.com/dialog/oauth?client_id=MYID&redirect_uri=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&scope=user_friends, publish_actions,friends_birthday"
It only asks for public information access and not the rest.
I have tried many different ways with the link, I can manage it to ask for the email if I put it first after scope, but the rest it does not request it.
I would very much appreciate your help.
My application works with a .sh script in Ubuntu, and needs the permission to run the script on my Facebook account.
I don't require the app to be used by anyone else in the future, this is why I limited myself to asking permission with this kind of link instead of doing some interface.
I don't require the app to be used by anyone else in the future, this is why I limited myself to asking permission with this kind of link instead of doing some interface.
This is the script I would like to run via the APP, so I have to allow application to access permissions accordingly. I don't know if the script work yet:
#!/bin/bash
NOW=$(date +"%m/%d")
#Enter your access token below within quotations
ACCESS_TOKEN="TOKEN"
#Get the names and UIDs of your unfortunate friends born on a day like today
curl "https://api.facebook.com/method/fql.query?access_token=$ACCESS_TOKEN&query=SELECT%20first_name,uid%20from%20user%20where%20uid%20in%20(SELECT%20uid2%20from%20friend%20where%20uid1=MYUSERID)AND%20substr(birthday_date,0,5)%20==%20'$NOW'" > birthdaywishtemp.xml
names=`sed -n -e 's/.*<first_name>\(.*\)<\/first_name>.*/\1/p' birthdaywishtemp.xml`
ids=`sed -n -e 's/.*<uid>\(.*\)<\/uid>.*/\1/p' birthdaywishtemp.xml`
F_ARRAY=( `echo ${names}` )
U_ARRAY=( `echo ${ids}` )
#Wish each of them with the same old boring message
for (( i = 0 ; i < ${#U_ARRAY[#]} ; i++ ))
do
curl 'https://graph.facebook.com/${U_ARRAY[$i]}'
curl -F 'access_token='$ACCESS_TOKEN'' \
-F 'message=Hey, Happy Birthday...'${F_ARRAY[$i]} \
https://graph.facebook.com/${U_ARRAY[$i]}/feed >> birthdaywishbackup.log
#Let you know the progress
echo "Wished ${F_ARRAY[$i]}" >> birthdaywishbackup.log
done

Curl command uploading document fails when run from Perl

I've got a Perl script that uploads documents into Alfresco using curl.
Some of the documents have ampersand in the file name and initially this caused curl to fail. I fixed this by placing a carat symbol in front of the ampersand. But now I'm finding some documents are failing to upload when they don't have a space either side of the ampersand. Other documents with spaces in the file name and an ampersand do load successfully.
The snippet of Perl code that is running is:
# Escape & for curl in file name with a ^
my $downloadFileNameEsc = ${downloadfile};
$downloadFileNameEsc =~ s/&/^&/g;
$command = "curl -u admin:admin -F file=\#${downloadFileNameEsc} -F id=\"${docId}\" -F title=\"${docTitle}\" -F tags=\"$catTagStr\" -F abstract=\"${abstract}\" -F published=\"${publishedDate}\" -F pubId=\"${pubId}\" -F pubName=\"${pubName}\" -F modified=\"${modifiedDate}\" -F archived=\"${archived}\" -F expiry=\"${expiryDate}\" -F groupIds=\"${groupIdStr}\" -F groupNames=\"${groupNameStr}\" ${docLoadUrl}";
logmsg(4, $command);
my #cmdOutput = `$command`;
$exitStatus = $?;
my $upload = 0;
logmsg(4, "Alfresco upload status $exitStatus");
if ($exitStatus != 0) {
You can see that I am using backticks to execute the curl command so that I can read the response. The perl script is being run under windows.
What this effectively tries to run is:
curl -u admin:admin -F file=#tmp-download/Multiple%20Trusts%20Gift%20^&%20Loan.pdf -F id="e2ef104d-b4be-4896-8360-7d6f2e7c7b72" ....
This works.
curl -u admin:admin -F file=#tmp-download/Quarterly_Buys^&sells_Q1_2006.doc -F id="78d18634-ee93-4c29-b01d-270aeee3219a" ....
This fails!!
The only difference being as far as I can see is that in the one that works the file name has spaces (%26) in the file name somewhere around the ampersand, not necessarily next to the ampersand.
I can't see why one runs successfully and the other doesn't. Think it must be to do with backticks and ampersands in the file name. I haven't tried using system as I wanted to capture the response.
Any thoughts because I've exhausted all options.
You should learn to use Perl modules. Perl has some great modules to handle the Web requests. If you depend upon operating system commands, you will end up with not only dependencies upon those commands, but shell interactions and whether or not you need to quote special characters.
Perl modules remove a lot of the issues that you can run into. You are no longer dependent upon particular commands or even particular implementation of those commands. (The curl command can vary from system to system, and may not even be on the system you're on). Plus, most of these modules handle the piddling details for you (such as URI escaping strings).
LWP is the standard Perl library for implementing these requests. Take a look at the LWP Cookbook. This is a tutorial on the whole HTTP process. Basically, you need to create an agent which is really just a virtual web browser for you to use. Then, you can configure it (for example, setting the machine, browser type, etc.) you might need.
What is really nice is HTTP::Request::Common that provides a simple interface for using HTTP forms.
my $results = POST "$docLoadUrl"
[ file => '#' . "$downloadFileName",
id => $docId,
title => $docTitle,
tag => $catTagStr,
abstract => $abstract,
published => $publishedDate,
pubId => $pubId,
pubName => $pubName,
...
];
This is a lot easier to read and maintain. Plus, it will handle URI encoding for you.

How do I get the raw version of a gist from github?

I need to load a shell script from a raw gist but I can't find a way to get raw URL.
curl -L address-to-raw-gist.sh | bash
And yet there is, look for the raw button (on the top-right of the source code).
The raw URL should look like this:
https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{commit_hash}/{file}
Note: it is possible to get the latest version by omitting the {commit_hash} part, as shown below:
https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{file}
February 2014: the raw url just changed.
See "Gist raw file URI change":
The raw host for all Gist files is changing immediately.
This change was made to further isolate user content from trusted GitHub applications.
The new host is
https://gist.githubusercontent.com.
Existing URIs will redirect to the new host.
Before it was https://gist.github.com/<username>/<gist-id>/raw/...
Now it is https://gist.githubusercontent.com/<username>/<gist-id>/raw/...
For instance:
https://gist.githubusercontent.com/VonC/9184693/raw/30d74d258442c7c65512eafab474568dd706c430/testNewGist
KrisWebDev adds in the comments:
If you want the last version of a Gist document, just remove the <commit>/ from URL
https://gist.githubusercontent.com/VonC/9184693/raw/testNewGist
One can simply use the github api.
https://api.github.com/gists/$GIST_ID
Reference: https://miguelpiedrafita.com/github-gists
Gitlab snippets provide short concise urls, are easy to create and goes well with the command line.
Sample example: Enable bash completion by patching /etc/bash.bashrc
sudo su -
(curl -s https://gitlab.com/snippets/21846/raw && echo) | patch -s /etc/bash.bashrc

cURL example of posting photos remotely to Facebook?

I am currently having a problem, where I try to post a picture to Facebook and I get an "error" response:
"Requires upload file", with OAuth exception #324.
I have the access token in there just fine and I can adapt my code from a cURL example relatively easily. All the examples I can find show how to do it in PHP (which I don't know) or something of the like. Any help with an example of how to upload a photo just from the cURL command line tool would be greatly appreciated.
I just can't find what I am looking for anywhere for the life of me.
Are you appending with the # character?
curl -F 'access_token=xxx' \
-F 'source=#img.jpg' \
-F 'message=Test'
'https://graph.facebook.com/me/photos'