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

REDCap now supports delete through API #76

Closed
damonms opened this issue Jul 24, 2017 · 5 comments · Fixed by #77
Closed

REDCap now supports delete through API #76

damonms opened this issue Jul 24, 2017 · 5 comments · Fixed by #77

Comments

@damonms
Copy link
Contributor

damonms commented Jul 24, 2017

Are there any plans to upgrade PyCap to include delete for records? If not, I will take a stab at it. It shouldn't take long.

Cheers from Steve and the VUIIS folks

@sburns
Copy link
Collaborator

sburns commented Jul 24, 2017

Hi Steve!

Currently no plans but I'd of course welcome a PR. I think they finally revoked my vandy credentials from REDCap, so if you submit a PR it will likely fail CI :(

@damonms
Copy link
Contributor Author

damonms commented Jul 24, 2017 via email

@remifrazierucsf
Copy link

remifrazierucsf commented Jul 24, 2017 via email

@bobromeo
Copy link

The title of this issue is not yet OK :), the Pull Request is not yet handled.
Looked into files of the branch, 'delete_record' only deletes 1 record, so the README.rst should be changed to singular.
-OR-
Better still: the .py could be changed to allow multiple records to be deleted, because the API allows for records[0], records[1] etc.
I am a noob at GitHub and Python is not my forté, but here's my 3cts solution for deleting records.
This works, but i am not yet using records[1] etc, have to dig in a bit deeper :)
Also: a nice 'delete_records' should iterate over chunks of 1000 or so ...

dataRep = {
    'token': api_key,
    'content': 'report',
    'format': 'csv',
    'report_id': '16',
    'rawOrLabel': 'raw',
    'rawOrLabelHeaders': 'raw',
    'exportCheckboxLabel': 'false',
    'returnFormat': 'csv'
}
dataDel = {
    'token': api_key,
    'action': 'delete',
    'content': 'record',
    'records[0]': 'xxx'
}
rr = requests.post(api_url, data = dataRep, verify=False)
for rrl in rr.iter_lines(chunk_size=128,decode_unicode=True):
    if(rrl != 'record_id'):
        dataDel["records[0]"] = rrl.strip('\"')
        rd = requests.post(api_url, data = dataDel, verify=False)
rr = requests.post(api_url, data = dataRep, verify=False)
print(rr.text)

@pwildenhain
Copy link
Collaborator

See my comment in the PR for how to easily delete multiple records through the API: #77 (comment)
TL:DR Change records[0] to records[] in the body of the POST request to pass a list of records to be deleted

@pwildenhain pwildenhain linked a pull request Mar 30, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

5 participants