Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix "must use account-specific domains" error with newer API versions #439

Closed

Conversation

q3aiml
Copy link

@q3aiml q3aiml commented Sep 20, 2019

Newer API versions require using the account-specific domains such as
<account-id>.suitetalk.api.netsuite.com. The WSDLs for these versions,
however, specify the generic webservices.netsuite.com domain. When
wsdl_domain is provided use this to override the endpoint so the
account-specific domain can be used and users can successfully use
2019_1.

I create the client first without the endpoint override to allow
reading the default endpoint from the client. Then wsdl_domain is
substituted into the default which avoids hardcoding the path in the gem
(/services/NetsuitePort_#{api_version}).

If this seems too messy I can instead (in addition?) open a PR that adds
a wsdl_override option.

Thanks for looking.

Fixes #430
Fixes #434

Newer API versions require using the account-specific domains such as
`<account-id>.suitetalk.api.netsuite.com`. The WSDLs for these versions,
however, specify the generic `webservices.netsuite.com` domain. When
`wsdl_domain` is provided use this to override the endpoint so the
account-specific domain can be used and users can successfully use
2019_1.

I create the client first without the `endpoint` override to allow
reading the default endpoint from the client. Then `wsdl_domain` is
substituted into the default which avoids hardcoding the path in the gem
(`/services/NetsuitePort_#{api_version}`).
@q3aiml
Copy link
Author

q3aiml commented Sep 20, 2019

Note that you can also patch something like this into a codebase using the current version of the gem with something like this:

module NetSuite
  module Configuration
    extend self

    alias :old_connection :connection
  
    def connection(params={}, credentials={})
      client = old_connection(params, credentials)
      client.wsdl.endpoint = client.wsdl.endpoint.to_s.sub('//webservices.netsuite.com/', "//#{wsdl_domain}/")
      client
    end
  end
end

@jormon
Copy link
Contributor

jormon commented Nov 20, 2019

Helped me out -- thank for this!

@mawaldne
Copy link

Thank you! This also helped me.

@iloveitaly
Copy link
Member

Hey All! Still haven't had time to dig into this contribution and get it mixed it. Will hopefully get to this sooner rather than later.

@ohaddahan
Copy link

@q3aiml

module NetSuite
  module Configuration
    extend self

    alias :old_connection :connection

    def connection(params={}, credentials={})
      client = old_connection(params, credentials)
      client.wsdl.endpoint = client.wsdl.endpoint.to_s.sub('//webservices.netsuite.com/', "//#{wsdl_domain}/")
      client
    end
  end
end

NetSuite.configure do
  reset!
  account          ENV['NETSUITE_ACCOUNT_ID']
  consumer_key     ENV['NETSUITE_CLIENT_ID']
  consumer_secret  ENV['NETSUITE_CLIENT_SECRET']
  token_id         ENV['NETSUITE_TOKEN_ID']
  token_secret     ENV['NETSUITE_TOKEN_SECRET']
  api_version      ::NETSUITE_API_VERSION
  wsdl_domain      ::NETSUITE_WSDL_DOMAIN
end

In my Rails config/initializers, getting error:

NoMethodError: undefined method `wsdl' for #Savon::Client:0x00007fe4b7254010

@q3aiml
Copy link
Author

q3aiml commented Jan 13, 2021

@ohaddahan I haven't been using netsuite for some time so I am afraid I won't be much help. I'll close to this for clarity. If anyone who still has the ability to test this change wants to open a new PR please feel free to use my patch (as hacky as it is!).

@q3aiml q3aiml closed this Jan 13, 2021
@darrend
Copy link

darrend commented Feb 16, 2021

@ohaddahan (and others)

(copying my comment verbatim from #445 (comment))

To get going with 2020_2 (2020.2, are these twice a year like clockwork? do we need to keep up with them?) I had to refine the hacks above a bit. The urls mentioned in the wsdl returned by Netsuite changed again from webservices.na0.netsuite.com to webservices.netsuite.com so I tweaked the code in #445 (comment) to use a more generic regex replacement. In addition, Savon doesn't expose (or no longer in the version included by this gem) wsdl so I had to crack it open and expose the attribute; this fixes the undefined method wsdl'` error.

Below is for a totally made up 0000000_SB1 sandbox account. Replace it with your real account of course.

NetSuite.configure do
  reset!
  api_version      '2020_2'
  account          "0000000_SB1" 
  consumer_key     "xxxxx"
  consumer_secret  "xxxxx"
  token_id         "xxxxx"
  token_secret     "xxxxx"
  # pull the following from `NetSuite::Utilities.data_center_url('0000000_SB1')` every time? once year? never? always?
  wsdl_domain     "0000000-sb1.suitetalk.api.netsuite.com"
end

module NetSuite
  module Configuration
    extend self

    alias :old_connection :connection

    def connection(params={}, credentials={})
      client = old_connection(params, credentials)
      wsdl = client.wsdl_netsuite_endpoint_hack
      # from "https://webservices.netsuite.com/services/NetSuitePort_2020_2" to "https://#{wsdl_domain}/services/NetSuitePort_2020_2"
      wsdl.endpoint = wsdl.endpoint.to_s.gsub(%r[//[^/]*/], "//#{wsdl_domain}/") #
      client
    end
  end
end

# above hack fails with undefined method `wsdl' for #<Savon::Client:0x00007fa07cb5c2e0> otherwise
module Savon
  class Client
    def wsdl_netsuite_endpoint_hack
      return self.wsdl if self.respond_to?(:wsdl)
      @wsdl
    end
  end
end

@iloveitaly
Copy link
Member

For any googlers, this was fixed with #473

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regardless of Config, All Calls Go to Wrong DataCenter Connection errors with the 2019_1 API
6 participants