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

ConnectWise API Base Path Change #9

Open
sgtoj opened this issue Nov 12, 2017 · 4 comments
Open

ConnectWise API Base Path Change #9

sgtoj opened this issue Nov 12, 2017 · 4 comments

Comments

@sgtoj
Copy link

sgtoj commented Nov 12, 2017

ConnectWise API's base path can and will change. Furthermore, CW Manage partners may be on different codebase (even if it cloud hosted). Therefore, the best practice is to build the basePath after retrieving the Codebase. This can be queried via https://{host}/login/companyinfo/{company-name}.

Acme Corporation (Fake) Example

let company = "acmecorp";
let host = "api-na.myconnectwise.net";

// get request: `https://api-na.myconnectwise.net/login/companyinfo/acmecorp`
let info = getCWManageCompanyInfo(host, company)
console.log(info);  
// > {  
// >    "CompanyName":"Acme Corporation",
// >    "Codebase":"v2017_6/",  <---------------- this is a legit codebase
// >    "VersionCode":"v2017.6",
// >    "VersionNumber":"v4.6.50810",
// >    "CompanyID":"acmecorp",
// >    "IsCloud":true,
// >    "SiteUrl":"api-na.myconnectwise.net",
// >    "LicenseBits":{
// >    }
// > }

let basePath = `https://${host}/${info.Codebase}apis/3.0`;
console.log(basePath);
// > https://api-na.myconnectwise.net/v2017_6/apis/3.0
@sgtoj
Copy link
Author

sgtoj commented Nov 12, 2017

Solutions

These are my suggested solutions in order of preference.

  1. Overload the Connectwise constructor to allow for options parameter to be used.
    • all other parameters are ignore if options object if it's the first parameter
    • options object would contain all the required values need to initialize the object
    • note: this is a common js pattern
  2. Create new class called CWManage
    • extends the Connectwise class
    • only accepts options parameter
    • note: this would be reflect proper name of ConnectWise Manage
  3. Allow host parameter of Connectwise constructor to be dynamic/overloaded.
    • regex or url.parse() the host parameter to determine if its a full basePath or just host
    • use the full basePath if basePath if provided; otherwise fallback to a default
  4. Add basePath parameter to the end of the Connectwise constructor signature.

No matter which solution, this module/lib should provide a function or method (a part of Connectwise) that will fetch the companyinfo.

@sowderca sowderca self-assigned this Nov 13, 2017
@sowderca
Copy link
Contributor

@sgtoj I am a fan of option 1 + 3 or 4.

@mattheyan what do you think about this?

@sgtoj
Copy link
Author

sgtoj commented Nov 22, 2017

There is a problem that will need to resolve first. The function the builds the CW Manage endpoint, will need to be async/promise or calls a callback because it's a web request. This complicates the logic little more than I originally thought when I proposed the solutions. That is because there should not be async code in a class constructor. There are ways to solve for this problem, though.

@sowderca
Copy link
Contributor

sowderca commented Sep 1, 2021

@sgtoj I was able to add support for this in another module:

Source of the method to pull from CompanyInfo

@sowderca sowderca removed their assignment Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants