Wraps the Benchling API for access in R.
If you have suggestions or find a bug, let us know via the Issues.
You can install the development version of benchlingapi like so:
# install.packages("remotes")
remotes::install_github("HIBio/benchlingapi")
library(benchlingapi)Set up the following environment variables for easy access (e.g. using
usethis::edit_r_environ())
BENCHLING_ORG=yourorgname
BENCHLING_TOKEN=sk_dMAQaaa9AaAAwwADRAzAs2AAz4Aaaset_creds() can be used to validate and set the credentials for a
given tenant (itself set via BENCHLING_ORG). To switch between a fixed
list of tenants, one could write a helper
use_tenant <- function(tenant = c("test", "prod")) {
tenant <- match.arg(tenant)
message("switching to ", tenant)
switch(tenant,
prod = benchlingapi::set_creds(
org_var = "PROD_BENCHLING_ORG",
token_var = "PROD_BENCHLING_TOKEN"
),
# default
test = benchlingapi::set_creds()
)
invisible()
}This has not been included in {benchlingapi} as organisations may have their own list of tenants to configure.
get_users()
#> email handle id name
#> 1 jamey@example.com jamey ent_SPXdAvAd Jamey Olson
#> 2 peggy@example.com peggy ent_N3ARMuA4 Peggy Paucek
#> 3 gabriel@example.com gabriel ent_og8mNFAy Gabriel Toy
#> 4 felix@example.com felix ent_CXxJcHK2 Felix Rohan
#> 5 garett@example.com garett ent_qac9DiQn Garett DonnellyMost of the endpoints have been automatically wrapped1 but there is no guarantee that they work.
The endpoints which should be wrapped with a get_* function are
#> [1] "aa-sequences" "app-configuration-items"
#> [3] "apps" "assay-result-schemas"
#> [5] "assay-results" "assay-run-schemas"
#> [7] "assay-runs" "automation-file-transforms"
#> [9] "automation-input-generators" "automation-output-processors"
#> [11] "batch-schemas" "batches"
#> [13] "blobs" "box-schemas"
#> [15] "boxes" "container-schemas"
#> [17] "containers" "custom-entities"
#> [19] "dna-alignments" "dna-oligos"
#> [21] "dna-sequences" "dropdowns"
#> [23] "entities" "entity-schemas"
#> [25] "entries" "entry-schemas"
#> [27] "entry-templates" "events"
#> [29] "exports" "feature-libraries"
#> [31] "features" "folders"
#> [33] "legacy-workflow-stage-runs" "legacy-workflow-stages"
#> [35] "legacy-workflows" "location-schemas"
#> [37] "locations" "mixtures"
#> [39] "molecules" "nucleotide-alignments"
#> [41] "oligos" "organizations"
#> [43] "plate-schemas" "plates"
#> [45] "projects" "registries"
#> [47] "request-fulfillments" "request-schemas"
#> [49] "request-task-schemas" "requests"
#> [51] "result-transactions" "rna-oligos"
#> [53] "rna-sequences" "tasks"
#> [55] "teams" "token"
#> [57] "transfers" "users"
#> [59] "warehouse-credentials" "workflow-outputs"
#> [61] "workflow-stage-runs" "workflow-stages"
#> [63] "workflow-task-groups" "workflow-task-schemas"
#> [65] "workflow-tasks" "workflows"
Some of these take an additional (optional) parameter (only one supported for now), e.g.
benchlingapi::get_users
#> function(user_id = NULL, ...) {
#> endpoint <- "users"
#> if (!is.null(user_id)) {
#> endpoint <- glue::glue("users/{user_id}")
#> }
#> get_benchling(endpoint, ...)
#> }
#> <bytecode: 0x12011e6c8>
#> <environment: namespace:benchlingapi>Many endpoints also include query parameters (see the official
reference). These can be specified
via the ... argument, and are detailed in the individual help for each
function, e.g.
?get_usersManage user objects.
get_users(user_id = NULL, ...)
user_id
|
users id |
…
|
additional query parameters; see Details below |
Available query parameters:
- ids
-
Comma-separated list of ids. Matches all of the provided IDs, or returns a 400 error that includes a list of which IDs are invalid.
- name
-
Name of a user. Restricts results to those with the specified name.
- nameIncludes
-
Name substring of a user. Restricts results to those with names that include the provided substring.
- names.anyOf
-
Comma-separated list of names. Restricts results to those that match any of the specified names, case insensitive. Warning - this filter can be non-performant due to case insensitivity.
- names.anyOf.caseSensitive
-
Comma-separated list of names. Restricts results to those that match any of the specified names, case sensitive.
- modifiedAt
-
Datetime, in RFC 3339 format. Supports the \> and \< operators. Time zone defaults to UTC. Restricts results to those modified in the specified range. e.g. \> 2017-04-30.
- memberOf
-
Comma-separated list of organization and/or team API IDs. Restricts results to users that are members of all given groups.
- adminOf
-
Comma-separated list of organization and/or team API IDs. Restricts results to users that are admins of all given groups.
- handles
-
Comma-separated list of handles. Restricts results to the users with the specified handles.
- passwordLastChangedAt
-
Datetime, in RFC 3339 format. Supports the \>, \>=, \<, \<=, operators. Time zone defaults to UTC. Restricts results to users who have last changed their password in the specified range. e.g. \> 2017-04-30. If "null" is provided returns users that have no password set (SAML).
- nextToken
-
Token for pagination
data from users endpoint
As an example, if your users list has several users with the name ‘David’
get_users(nameIncludes = "david")#> email handle id name
#> 1 david.old@example.com david.old ent_U2gA6a41 David Old
#> 2 david.new@example.com david.new ent_AvA2sA2X David New
{benchlingapi} uses
{logger} for logging
messages, warnings, errors, and debug info. A default of
logger::log_threshold(ERROR) is set on package load, but can be
overridden, e.g.
logger::log_threshold(DEBUG)
get_users(nameIncludes = "david")DEBUG [2023-03-27 16:53:25] GET prod with endpoint: users
DEBUG [2023-03-27 16:53:25] Building query from `...` arguments
DEBUG [2023-03-27 16:53:25] query to be sent: list(nameIncludes = "david")
SUCCESS [2023-03-27 16:53:26] Returned status code: 200
#> email handle id name
#> 1 david.old@example.com david.old ent_U2gA6a41 David Old
#> 2 david.new@example.com david.new ent_AvA2sA2X David New
Errors and messages can be injected with logger::log_errors() and
logger::log_messages().
Footnotes
-
See
inst/scripts/template.Rfor how theseauto_*.Rfiles are generated ↩