I’m building a Rails application that integrates with Shopify and I’m having trouble with the OAuth authentication process. After following the official documentation, I’m stuck at the point where I need to exchange the authorization code for a permanent access token.
When I make a POST request to the OAuth access token endpoint with the required parameters (client_id, client_secret, and code), I get a 200 status response but the body is completely empty. There are no headers returned either.
I’ve double-checked my credentials and the authorization code appears to be valid. Interestingly, when I test the same request using an HTML form, it works perfectly and returns the expected access token. However, programmatically with Ruby’s Net::HTTP or even the rest-client gem, I keep getting this empty response.
Has anyone encountered this issue before? What could be causing the difference between form submission and programmatic requests?
I hit this exact same issue a few months back with a Shopify integration. You’re passing the full URL to Net::HTTP.new, but it only wants the hostname - no protocol. Change your first line to: ```ruby
http_client = Net::HTTP.new(“#{store_name.strip}.myshopify.com”, 443)
http_client.use_ssl = true
check your content-type header - shopify’s picky about that. add token_request['Content-Type'] = 'application/x-www-form-urlencoded' before making the request. also make sure your store_name variable doesn’t have weird characters or spaces that could mess up the url.
That empty 200 response happens when Net::HTTP can’t parse the URL properly. Using URI fixes it. Also check if your auth code expired - they don’t last long.
It’s probably how you’re handling the request parameters. I hit the same issue building my Shopify app last year. Don’t use set_form_data - build the request body manually and set the content type:
Also check that your store_name variable has the full domain like your-store.myshopify.com. Empty response with 200 status usually means the request format isn’t what Shopify expects, even though you’re hitting the endpoint.