zendesk api

postmanで接続確認

Authorization

Basic Auth
* username
* password

url

エンドポイント

// post
https://dev-air-payment.zendesk.com/api/v2/tickets.json

body

{"ticket" : {"subject" : "hello", "description" : "テスト"}}

コード

address = URI("https://dev-air-payment.zendesk.com/api/v2/tickets.json")
http = Net::HTTP.new(address.host, address.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new address.request_uri

// 方法1
request.basic_auth("{id}", "{pass(APIトークン)}")
request.add_field("Content-Type", "application/json")

// 方法2 base64エンコードする
bearer_token = "{id}/token:{pass(APIトークン)}"
encoded_bearer_token = Base64.strict_encode64(bearer_token)
request.add_field("Authorization", "Basic #{encoded_bearer_token}")

body = {
  "ticket" => {"subject" => "hello", "description" => "test!"}
}.to_json
request.body = body
response = http.request(request)