10 releases
0.1.8 | May 4, 2021 |
---|---|
0.1.7 | May 3, 2021 |
0.1.6 | Apr 20, 2021 |
0.1.3 | Mar 9, 2021 |
0.1.0 | Feb 26, 2021 |
#70 in #developer
37KB
505 lines
cwmanage
cwmanage - Connectwise Manage api crate
This is just my little manage api "library" for learning how rust crates and libraries work
lib.rs
:
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, PatchOp};
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 = json!("test_basic_patch_replace");
let result = 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%'")]
Dependencies
~5–17MB
~229K SLoC