-
Notifications
You must be signed in to change notification settings - Fork 48
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
Unexpected Behavior: error is not triggered #317
Comments
TLDR: I think an error is thrown, unless you have @llrs, Thanks for all the inside & advanced information. That helps a lot. Let me slightly restate some things to make sure I understand the problem, your suggestions, and how to reproduce it for testing. I'm getting slightly different results from you, so I want to talk through it. Did you have
@llrs and others, do you agree with these steps? Do you like the returned values below? (Except for If you want to replicate the steps below, use this line of code. (The dataset doesn't conform, but it that's irrelevant, because the privileges errors are always triggered first.) REDCapR::redcap_write(ds=mtcars, redcap_uri="https://bbmc.ouhsc.edu/redcap/api/", token="9A81268476645C4E5F03428B8AC3AA7B") Here's what > REDCapR::redcap_write(ds=mtcars, redcap_uri=credential$redcap_uri, token=credential$token)
Starting to update 32 records to be written at 2021-01-12 14:54:45.
Writing batch 1 of 1, with indices 1 through 32.
The REDCapR write/import operation was not successful. The error message was:
ERROR: You do not have API Import/Update privileges
Error in REDCapR::redcap_write(ds = mtcars, redcap_uri = credential$redcap_uri, :
The `redcap_write()` call failed on iteration 1. Here's what > REDCapR::redcap_write_oneshot(ds=returned_object1$data, redcap_uri=credential$redcap_uri, token=credential$token)
The REDCapR write/import operation was not successful. The error message was:
ERROR: You do not have API Import/Update privileges
$success
[1] FALSE
$status_code
[1] 403
$outcome_message
[1] "The REDCapR write/import operation was not successful. The error message was:\nERROR: You do not have API Import/Update privileges"
$records_affected_count
[1] NA
$affected_ids
character(0)
$elapsed_seconds
[1] 0.1930091
$raw_text
[1] "ERROR: You do not have API Import/Update privileges" Here's > REDCapR::redcap_write(ds=mtcars, redcap_uri=credential$redcap_uri, token=credential$token, continue_on_error=TRUE)
Starting to update 32 records to be written at 2021-01-12 14:59:14.
Writing batch 1 of 1, with indices 1 through 32.
The REDCapR write/import operation was not successful. The error message was:
ERROR: You do not have API Import/Update privileges
$success
[1] TRUE # <--- THIS IS WRONG and should be fixed. I'm changing the 'or' to 'and' so `FALSE` is returned. See the next commit
$status_code
[1] "403"
$outcome_message
[1] "The REDCapR write/import operation was not successful. The error message was:\nERROR: You do not have API Import/Update privileges"
$records_affected_count
[1] 0
$affected_ids
character(0)
$elapsed_seconds
[1] 0.80884
Warning message:
In REDCapR::redcap_write(ds = mtcars, redcap_uri = credential$redcap_uri, :
The `redcap_write()` call failed on iteration 1. REDCapR 0.11.0.9002; REDCap 10.5.1 |
I didn't have the I can't generate a different API for the same project. I can only delete or regenerate it (and I won't do that because it takes time to get the token approved) and I can't toggle privileges: I tried to reproduce this from another internet connection and didn't get the same result (with the same exact code used), now on library("REDCapR")
url <- "https://redcap.clinic.cat/redcap_v10.0.0/API/"
token <- Sys.getenv("REDCAP_BARCELONA")
data <- data.frame(patient = paste0("BCN 00", 5:9), record_id = 18:22,
redcap_event_name = "week_0_arm_1")
validate_for_write(data)
#> # A tibble: 0 x 4
#> # … with 4 variables: field_name <chr>, field_index <int>, concern <chr>,
#> # suggestion <chr>
da2 <- redcap_write(ds_to_write = data, redcap_uri = url, token = token)
#> Starting to update 5 records to be written at 2021-01-13 09:34:05.
#> Writing batch 1 of 1, with indices 1 through 5.
#> 13 records were written to REDCap in 0.2 seconds.
da2$affected_ids # Error
#> [1] "\t\t\t\t\t\t<form action=\"/redcap_v10.5.0/API/\" method=\"post\" name=\"form\" enctype=\"multipart/form-data\">"
#> [2] "\t\t\t\t\t\t\t<input type='hidden' name=\"token\" value=\"MYBARETOKEN!!\"><input type='hidden' name=\"content\" value=\"record\"><input type='hidden' name=\"format\" value=\"csv\"><input type='hidden' name=\"type\" value=\"flat\"><input type='hidden' name=\"data\" value=\""patient","record_id","redcap_event_name""
#> [3] ""BCN 005",18,"week_0_arm_1""
#> [4] ""BCN 006",19,"week_0_arm_1""
#> [5] ""BCN 007",20,"week_0_arm_1""
#> [6] ""BCN 008",21,"week_0_arm_1""
#> [7] ""BCN 009",22,"week_0_arm_1"\"><input type='hidden' name=\"overwriteBehavior\" value=\"overwrite\"><input type='hidden' name=\"returnContent\" value=\"ids\"><input type='hidden' name=\"returnFormat\" value=\"csv\">\t\t\t\t\t\t</form>"
#> [8] "\t\t\t\t\t\t<script type='text/javascript'>"
#> [9] "\t\t\t\t\t\tdocument.form.submit();"
#> [10] "\t\t\t\t\t\t</script>"
#> [11] "\t\t\t\t\t\t</body>"
#> [12] "\t\t\t\t\t\t</html>"
#> [13] "\t\t\t\t\t\t" Created on 2021-01-13 by the reprex package (v0.3.0) I can reproduce your example: library("REDCapR")
redcap_write(ds=mtcars, redcap_uri="https://bbmc.ouhsc.edu/redcap/api/",
token="9A81268476645C4E5F03428B8AC3AA7B")
#> Starting to update 32 records to be written at 2021-01-13 09:33:15.
#> Writing batch 1 of 1, with indices 1 through 32.
#> The REDCapR write/import operation was not successful. The error message was:
#> ERROR: You do not have API Import/Update privileges
#> Error in redcap_write(ds = mtcars, redcap_uri = "https://bbmc.ouhsc.edu/redcap/api/", : The `redcap_write()` call failed on iteration 1. Created on 2021-01-13 by the reprex package (v0.3.0) I think that I found the error: Previously there was some documentation that pointed out to this url:
Is there a way to check that I'm pointing to a valid API url or that I have the right permissions? |
Weird, I wouldn't have expected that including the "version folder" would lead to different behavior like this. This kinda suggests something changed between REDCap version 10.0.0 (ie the version in the url) and 10.5.0 (ie, the version you're currently running). I looked through the change log between 10.0.0 and 10.5.0, but didn't see anything suggesting their code changed related to this behavior. The bare token concerns me too. I can't find any post about in in the forums. But I reported your experience in the bug reports. If you have access to the forums, please provide any more info you'd like. https://community.projectredcap.org/questions/98856/bare-token-revealed-in-text-following-import-error.html By the way, I don't think this is related to the OS of the client. I did test it on my Windows desktop, linux laptop, and Linux on Travis. Thanks providing such good information. Tell me if there's something else. |
I wasn't aware that there could be multiple API versions available. Maybe the problem is that there is a mismatch between the url and the version available? Unfortunately I'm not able to register on the community site as I am not the admin of the REDCap at my institution. If I find something else using the package I'll get in touch. |
@llrs, Rob Taylor is looking into this, but needs some more info to replicate the problem. If you email me your contact info (at [email protected]), I'll show you want he's looking at, and connect you. Alternatively, you REDCap site admin can participate in the post. Again, I regret that AnswerHub is so closed off from most API developers. https://community.projectredcap.org/questions/98856/bare-token-revealed-in-text-following-import-error.html |
Thank you for taking the time to maintain and reply to users of this package!
Troubleshooter: I am not sure all the examples of the API playground work with all the options. But I assume they do, as several of them I tried did run.
Describe the behavior:
I am testing how to add data o the database through the API with REDCapR
Due to some protections on the website I think I cannot write (This is not the issue with REDCapR but it is related). However, I don't get any error message or warning that this couldn't be done, and instead
da2$affected_ids
contains the content of the website.If this is expected to be a number then I think it should check that it is not a number and return an informative error (the
da2$status_code
is 200 so it is not enough to check the response code ), something along the lines:Expected behavior: An error or an informative message of the failing nature of the operation
Desktop (please complete the following information):
Additional context: First time we are using REDCap on my institution (and I am just an advanced R user not the REDCap admin).
The text was updated successfully, but these errors were encountered: