Skip to content →

Posting to Basecamp using Powershell

Problem:  I want to report to the “business” from our webapplication without having to get involved in the massive nightly reporting process.

Solution: The “business” is already familar with Basecamp, so with a little Powershell and a couple of scheduled jobs we can post summary reports to Basecamp for everybody to see.

$request = "<request><post><category-id>10574251</category-id><title>This is a test message</title><body>This is the body of the message</body></post></request>"

$uri = "http://yourbasecampurl/projects/yourprojectid/posts.xml";
$usernamePassword = $username + ":" + $password;
$mycache = New-Object System.Net.CredentialCache;
$uri = New-Object System.Uri $uri ;
$credentials = New-Object System.Net.NetworkCredential($username,$password);
$mycache.Add( $uri,"Basic" ,$credentials);
$encoding = New-Object System.Text.ASCIIEncoding
$headerValue = "Basic " + [System.Convert]::ToBase64String( $encoding.GetBytes($usernamePassword)  );
$req = [System.Net.WebRequest]::Create($uri);
$req.Method = "POST";        
$req.ContentType = "application/xml";
$req.Credentials = $mycache;
$writer = New-Object System.IO.StreamWriter $req.GetRequestStream();
$response = $req.GetResponse();
$receiveStream = $response.GetResponseStream();
$reader = New-Object System.IO.StreamReader($receiveStream, [System.Text.Encoding]::UTF8);

Write-Output $reader.ReadToEnd();

Published in Powershell


Leave a Reply

Your email address will not be published. Required fields are marked *