tomquirk / linkedin-api

👨‍💼 LinkedIn API for Python
https://pypi.org/project/linkedin-api
MIT License
1.92k stars 426 forks source link

reply_invitation() seems not to work, returns a 404 - likely broken URL construction? #351

Closed pww217 closed 6 months ago

pww217 commented 11 months ago

I'm looking for a simple functionality here - get my invites and generally accept them except under certain conditions.

To do this I leverage get_invitations() and reply_invitation() function. The first works and the latter does not.

My code looks like this:

invites is the response of get_invitations() with no modifications. api is a regular object with username/pw auth, and I know it can return other functions correctly.

def handle_invites(api, limit=50):
    invites = api.get_invitations(limit=limit)
    for i in invites:
        urn = i["mailboxItemId"] # Tried both this and entityUrn, which should return the same value anyway. Neither worked.
        secret = i["sharedSecret"] # Extracted in string form
        # (invitation_entity_urn, invitation_shared_secret, action='accept')
        result = api.reply_invitation(urn, secret, action="reject") # Pass these as the comment above says
        print(f"Rejected invite: {result} for urn: {urn}, secret: {secret}")

And my output shows a successful pulling of the invitation, but the a 404 is returned for the POST reply, which from my limited experience with the library and the LinkedIn API looks like a malformed URL.

This debug log shows again a 200 from the GET, a 404 from the POST, and in the last line the urn and secret (altho secret is slightly altered).

DEBUG:urllib3.connectionpool:https://www.linkedin.com:443 "GET /voyager/api/relationships/invitationViews?start=0&count=50&includeInsights=True&q=receivedInvitation HTTP/1.1" 200 25316
DEBUG:urllib3.connectionpool:https://www.linkedin.com:443 "POST /voyager/apihttps://www.linkedin.com/voyager/api/relationships/invitations/7112521258587586562?action=accept HTTP/1.1" 404 51660
Accepted invite: False from urn: urn:li:invitation:7112521258587586562, secret: FGZB1F4D

I don't know if there's anything wrong with the request body itself, but it looks to me like this is a bad URL: /voyager/apihttps://www.linkedin.com/voyager/api/relationships/invitations/7112521258587586562?action=accept that seems to result from cramming a BASE_API_URL in there. Is that intentional, or something that got broken on accident? Can I submit a PR that attempts to fix?

christian-reiser commented 9 months ago

with your fix, it works for me. Thanks!

pww217 commented 9 months ago

Good to hear, if only someone would approve it :)

I find that it doesn't seem capable of rejecting invitations, but I haven't really gotten to the bottom of that one yet. But this forked version has worked for me for weeks in a row on a cron schedule now.