hipchat / hipchat-rb

HipChat HTTP API Wrapper in Ruby with Capistrano hooks
https://www.hipchat.com/docs/apiv2
MIT License
336 stars 172 forks source link

Send card doesnt work #189

Open pchaganti opened 7 years ago

pchaganti commented 7 years ago

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)
dodontommy commented 7 years ago

+1 getting the same thing

joshuamcginnis commented 6 years ago

@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!