| Crates.io | dimo-rust-sdk |
| lib.rs | dimo-rust-sdk |
| version | 0.1.3 |
| created_at | 2024-11-20 17:19:37.241696+00 |
| updated_at | 2025-01-05 16:31:03.879566+00 |
| description | Community-driven DIMO SDK in Rust |
| homepage | https://docs.dimo.org/developer-platform |
| repository | https://github.com/iMac7/dimo-rust-sdk |
| max_upload_size | |
| id | 1455072 |
| size | 96,472 |
For detailed API documentation, visit the DIMO Developer Documentation.
Add the crate to your project's cargo.toml under [dependencies] . Ensure to check for the latest version.
[dependencies]
dimo-rust-sdk = "0.1.0"
To use the DIMO SDK in your Rust project, start by importing the SDK library:
use dimo_rust_sdk::{Environment, DIMO};
Then, initialize the SDK with the appropriate environment. The Environment enum supports two values: Production and Dev:
let mut dimo = DIMO::new(Environment::Production);
The SDK requires credentials, which should be passed via system environment variables. Below are the required and optional credentials:
CLIENT_IDAPI_KEY – The API key / private key for your DIMO account.REDIRECT_URI – redirect uri / domainDEVELOPER_JWTVEHICLE_JWTTo set your credentials, export them as environment variables from your terminal:
export CLIENT_ID="DIMO_CLIENT_ID"
export API_KEY="DIMO_API_KEY"
export REDIRECT_URI="http://thatplace.com/doesntexist"
You can check the currently set credentials by calling the get_credentials() function:
use rust_sdk::{get_credentials};
let credentials = get_credentials();
Alternatively, you can check the credentials directly via the terminal:
echo $client_id
There are two types of tokens in the DIMO SDK:
Developer JWT: This token is generally used for authenticated endpoints.
Developer JWT, ensure the three required environment variables (client_id, api_key, and redirect_uri) are set.let token = dimo.get_token().await;
Store the returned token string as an environment variable to use it.
Vehicle JWT: This token is needed for certain REST endpoints that require a token_id, and some GraphQL endpoints (dimo.telemetry).
dimo.tokenexchange.exchange(1, vec![2, 3])
To interact with the REST API, use the appropriate method in the SDK, passing the required parameters. Some methods will require a Developer JWT to authenticate the request.
All entry points in the main dimo struct are rest endpoints, except those in the graphql section below.
dimo.devicedefinitions.get_by_id("0x23dfdf");
Some methods have optional parameters denoted by Option<Type>, you can use None in place of the parameter.
let result = dimo.devices.create_vehicle_from_vin("12345", "254", None);
Where a Value type is required, use the exported Value from the sdk.
use dimo_rust_sdk::{Value};
let mut data = HashMap::new();
data.insert("hello".to_string(), Value::String("world".to_string()));
let result = dimo.attestation.create_pom_vc("1", data).await;
The SDK provides access to the GraphQL API through two entry points (dimo.identity , dimo.telemetry) in the DIMO struct, each with several methods available.
query(): This method accepts any valid GraphQL query string and sends it to the respective endpoint.
let query = "
{
vehicles (first: 10) {
totalCount
}
}
";
let result = dimo.identity.query(query).await;
This query is equivalent to calling dimo.identity.count_dimo_vehicles().
To check whether your GraphQL query is valid, paste it in the Identity API GraphQL Playground or Telemetry API GraphQL Playground.
Note: The
telemetryAPI (dimo.telemetry) requires aVehicle JWT. Ensure that the appropriate token is set before querying telemetry-related endpoints.