posit-dev / posit-dev/connectapi

Looking for an example of `Variant$update_variant(...)`

Open
#199 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
54
Forks
27
Avg merge
1d 3m
Merged PRs (30d)
1

Description

Can you share a working example of how to use Variant$update_variant(...), and perhaps add that example to the method's documentation? I am trying to use Variant$update_variant(...) to update Variant parameters, but am struggling to format the call correctly for it to work. My goal is to update the parameters for many Variants, in bulk. I believe this is the appropriate method for that.

I don't get any error, but I don't get a standard http response either, and the parameters are unchanged when I look at the content on the Connect server.

Attempt 1:

> guid <- "89a629d4-5535-4b87-9b5a-9e64968b6d8e"
> variant <- guid %>% 
  get_content_item_variant_by_name(.variant_name = "delivery")

> variant
RStudio Connect Content: 
  Content GUID: 89a629d4-5535-4b87-9b5a-9e64968b6d8e
  Content URL: https://rstudio-connect.prod.flatiron.io/connect/#/apps/89a629d4-5535-4b87-9b5a-9e64968b6d8e/
  Content Title: test_aml_all

content_item(client, guid = "89a629d4-5535-4b87-9b5a-9e64968b6d8e")

Variant:
  get_variant(content, key = 'nMxnF64W' ) 


> variant$update_variant(
  GOOGLE_SPREADSHEET_ID = "123"
)

Result 1:

RStudio Connect Content: 
  Content GUID: 89a629d4-5535-4b87-9b5a-9e64968b6d8e
  Content URL: https://rstudio-connect.prod.flatiron.io/connect/#/apps/89a629d4-5535-4b87-9b5a-9e64968b6d8e/
  Content Title: test_aml_all

content_item(client, guid = "89a629d4-5535-4b87-9b5a-9e64968b6d8e")

Variant:
  get_variant(content, key = 'nMxnF64W' ) 

Attempt 2:

> url <- glue::glue("variants/{variant$get_variant()$id}")
> res <- variant$get_connect()$POST(
  path = url,
  body = list(
    GOOGLE_SPREADSHEET_ID = "123"
  )
)

> res

Result 2:

$id
[1] 419

$app_id
[1] 419

$key
[1] "nMxnF64W"

$bundle_id
[1] 4280

$is_default
[1] FALSE

$name
[1] "delivery"

$email_collaborators
[1] FALSE

$email_viewers
[1] FALSE

$email_all
[1] FALSE

$created_time
[1] "2023-07-06T05:51:42.237485Z"

$rendering_id
[1] 31744

$render_time
[1] "2023-07-06T05:50:38.887516Z"

$render_duration
[1] 208630916391

$visibility
[1] "public"

$owner_id
[1] 15

My helper functions

get_content_item_variant_by_name <- function(.content_guid, .variant_name = "delivery", .url = "https://rstudio-connect.prod.flatiron.io") {
  content <- .content_guid %>%
    get_content_item_from_guid(.url)
  
  variant_key <- content %>% 
    get_variants() %>% 
    filter(name == .variant_name) %>% 
    select(key) %>% 
    pull()
  
  content %>%
    get_variant(variant_key)
}

get_content_item_from_guid <- function(.content_guid, .url = "https://rstudio-connect.prod.flatiron.io") {
  connect(.url) %>%
    content_item(.content_guid)
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the documentation and implementation for Variant$update_variant(...), then compare its expected call format with the two attempts and helper functions shown in the issue. Verify the example against a Posit Connect server and document a working bulk-parameter update example, including the expected response or result.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
api, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.