Shopify / shopify-api-ruby

ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services.
MIT License
1.05k stars 468 forks source link

"Bad Request" instead of JSON when registering Webhook #1258

Closed Zapotek closed 8 months ago

Zapotek commented 8 months ago

Issue summary

I'm doing:

ShopifyAPI::Context.setup(
  api_key:        SHOPIFY_API_KEY,
  api_secret_key: SHOPIFY_API_SECRET_KEY,
  host:           "ecsypno.com",
  scope:          "read_fulfillments, read_orders, read_customers",
  is_embedded:    false, # Set to true if you are building an embedded app
  api_version:    "unstable",
  is_private:     true, # Set to true if you have an existing private app,
  log_level: :debug
)

SESSION = ShopifyAPI::Auth::Session.new(
  shop:         "ecsypno.com",
  access_token: SHOPIFY_ACCESS_TOKEN,
)

client = CLIENT = ShopifyAPI::Clients::Rest::Admin.new(
  session: SESSION
)

# Clear all previous Webhooks, we're taking over.
client.get( path: 'webhooks' ).body['webhooks'].each do |hook|
  client.delete( path: "webhooks/#{hook['id']}" )
end

response = client.post(
  path: 'webhooks',
  body: {
    "webhook": {
      "topic":   "order/fulfillment_success",
      "address": OWN_URL,
      "format":  "json"
    }
  }
)
         9: from /home/zapotek/workspace/scnr/license-manager/app.rb:46:in `<top (required)>'
         8: from .../gems/gems/sorbet-runtime-0.5.11163/lib/types/private/methods/_methods.rb:272:in `block in _on_method_added'
         7: from .../gems/gems/sorbet-runtime-0.5.11163/lib/types/private/methods/call_validation.rb:256:in `validate_call'
         6: from .../gems/gems/sorbet-runtime-0.5.11163/lib/types/private/methods/call_validation.rb:256:in `bind_call'
         5: from .../gems/gems/shopify_api-13.3.1/lib/shopify_api/clients/rest/admin.rb:84:in `post'
         4: from .../gems/gems/sorbet-runtime-0.5.11163/lib/types/private/methods/call_validation_2_7.rb:108:in `block in create_validator_method_fast1'
         3: from .../gems/gems/sorbet-runtime-0.5.11163/lib/types/private/methods/call_validation_2_7.rb:108:in `bind_call'
         2: from .../gems/gems/shopify_api-13.3.1/lib/shopify_api/clients/http_client.rb:56:in `request'
         1: from .../usr/lib/ruby/2.7.0/json/common.rb:156:in `parse'
.../usr/lib/ruby/2.7.0/json/common.rb:156:in `parse': 783: unexpected token at 'Bad Request' (JSON::ParserError)

Expected behavior

Register Webook and return JSON response.

Actual behavior

HTML "Bad Request" error.

Steps to reproduce the problem

1. 1. 1.

lizkenyon commented 8 months ago

Hi there 👋

I don't think this is a bug with the API library. This question is probably better suited in the Shopify Community forums. They may be able to point out what is going wrong with your code.