Learn How to Use PowerShell to Post to Campfire’s API

Adam Bertram

Adam Bertram

Read more posts by this author.

Myself and few of my coworkers use 37 Signals‘s Campfire for chat messaging. We’re all in the room all day. I thought this was a great place to be notified of certain things going on in the environment so I created this PowerShell script. I was able to cobble something together.

This script does a call to Campfire’s API and passes all the appropriate XML. You will require the room number, token and message body as parameters. You can find the room number by looking at the URL when you’re in the room. You can find the token by going to My Info when you’re in Campfire. The message body is simply the text you’d like to see as a message. You can also post sound messages as well which are pretty entertaining.

I had to create a dummy user and use that user’s token. If you were to use your own token it would still work but you wouldn’t be able to see the messages you’re posting programmatically via the API.

Eventually, I plan to incorporate this somehow into my SCCM deployments. Rather than staring at a report all night I’d rather just sit in my Campfire room and wait for the notifications. I’ll get to that one of these days. If I were to let myself “play” I’d come up with all kinds of crazy scripts and never get other necessary work done.

$CampfireAccount = 'ABC123'
$postUrl = "https://$CampfireAccount.campfirenow.com/room/$RoomNumber/speak.json"
$message = 'TextMessage'+$MessageBody+''
$baseuri = $base_url + '/speak.xml'
$contentType = 'application/xml'
$headers = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($token+": x"))}
Invoke-WebRequest -Uri $postUrl -Headers $headers -Method Post -body $message -contenttype 'application/xml'

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!