Title: | Interface to the 'Request Tracker' API |
---|---|
Description: | Provides a programmatic interface to the 'Request Tracker' (RT) HTTP API <https://rt-wiki.bestpractical.com/wiki/REST>. 'RT' is a popular ticket tracking system. |
Authors: | Bryce Mecum [aut, cre] |
Maintainer: | Bryce Mecum <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0 |
Built: | 2025-03-10 03:33:58 UTC |
Source: | https://github.com/nceas/rt |
Check that the login request was successful or not
check_login(response)
check_login(response)
response |
(httr::response) RT API login response |
(logical) TRUE if login was successful, errors out otherwise
Remove all NULL entries from a list. From plyr::compact()
.
compact(l)
compact(l)
l |
list |
RT's API, in a few cases, takes a body of key value pairs that are colon
separated and each key value pair is newline separated. Each pair is also
run through compact
to remove NULL
elements.
construct_newline_pairs(params)
construct_newline_pairs(params)
params |
(list) One or more key value pairs |
(character)
The code gives a basic idea of the format but it's basically newline-separated key-value pairs with a ': ' between them. e.g.,
parse_rt_properties(body)
parse_rt_properties(body)
body |
(character) Response body from an |
id: queue/1 Name: General
List of properties
This function essential parses the text:
"# Ticket 1 created."
parse_ticket_create_body(body)
parse_ticket_create_body(body)
body |
(character) The ticket create response body |
(numeric) The ticket ID
rt_user_create
Parse the response body from a call to rt_user_create
parse_user_create_body(body)
parse_user_create_body(body)
body |
(character) |
(numeric) The user ID
rt_api
objectPrint an rt_api
object
## S3 method for class 'rt_api' print(x, ...)
## S3 method for class 'rt_api' print(x, ...)
x |
object of class |
... |
Other arguments passed to |
rt
packagert
provides a programming interface to the
Request Tracker API.
Everything should be implemented and all functions should return a reasonably useful result that's suitable for integrating into your workflows.
Before you can do anything useful with this package, you'll need to do three things:
Determine your base URL and set it using
Sys.setenv(RT_BASE_URL="your url here)
. In most cases, this will be the
same as the URL of the page you use to log in to RT.
Determine and set your credentials. You can skip setting them if you like
and skip to step 3 or you can set them using the RT_USER
and RT_PASSWORD
environmental variables via Sys.setenv
. See rt_login
for
more.
Log in using R by calling rt_login
. See rt_login
for more.
A typical flow for setting up your R session to work with RT might look like this:
Sys.setenv(RT_BASE_URL = "http://example.com/rt", RT_USER = "[email protected]", RT_PASSWORD = "mypassword")
If you use RT a lot, you might consider putting code like the above in your
.Renviron, minus the call to rt_login()
so the environmental variables are
available but you aren't logging into RT every time you start R. See ?Startup
for more information.
Called by rt_login
and rt_login_interactive
to
do the work of logging in
rt_do_login(user, password, ...)
rt_do_login(user, password, ...)
user |
(character) Your username. |
password |
(character) Your password. |
... |
Other arguments passed to |
(logical) Either returns TRUE
if successful or errors out
Get an RT response and format it into an S3 object
rt_GET(url, raw = FALSE, ...)
rt_GET(url, raw = FALSE, ...)
url |
(character) The full RT URL |
raw |
(logical) Whether or not to return the raw response from \
codeGET ( |
... |
Other arguments passed to |
(rt_api) The parsed response from RT
Use this to log into RT at the start of your session. Once you call this function and successfully log in, calls of other functions within this package will re-use your login information automatically.
rt_login( user = Sys.getenv("RT_USER"), password = Sys.getenv("RT_PASSWORD"), ... )
rt_login( user = Sys.getenv("RT_USER"), password = Sys.getenv("RT_PASSWORD"), ... )
user |
(character) Your username. |
password |
(character) Your password. |
... |
Other arguments passed to |
The value of rt_base_url
should be the same address you use in your
web browser to log into RT (i.e., the address of the log in page).
Either TRUE
, invisibly, if logged in, or throws an error.
## Not run: # You can setup the location of your RT installation and the values for # your credentials as environmental variables Sys.setenv("RT_USER" = "user", "RT_PASSWORD" = "password", "RT_BASE_URL" = "https://demo.bestpractical.com") # And then log in directly like rt_login() # You can also skip setting `RT_USER` and `RT_PASSWORD` and specify them # directly rt_login("user", "password") # Note that you still need to set `RT_BASE_URL` ## End(Not run)
## Not run: # You can setup the location of your RT installation and the values for # your credentials as environmental variables Sys.setenv("RT_USER" = "user", "RT_PASSWORD" = "password", "RT_BASE_URL" = "https://demo.bestpractical.com") # And then log in directly like rt_login() # You can also skip setting `RT_USER` and `RT_PASSWORD` and specify them # directly rt_login("user", "password") # Note that you still need to set `RT_BASE_URL` ## End(Not run)
Wrapper for rt_login
to interactively log into RT at the start
of your session. Keeps your log-in information private.
rt_login_interactive(rt_base_url = Sys.getenv("RT_BASE"), ...)
rt_login_interactive(rt_base_url = Sys.getenv("RT_BASE"), ...)
rt_base_url |
(character) The base URL that hosts RT for your
organization. Set the base URL in your R session using
|
... |
Other arguments passed to |
## Not run: Sys.setenv(RT_BASE_URL = "https://demo.bestpractical.com") rt_login_interactive() ## End(Not run)
## Not run: Sys.setenv(RT_BASE_URL = "https://demo.bestpractical.com") rt_login_interactive() ## End(Not run)
Use this to log out of RT at the end of your session. Note: restarting your R session will also log you out.
rt_logout(...)
rt_logout(...)
... |
Other arguments passed to |
(rt_api) The parsed response from RT
## Not run: # First, log in rt_login() # Then logout rt_logout() ## End(Not run)
## Not run: # First, log in rt_login() # Then logout rt_logout() ## End(Not run)
The RT API uses overrides default HTTP behavior with their own set of status codes, messages, and response formats. This function parses that custom implementation and presents it into something that's easier to build a package with.
rt_parse_response(response, verbose = FALSE)
rt_parse_response(response, verbose = FALSE)
response |
(character) Parsed response from |
verbose |
(logical) Optional, defaults to |
For example, a response like:
"RT/4.4.3 200 Ok # Ticket 2 created.
is turned into the list:
$status [1] 200 $message [1] "Ok" $body [1] "# Ticket 2 created."
(list) List with named elements status, message, and body
POST an RT request
rt_POST(url, raw = FALSE, ...)
rt_POST(url, raw = FALSE, ...)
url |
(character) The full RT URL |
raw |
(logical) Whether or not to return the raw response from \
codePOST ( |
... |
Other arguments passed to |
(rt_api) The parsed response from RT
Get the properties of a queue
rt_queue_properties(queue, ...)
rt_queue_properties(queue, ...)
queue |
(character) The queue |
... |
Other arguments passed to |
(list) A list of queue properties
## Not run: # By default, RT installations come with a General queue # We can get its properties like this rt_queue_properties("General") ## End(Not run)
## Not run: # By default, RT installations come with a General queue # We can get its properties like this rt_queue_properties("General") ## End(Not run)
Retrieves attachment metadata. To get the attachment itself, see rt_ticket_attachment_content.
rt_ticket_attachment(ticket_id, attachment_id, ...)
rt_ticket_attachment(ticket_id, attachment_id, ...)
ticket_id |
(numeric) The ticket identifier |
attachment_id |
(numeric) The attachment identifier |
... |
Other arguments passed to |
(rt_api) An rt_api
object with the response
## Not run: # Before running rt_ticket_attachment, you'll probably want to get a list of # the attachments for a given ticket, like: attachments <- rt_ticket_attachments(1) # Ticket ID 1 # And then you can get information about a specific attachment: rt_ticket_attachment(1, 3) # Attachment 3 on ticket 1 ## End(Not run)
## Not run: # Before running rt_ticket_attachment, you'll probably want to get a list of # the attachments for a given ticket, like: attachments <- rt_ticket_attachments(1) # Ticket ID 1 # And then you can get information about a specific attachment: rt_ticket_attachment(1, 3) # Attachment 3 on ticket 1 ## End(Not run)
Gets the content of the specified attachment for further processing or
manipulation. You'll almost always want to call a second function like
content
to make the content of the
attachment usable from R.
rt_ticket_attachment_content(ticket_id, attachment_id, ...)
rt_ticket_attachment_content(ticket_id, attachment_id, ...)
ticket_id |
(numeric) The ticket identifier |
attachment_id |
(numeric) The attachment identifier |
... |
Other arguments passed to |
(rt_api) An rt_api
object with the response
## Not run: # First, get the attachment content which gives is the raw response att <- rt_ticket_attachment_content(2, 1) # Then process it directly in R httr::content(att) # Or write it to disk out_path <- tempfile() writeBin(httr::content(x, as = 'raw'), out_path) ## End(Not run)
## Not run: # First, get the attachment content which gives is the raw response att <- rt_ticket_attachment_content(2, 1) # Then process it directly in R httr::content(att) # Or write it to disk out_path <- tempfile() writeBin(httr::content(x, as = 'raw'), out_path) ## End(Not run)
Retrieves attachment metadata for a ticket in a tabular form.
rt_ticket_attachments(ticket_id, ...)
rt_ticket_attachments(ticket_id, ...)
ticket_id |
(numeric) The ticket identifier |
... |
Other arguments passed to |
Either a data.frame
or tibble
of the attachments.
## Not run: # Given a ticket exists with id '2', we can get its attachments as a table rt_ticket_attachments(2) ## End(Not run)
## Not run: # Given a ticket exists with id '2', we can get its attachments as a table rt_ticket_attachments(2) ## End(Not run)
Create a ticket
rt_ticket_create( queue, requestor = NULL, subject = NULL, cc = NULL, admin_cc = NULL, owner = NULL, status = NULL, priority = NULL, initial_priority = NULL, final_priority = NULL, time_estimated = NULL, starts = NULL, due = NULL, text = NULL, custom_field = NULL, ... )
rt_ticket_create( queue, requestor = NULL, subject = NULL, cc = NULL, admin_cc = NULL, owner = NULL, status = NULL, priority = NULL, initial_priority = NULL, final_priority = NULL, time_estimated = NULL, starts = NULL, due = NULL, text = NULL, custom_field = NULL, ... )
queue |
(character) The queue |
requestor |
(character) Requestor email address |
subject |
(character) Ticket subject |
cc |
(character) Email address to cc |
admin_cc |
(character) Admin email address to cc |
owner |
(character) Owner username or email |
status |
(character) Ticket status; typically "open", "new", "stalled", or "resolved" |
priority |
(numeric) Ticket priority |
initial_priority |
(numeric) Ticket initial priority |
final_priority |
(numeric) Ticket final priority |
time_estimated |
(character) Time estimated |
starts |
(character) Starts |
due |
(character) Due date |
text |
(character) Ticket content; if multi-line, prefix every line with a blank |
custom_field |
(vector) Takes a named vector of the custom field name and custom field value |
... |
Other arguments passed to |
(numeric) The ID of the ticket
## Not run: # We can create an empty ticket rt_ticket_create("General") # Or we can provide some of the fields rt_ticket_create("General", requestor = "[email protected]", subject = "An example ticket") ## End(Not run)
## Not run: # We can create an empty ticket rt_ticket_create("General") # Or we can provide some of the fields rt_ticket_create("General", requestor = "[email protected]", subject = "An example ticket") ## End(Not run)
Updates an existing ticket with new information.
rt_ticket_edit( ticket_id, queue = NULL, requestor = NULL, subject = NULL, cc = NULL, admin_cc = NULL, owner = NULL, status = NULL, priority = NULL, initial_priority = NULL, final_priority = NULL, time_estimated = NULL, starts = NULL, due = NULL, text = NULL, custom_field = NULL, ... )
rt_ticket_edit( ticket_id, queue = NULL, requestor = NULL, subject = NULL, cc = NULL, admin_cc = NULL, owner = NULL, status = NULL, priority = NULL, initial_priority = NULL, final_priority = NULL, time_estimated = NULL, starts = NULL, due = NULL, text = NULL, custom_field = NULL, ... )
ticket_id |
(numeric|character) The ticket number |
queue |
(character) The queue |
requestor |
(character) Requestor email address |
subject |
(character) Ticket subject |
cc |
(character) Email address to cc |
admin_cc |
(character) Admin email address to cc |
owner |
(character) Owner username or email |
status |
(character) Ticket status; typically "open", "new", "stalled", or "resolved" |
priority |
(numeric) Ticket priority |
initial_priority |
(numeric) Ticket initial priority |
final_priority |
(numeric) Ticket final priority |
time_estimated |
(character) Time estimated |
starts |
(character) Starts |
due |
(character) Due date |
text |
(character) Ticket content; if multi-line, prefix every line with a blank |
custom_field |
(vector) Takes a named vector of the custom field name and custom field value |
... |
Other arguments passed to |
(numeric) The ID of the ticket
## Not run: # First, create a ticket ticket <- rt_ticket_create("General") # Then we can update its fields rt_ticket_edit(ticket, requestor = "[email protected]", subject = "My subject") ## End(Not run)
## Not run: # First, create a ticket ticket <- rt_ticket_create("General") # Then we can update its fields rt_ticket_edit(ticket, requestor = "[email protected]", subject = "My subject") ## End(Not run)
Get a ticket's history
rt_ticket_history(ticket_id, format = "l", ...)
rt_ticket_history(ticket_id, format = "l", ...)
ticket_id |
(numeric) The ticket identifier |
format |
(character) The format of the ticket history response. Either
|
... |
Other arguments passed to |
(rt_api) An rt_api
object with the response
## Not run: # Get the full ticket history for ticket 992 rt_ticket_history(992) # Get just the ticket ID and subject for ticket 992 rt_ticket_history(992, format = "s") ## End(Not run)
## Not run: # Get the full ticket history for ticket 992 rt_ticket_history(992) # Get just the ticket ID and subject for ticket 992 rt_ticket_history(992, format = "s") ## End(Not run)
Comment on a ticket
rt_ticket_history_comment(ticket_id, comment_text, ...)
rt_ticket_history_comment(ticket_id, comment_text, ...)
ticket_id |
(numeric) The ticket identifier |
comment_text |
(character) Text that to add as a comment |
... |
Other arguments passed to |
(numeric) The ID of the ticket
## Not run: rt_ticket_history_comment(1, "Your comment here...") ## End(Not run)
## Not run: rt_ticket_history_comment(1, "Your comment here...") ## End(Not run)
Gets the history information for a single history item
rt_ticket_history_entry(ticket_id, history_id, ...)
rt_ticket_history_entry(ticket_id, history_id, ...)
ticket_id |
(numeric) The ticket identifier |
history_id |
(numeric) The history entry identifier |
... |
Other arguments passed to |
(rt_api) An rt_api
object with the response
## Not run: # Get the history entry for ticket 992 and history id 123 rt_ticket_history(992, 123) ## End(Not run)
## Not run: # Get the history entry for ticket 992 and history id 123 rt_ticket_history(992, 123) ## End(Not run)
Reply to a ticket
rt_ticket_history_reply( ticket_id, text, cc = NULL, bcc = NULL, time_worked = "0", attachment_path = NULL, ... )
rt_ticket_history_reply( ticket_id, text, cc = NULL, bcc = NULL, time_worked = "0", attachment_path = NULL, ... )
ticket_id |
(numeric) The ticket identifier |
text |
(character) Text that to add as a comment |
cc |
(character) Email for cc |
bcc |
(character) Email for bcc |
time_worked |
(character) |
attachment_path |
(character) Path to a file to upload |
... |
Other arguments passed to |
(numeric) The ID of the ticket
## Not run: # Reply to ticket 11 with a courteous message rt_ticket_history_reply(11, "Thank you. Have a great day!") ## End(Not run)
## Not run: # Reply to ticket 11 with a courteous message rt_ticket_history_reply(11, "Thank you. Have a great day!") ## End(Not run)
Gets the ticket links for a single ticket. If applicable, the following
fields will be returned: HasMember
,
ReferredToBy
, DependedOnBy
, MemberOf
, RefersTo
,
and DependsOn
.
rt_ticket_links(ticket_id, ...)
rt_ticket_links(ticket_id, ...)
ticket_id |
(numeric) The ticket identifier |
... |
Other arguments passed to |
(rt_api) An rt_api
object with the response
## Not run: # Assuming have a ticket with id 1007, we can get it links by calling rt_ticket_links(1007) ## End(Not run)
## Not run: # Assuming have a ticket with id 1007, we can get it links by calling rt_ticket_links(1007) ## End(Not run)
Edit the links on a ticket
rt_ticket_links_edit( ticket_id, referred_to_by = NULL, depended_on_by = NULL, member_of = NULL, refers_to = NULL, depends_on = NULL, ... )
rt_ticket_links_edit( ticket_id, referred_to_by = NULL, depended_on_by = NULL, member_of = NULL, refers_to = NULL, depends_on = NULL, ... )
ticket_id |
(numeric) The ticket identifier |
referred_to_by |
Tickets that are referred to |
depended_on_by |
Tickets that are depended on |
member_of |
Ticket groups? |
refers_to |
Tickets that are referred to |
depends_on |
Tickets that are depended on |
... |
Other arguments passed to |
(numeric) The ID of the ticket
## Not run: # Assuming we have tickets 20 and 21, we can make ticket 20 depend on ticket # 21 rt_ticket_links_edit(20, depends_on = 21) ## End(Not run)
## Not run: # Assuming we have tickets 20 and 21, we can make ticket 20 depend on ticket # 21 rt_ticket_links_edit(20, depends_on = 21) ## End(Not run)
Merge two tickets
rt_ticket_merge(origin, into)
rt_ticket_merge(origin, into)
origin |
(character|numeric) Ticket ID to merge into |
into |
(character|numeric) Ticket ID to merge |
(numeric) The ID of ticket both tickets were merged into
## Not run: # First, create two tickets ticket_one <- rt_ticket_create("General") ticket_two <- rt_ticket_create("General") # Then merge them together ticket_merge(ticket_one, ticket_two) ## End(Not run)
## Not run: # First, create two tickets ticket_one <- rt_ticket_create("General") ticket_two <- rt_ticket_create("General") # Then merge them together ticket_merge(ticket_one, ticket_two) ## End(Not run)
Retrieves ticket properties
rt_ticket_properties(ticket_id, ...)
rt_ticket_properties(ticket_id, ...)
ticket_id |
(numeric) The ticket identifier |
... |
Other arguments passed to |
(list) A list of the ticket's properties
## Not run: rt_ticket_properties(15) ## End(Not run)
## Not run: rt_ticket_properties(15) ## End(Not run)
Search RT for tickets using RT's query syntax which is documented at https://docs.bestpractical.com/rt/4.4.4/query_builder.html.
rt_ticket_search(query, orderby = NULL, format = "l", fields = NULL, ...)
rt_ticket_search(query, orderby = NULL, format = "l", fields = NULL, ...)
query |
(character) Your query (See Details) |
orderby |
(character) How to order your search results. Should be a ticket property name preceded by either a + or a - character. |
format |
(character) Either |
fields |
(character) Comma-separated list of fields to include in the results. |
... |
Other arguments passed to |
The query
parameter conforms to RT's
query syntax
and requires you to build the query yourself. A query will have one or more
parameters of the form $FIELD='$VALUE'
where $FIELD
is an RT ticket
property like Subject, Requestor, etc and $VALUE
(surrounded by single
quotes) is the value to filter by. See Examples for examples.
Either a data.frame
or tibble
(when format is l
or s
) or a
numeric vector when it's i
.
## Not run: # To return all un-owned tickets on a queue: rt_ticket_search("Queue='General' AND (Status='new')") # We can sort by date created, increasing rt_ticket_search("Queue='General' AND (Status='new')", orderby = "+Created") # If we just need a vector of ticket ids rt_ticket_search("Queue='General' AND (Status='new')", orderby = "+Created", format = "i") ## End(Not run)
## Not run: # To return all un-owned tickets on a queue: rt_ticket_search("Queue='General' AND (Status='new')") # We can sort by date created, increasing rt_ticket_search("Queue='General' AND (Status='new')", orderby = "+Created") # If we just need a vector of ticket ids rt_ticket_search("Queue='General' AND (Status='new')", orderby = "+Created", format = "i") ## End(Not run)
Create an RT API URL based on the server URL and any arguments provided
rt_url(..., query_params = NULL, base_url = Sys.getenv("RT_BASE_URL"))
rt_url(..., query_params = NULL, base_url = Sys.getenv("RT_BASE_URL"))
... |
Parts of the URL to be joined by "/" |
query_params |
(list) A named list of query parameters where the names
of the list map to the query parameter names and the values of the list map
to the query parameter values. e.g., |
base_url |
(character) The base URL that hosts RT for your organization |
This is used by rt_GET
and rt_POST
to provide
HTTP requests with an appropriate user agent.
rt_user_agent()
rt_user_agent()
(character) The user agent string for the package
Create a user
rt_user_create( name, password = NULL, email_address = NULL, real_name = NULL, organization = NULL, privileged = NULL, disabled = NULL, ... )
rt_user_create( name, password = NULL, email_address = NULL, real_name = NULL, organization = NULL, privileged = NULL, disabled = NULL, ... )
name |
(character) Optional. User name |
password |
(character) The password |
email_address |
(character) Optional. User email |
real_name |
(character) Optional. User real name |
organization |
(character) Optional. User organization |
privileged |
(numeric) Optional. User privilege status |
disabled |
(numeric) Optional. User disabled status |
... |
Other arguments passed to |
(numeric) The ID of the newly-created user
## Not run: # Create a barebones user with just a name rt_user_create("Some Person") # Create user that also has an email address rt_user_create("Person", email_address = "[email protected]") ## End(Not run)
## Not run: # Create a barebones user with just a name rt_user_create("Some Person") # Create user that also has an email address rt_user_create("Person", email_address = "[email protected]") ## End(Not run)
Edit a user's information.
rt_user_edit( user_id, password = NULL, name = NULL, email_address = NULL, real_name = NULL, organization = NULL, privileged = NULL, disabled = NULL, ... )
rt_user_edit( user_id, password = NULL, name = NULL, email_address = NULL, real_name = NULL, organization = NULL, privileged = NULL, disabled = NULL, ... )
user_id |
(numeric) The ID of the User to edit |
password |
(character) The password |
name |
(character) Optional. User name |
email_address |
(character) Optional. User email |
real_name |
(character) Optional. User real name |
organization |
(character) Optional. User organization |
privileged |
(numeric) Optional. User privilege status |
disabled |
(numeric) Optional. User disabled status |
... |
Other arguments passed to |
The ID of the edited user
## Not run: # First, create a user user_id <- rt_user_create("Example", "password", "[email protected]") # Then we can edit it rt_user_edit(user_id, real_name = "Example User") ## End(Not run)
## Not run: # First, create a user user_id <- rt_user_create("Example", "password", "[email protected]") # Then we can edit it rt_user_edit(user_id, real_name = "Example User") ## End(Not run)
Get a user's properties
rt_user_properties(user_id, ...)
rt_user_properties(user_id, ...)
user_id |
(numeric) The ID of the User to edit |
... |
Other arguments passed to |
(list) A list of the user's properties
## Not run: # Assuming we have a user with id 1, we can get its properties rt_user_properties(1) ## End(Not run)
## Not run: # Assuming we have a user with id 1, we can get its properties rt_user_properties(1) ## End(Not run)
Get the version of the currently installed version of this package as a character vector
rt_version_string()
rt_version_string()
(character) The version is a character vector, e.g. "1.2.3"
Throw an error if the RT status code is an error status
stopforstatus(response)
stopforstatus(response)
response |
(response) An |
Either nothing, or throws an error
tidy_long_search_result
tidy_long_search_result(result)
tidy_long_search_result(result)
result |
(list) List of lists from search results |
A data.frame
or tibble
Try to make a tibble
try_tibble(df, coerce = TRUE)
try_tibble(df, coerce = TRUE)
df |
(data.frame) The |
coerce |
(logical) Whether or not to try coercion. Provided for upstream calling functions. |
Either a data.frame
or a tibble
Warn if a user edit response body contains warnings
warn_user_edit_warnings(body)
warn_user_edit_warnings(body)
body |
(character) |
None.