arthur-shaw / susoapi

R interface for Survey Solutions' APIs
https://arthur-shaw.github.io/susoapi/
Other
9 stars 5 forks source link

Workspaces #2

Closed ashwinikalantri closed 3 years ago

ashwinikalantri commented 3 years ago

get_questionnaire will only show questionnaires from the primary workspace. There is no way to set another workspace.

get_workspace gives an error - Could not resolve host: server.name:9700api; Unknown error

check_credentials is not able to verify api users unless they are a part of primary workspace.

arthur-shaw commented 3 years ago

Thanks so much for flagging these issues. Let me take each one in turn:

get_questionnaire will only show questionnaires from the primary workspace. There is no way to set another workspace.

check_credentials is not able to verify api users unless they are a part of primary workspace.

These two issues will require revisions to the functions to be "scoped" to workspaces. Both of these particular functions rely on the GET ​/api​/v1​/interviews endpoint, which has seen a soft deprecation in SuSo 21.05. (Note: I've not updatd my code yet for that release.) Both functions will likely need to shift to the GraphQL endpoint. This is easy to do, and I'm only waiting on confirmation from the SuSo dev team about the deprecation and how the questionnaires object works with GraphQL (i.e., looks to have required a workspace argument). Stay tuned.

These two issues may point to the need for a migration to scoped functions overall. This is again a point for which I am awaiting feedback from the SuSo dev team. For example, following the logic of the GET ​/api​/v1​/interviews endpoint getting deprecated, then many other endpoints should have the same fate (e.g., assignments are also specific to workspaces). But it's unclear whether there will be a v2 of the REST endpoints that are require workspaces or whether this will mean a global migration from REST to GraphQL endpoints.

I'll open one or more new issues for the points above once I learn more--hopefully early next week.

get_workspace gives an error - Could not resolve host: server.name:9700api; Unknown error

Unfortunately, I could not replicate this issue with my 21.05.2 (build 31189) SuSo instance. Also, the error message makes me wonder if the server address is incorrect when executing this command.

Could you please open a separate issue on this and provide a pseudo reprex? I know you can't share logins, but it would be good to see your code, your session info, etc.

Also, could you try running this code interactively, and checking objects and monitoring errors along the way? This is basically a "defunctionized" version of an internal function that simply checks how many workspaces exist (here). The issues you encounter will hopefully help me understand what might be going on.

# load necessary libraries
library("httr")
library("jsonlite")

# populate parameters
start <- 0
length <- 1
user_id <- ""
include_disabled = "false"
server = Sys.getenv("SUSO_SERVER")
user = Sys.getenv("SUSO_USER")
password = Sys.getenv("SUSO_PASSWORD")

# form the base URL
base_url <- paste0(server, "api/v1/workspaces")

# compose query
# match function params to expected query params
query <- list(
    Start = start,
    Length = length,
    UserId = user_id,
    IncludeDisabled = include_disabled
)
# remove those note specified
query <- query[query != ""]

# compose the full URL: base + query parameters
url <- httr::modify_url(
    url = base_url,
    query = query
)

# get workspaces
response <- httr::GET(
    url = url,
    httr::authenticate(user = user, password),
    httr::accept_json(),
    httr::content_type_json()
)

# return count of workspaces
workspace_count <- jsonlite::fromJSON(content(response, as = "text"), flatten = TRUE)$TotalCount
ashwinikalantri commented 3 years ago

Thanks for the quick response.

For get_workspace function, I was able to locate the error. I entered "server.name:9700" as the server name. Adding a / at the end ("server.name:9700/") resolved the issue.

base_url <- paste0(server, "api/v1/workspaces") should have a / making it base_url <- paste0(server, "/api/v1/workspaces"). Its is not usual to add the / at the end of the server name.

arthur-shaw commented 3 years ago

Thanks for so quickly spotting the underlying issue. I addressed it in #3 . I also created a #4 to deal with get_questionnaires, which may be one in a broader set of functions to update.

@ashwinikalantri , please let me know if I missed anything. If not, let's close this issue and pursue the other issues that, quite helpfully, it spawned.

Greatly appreciate your help troubleshooting!

ashwinikalantri commented 3 years ago

@arthur-shaw #3 is addressed. Closing this.