Skip to content

Instantly share code, notes, and snippets.

@AbeCole
Created March 5, 2016 17:17
Show Gist options
  • Save AbeCole/f2c4a007faa7d54af79e to your computer and use it in GitHub Desktop.
Save AbeCole/f2c4a007faa7d54af79e to your computer and use it in GitHub Desktop.
require 'net/http'
require 'json'
API_TOKEN = 'YOUR_API_TOKEN'
data = {
:event => 'client/create',
:target_url => 'CALLBACK_URL_HERE'
}
uri = URI("https://hook.vcita.com/v1/subscriptions/standard/subscribe")
request = Net::HTTP::Post.new(uri)
request.set_form_data(data)
request["Authorization"] = "Token #{API_TOKEN}"
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
http.request(request)
end
return res.body
@bubbavcita
Copy link

Abe,

The only thing that is preventing this from working is to send the parameters as a json string.

Thanks,
B.

Here is some sample code:

require 'net/http'
require 'json'

parameters = {
  :event => 'client/create',
  :target_url => 'http://someexternalurl.com'
}

uri = URI("https://hook.vcita.com/v1/subscriptions/standard/subscribe")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
  req = Net::HTTP::Post.new(uri)
  req["Authorization"] = "Token YOUR_TOKEN"
  req['Content-Type'] = 'application/json'
  # The body needs to be a JSON string, use whatever you know to parse Hash to JSON
  req.body = parameters.to_json
  http.request(req)
end

p res.body

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment