hipchat / hipchat-rb

HipChat HTTP API Wrapper in Ruby with Capistrano hooks

Home Page:https://www.hipchat.com/docs/apiv2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Send card doesnt work

pchaganti opened this issue · comments

Unable to get this to work. The error message is rather cryptic about what is missing. Anyone have any pointers?

client = HipChat::Client.new(api_token, :api_version => 'v2')

card = {
    :style => 'application',
    :title => 'My Awesome Card',
    :id => 12345 ,
    :format => "html"
}

client[roomid].send('Tester', 'Testing Card', :color => 'red', :card => card)
The request was invalid. You may be missing a required argument or provided bad data. 
path:/my-card-test/notification method:Net::HTTP::Post (HipChat::BadRequest)
commented

+1 getting the same thing

@pchaganti @tommybstitch

This works for me.

require 'hipchat'
require 'securerandom'

client = HipChat::Client.new(my_token)

card = {
  style: 'application',
  title: 'Example Title',
  id: SecureRandom.uuid,
  url: 'my_url',
  description: {
    format: :html,
    value: 'This is a test'
  },
  attributes: [
    {
      label: 'Total Records',
      value: { label: '1082404', style: 'lozenge-success' }
    },
    {
      label: 'Total Runtime',
      value: { label: '0.39 seconds', style: 'lozenge' }
    },
  ]
}

room = client['Test']

room.send('test_sender', 'test_message', message_format: :html, card: card)

This list of required fields are here:
https://www.hipchat.com/docs/apiv2/method/send_room_notification

Example API payloads are here:
https://developer.atlassian.com/server/hipchat/messages/

Hope this helps!