Crate cwmanage[−][src]
crate for working with Connectwise Manage API
In the connectwise api https://developer.connectwise.com/Products/Manage some results are returned as a single ‘object’ and most are returned as a list. Normally you will be getting a list of results (even a list of one) so you would use [Client.get]. In some cases, (/system/info for example) it does not return a list, in this case use [Client.get_single]. Consult the api documentation (above) for more details.
Get Example
Basic client with default api_uri, codebase, and api version
use cwmanage::Client; use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let query = [("", "")]; let result = client.get_single("/system/info", &query).unwrap();
Override the api_version
use cwmanage::Client; use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let query = [("", "")]; let result = client.get_single("/system/info", &query).unwrap();
Get an endpoint with multiple results
use cwmanage::Client; use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let query = [("fields", "id,identifier")]; let result = client.get("/system/members", &query);
Post Example
use cwmanage::Client; use serde_json::json; use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let body = json!({"foo": "bar"}).to_string(); let result = client.post("/system/members", body);
Patch Example
use cwmanage::Client; use serde_json::json; use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let op = PatchOp::Replace; let path = "name"; let value = "test_basic_patch_replace"; let result = testing_client().patch("/sales/activities/100", op, path, value);
Query examples
See the connectwise api for further details
- No query -
[("", "")]
- Only get the id field
[("fields", "id")]
- Also apply some conditions
[("fields", "id"), ("conditions", "name LIKE '%foo%'")]
Structs
Client | Connectwise client. Initinitialize with Client::new. Use Client::api_url, Client::api_version and Client::codebase to customize. The finalize with Client::build |
Enums
PatchOp | Our possible patch operations |
Constants
DEFAULT_API_CODEBASE | This is the release version specified in the documentation. |
DEFAULT_API_URL | Default api url. NA for north america. Adjust to your cloud instance or local instance. See Client for how to customize |
DEFAULT_API_VERSION | I cannot find documentation on this , but since it is a number it is customizable. See Client for how to customize |