rikas / zoho_hub

Zoho CRM API V2 Wrapper
MIT License
25 stars 30 forks source link

Sandbox API access #33

Closed artsyca closed 5 years ago

artsyca commented 5 years ago

As it seems, Zoho provides a sandbox environment for development purposes

The API url is https://crmsandbox.zoho.com/crm/v2

This allows API access using the same tokens as the live environments, as it seems There exists a need in my application to access this sandbox environment, I wonder the best way to specify the url? Currently looking at connection.rb

TimCummings commented 5 years ago

You can pass the sandbox URL to ZohoHub.setup_connection as the api_domain argument. If your use case is simple you could do this manually where needed, or you could do something more broad and dynamic, e.g. I'm using ZohoHub in a Rails app and define both the regular API domain as well as the sandbox API domain in my Rails credentials file; then I have a method that passes the appropriate domain to ZohoHub.setup_connection depending on my app's environment (i.e. regular API domain in production, sandbox domain everywhere else.)

rikas commented 5 years ago

You can do as @TimCummings says. If something doesn't work please let us know. Closing for now.

artsyca commented 5 years ago

Appreciate the pointers fellows, to confirm --

In Zohohub.configure we still provide the regular config.api_domain i.e. https://accounts.zoho.com but in ZohoHub.setup_connection we override the option to point to https://crmsandbox.zoho.com

i.e.

ZohoHub.configure do |config|
  ...
  config.api_domain   = ENV.fetch('ZOHO_API_DOMAIN') # => 'https://accounts.zoho.com'
  ...
end

but then

ZohoHub.setup_connection(
  access_token:  'xxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  refresh_token: ENV.fetch('ZOHO_REFRESH_TOKEN'),
  api_domain:    'https://crmsandbox.zoho.com' # => Override it again here.. 
                                               # would've been 'https://www.zohoapis.com'
)

which I suppose overrides the initializer call to infer_api_domain

🤔 definitely usable for our purposes --