Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for an example of Variant$update_variant(...) #199

Open
fh-kpikhart opened this issue Jul 7, 2023 · 7 comments
Open

Looking for an example of Variant$update_variant(...) #199

fh-kpikhart opened this issue Jul 7, 2023 · 7 comments

Comments

@fh-kpikhart
Copy link

fh-kpikhart commented Jul 7, 2023

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)
}
@fh-kpikhart fh-kpikhart changed the title Looking for example of Variant$update_variant(...) Looking for an example of Variant$update_variant(...) Jul 7, 2023
@aronatkins
Copy link
Contributor

Parameters are not configurable nor specifiable using the API. Unfortunately, a Shiny application is currently used for that parameter configuration.

Similar to my response to #200, we want to make this entire lifecycle better -- from creating variants to managing their persisted parameter values and also specifying ad-hoc parameter values for a specific render request.

We are already tracking this feature request internally; I've referenced this ticket to share what you're attempting.

@fh-kpikhart
Copy link
Author

Got it. Thanks for your quick responses. What can Variant$update_variant(...) be used for, if not to update parameters?

@aronatkins
Copy link
Contributor

The variant update can manage most of the fields you're seeing in the response -- its name and some of the "who gets email" fields. It is not the way to configure values-used-by-render.

@fh-kpikhart
Copy link
Author

Thank you. I know it's challenging to promise any specific timelines, but do you anticipate releasing some improvements to the Variants workflow/lifecycle in this calendar year?

(Just trying to get a very rough sense of how much ongoing manual work we're signing up for if we start using variants for dozens of reports -- and need to create them, perhaps update params at a later date, etc.)

@fh-kpikhart
Copy link
Author

fh-kpikhart commented Jul 22, 2023

Also, I'm just dropping a few errors here, as an FYI. I can open a fresh issue if you want it, but it seems like the general messaging is "there will be significant overhaul in the future; stand by."

> var
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' ) 

> class(var)
[1] "Variant" "Content" "R6" 

> var$get_subscribers()
List of 3 $ code   : int 25 $ error  : chr "The parameter is invalid." $ payload: NULL
Error in self$raise_error(res) : 
  https://rstudio-connect.prod.flatiron.io/__api__/variants/{self$get_variant()$id}/subscribers request failed with Client error: (400) Bad Request

> var$get_variant_remote()
List of 3 $ code   : int 25 $ error  : chr "The parameter is invalid." $ payload: NULL
Error in self$raise_error(res) : 
  https://rstudio-connect.prod.flatiron.io/__api__/variants/{self$get_variant()$id} request failed with Client error: (400) Bad Request

When I looked at the source code, it appeared some of these endpoint URLs were missing a call to glue() to evaluate parts of the URL such as {self$get_variant()$id}. This (a modification of a line from your source code) works:

var$get_connect()$GET(glue("variants/{id}/subscribers"))

@colearendt
Copy link
Contributor

Howdy @fh-kpikhart !

Thanks so much for the note. It looks like you may have found a legitimate bug, which we can definitely fix!

That said, we are definitely still working on refactoring the parameterization experience. Unfortunately that work has just been slowed down by some other work to support maintenance / stability. We are still chugging away though!

Although we expect that work to change the experience, we still want to be sure that the product and its available features work as expected today, which would definitely include fixing the issue you found!

@colearendt
Copy link
Contributor

Maybe give #204 a shot and see if it fixes things for you in the short term?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants