0

I am using mendeley a lot for my research. I want to edit the "user-tags" for the documents in the catalog of my mendeley client. Specifically I want to add the reputation of the journal to this field (in form of h-factor or impact factor). I've successfully set up the OAuth2 Authentification and am able to retrieve all the documents in my catalog. However I am not able to change the details / sync them back.

Do you know if this would be possible with the Mendeley API?

I didn't find a method like set or sync in the documentation of the API.

from mendeley import Mendeley

# I've changed the authentication details of my script (of course)
client_id = ****
client_secret = "abcdefghijklmnop"

redirect_uri = "http://localhost:8080/someTest"

# These values should match the ones supplied when registering your application
mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

# The user needs to visit this URL, and log in to Mendeley.
login_url = auth.get_login_url()

res = requests.post(login_url, allow_redirects=False, data={
    'username': 'mymail@myprovider.net',
    'password': 'somePsasword?!'
})

auth_response = res.headers['Location']

# After logging in, the user will be redirected to a URL, auth_response.
session = auth.authenticate(auth_response)

# print(session.files.list().items)
for document in session.documents.iter(view='tags'):
    print(document.title)

a = session.documents.get("5982d0ce-0425-3548-a063-519620c17886", view='tags')
a.tags = "TESTETETSETEST"

Another option would be to just change my catalog locally on my PC, however I wasn't able to find a file / database for this in my mendeley directory

Edit:

I've tried the update() method mentioned in the API by changing the loop to the following. Which didn't solve my problem for now

for document in session.documents.iter(view='tags'):
    print(document.tags)
    document.tags = ["Test"]
    document.update()
Community
  • 1
  • 1
Björn
  • 1,610
  • 2
  • 17
  • 37

1 Answers1

0

I'm not familiar with the Mendeley Python SDK but it did seem odd to me that you didn't need to make some other calls after a.tags = "TESTETETSETEST".

Do you not need to use the update method?

customcommander
  • 17,580
  • 5
  • 58
  • 84
  • However is apparently does not change the details, since when I run the script again the print(document.tags) still returns None for all documents. The API Doc states "Updates this document." and it also returns the updated document. Is it possible that I still would have to sync / update the session? – Björn Jan 23 '19 at 14:33
  • I think the `update` method requires some arguments. Presumably the fields that you intend to update. I can't help much as I don't have much Python knowledge I'm afraid – customcommander Jan 23 '19 at 15:10
  • NW I am greatful for any help I can get at this point. Althoug I think a real Mendeley API Board would be helpful for the comunity. I tried it with document.update("tags") Resulting in a TypeError: update() takes 1 positional argument but 2 were given – Björn Jan 23 '19 at 15:14
  • This error I usually get when I use classes however this example doesnt use classes – Björn Jan 23 '19 at 15:19