hey guys,
I am trying to use Bamboo's rest api and I need to post an xml formatted payload to it. I have been able to do other gets and posts without a payload, but I am having trouble sending a payload that bamboo recognizes.
In bamboos rest api documentation: (https://docs.atlassian.com/bamboo/REST/4.0/), it says that I need to send the following as the payload:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<label name="someLabel"/>
here is my test code that I am trying to use:
use LWP::UserAgent;
my $urlRequest = "http://bamboohost/rest/api/latest/result/projectname
+-planname-latest/label";
my $message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"y
+es\"?><label name=\"testlabel\"/>";
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new( POST => "$urlRequest");
$req->authorization_basic("username", "password");
$req->content($message);
my $result = $ua->request( $req );
when I run this, I get the following error message:
The server refused this request because the request entity is in a for
+mat not supported by the requested resource for the requested method.
am I sending the xml payload properly? what am I missing here?
UPDATE:
I was able to get it to work. This is the solution:
use LWP::UserAgent;
my $urlRequest = "http://bamboohost/rest/api/latest/result/projectname
+-planname-latest/label";
my $message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"y
+es\"?><label name=\"testlabel\"/>";
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new( POST => "$urlRequest");
$req->authorization_basic("username", "password");
$req->content($message);
$req->content_type('application/xml');
my $result = $ua->request( $req );
thanks,
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.