I'm hitting Github's v3 rest api, I'm making a POST request attempting to create a comment on a test PR. I'm getting back a 200 response, and upon inspecting the request, it was sent as a GET, not a POST:
response = HTTParty.post(
"http://api.github.com/repos/my_github/my_repo/issues/1/comments",
body: { body: "works" }.to_json,
headers: {
"Authorization": "Bearer #{ENV['GITHUB_TOKEN']}",
"Content-Type": "application/json",
"User-Agent": ENV["GITHUB_USER_AGENT"]
}
)
response.request
=> #<HTTParty::Request:0x007fdd45a42688
@http_method=Net::HTTP::Get,
@last_response=#<Net::HTTPOK 200 OK readbody=true>,
@last_uri=#<URI::HTTPS https://api.github.com/repos/my_github/my_repo/issues/1/comments>,
@options=
{:limit=>4,
:assume_utf16_is_big_endian=>true,
:default_params=>{},
:follow_redirects=>true,
:parser=>HTTParty::Parser,
:uri_adapter=>URI,
:connection_adapter=>HTTParty::ConnectionAdapter,
:body=>{:body=>"works"},
:headers=>
{:Authorization=>"Bearer my_token",
:Accept=>"application/vnd.github.machine-man-preview+json",
:"Content-Type"=>"application/json",
:"User-Agent"=>"me"}},
@path=#<URI::HTTPS https://api.github.com/repos/my_github/my_repo/issues/1/comments>,
The response body is a list of all the comments on that PR, which is the GET request to that same url. I have no idea why it's not sending a POST. Any help is appreciated.
Change your request to use HTTPS, not HTTP:
https://api.github.com/repos/my_github/my_repo/issues/1/comments
instead of:
http://api.github.com/repos/my_github/my_repo/issues/1/comments
and you get:
response.request
=> #<HTTParty::Request:0x00007ffdb81c7e48 @changed_hosts=false, @credentials_sent=false, @http_method=Net::HTTP::Post ...
as well as:
response.code
=> 201
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With