Skip to content

Commit

Permalink
fix: add_connection method (#453)
Browse files Browse the repository at this point in the history
* fixed add_connection method

* fixed formatting in payload of add_conection method
  • Loading branch information
yashdharme authored Nov 7, 2024
1 parent 1c33cdd commit aac62a2
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions linkedin_api/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,25 +1436,29 @@ def add_connection(self, profile_public_id: str, message="", profile_urn=None):
# We extract the last part of the string
profile_urn = profile_urn_string.split(":")[-1]

trackingId = generate_trackingId()
payload = {
"trackingId": trackingId,
"message": message,
"invitations": [],
"excludeInvitations": [],
"invitee": {
"com.linkedin.voyager.growth.invitation.InviteeProfile": {
"profileId": profile_urn
}
"inviteeUnion": {"memberProfile": f"urn:li:fsd_profile:{profile_urn}"}
},
"customMessage": message,
}
params = {
"action": "verifyQuotaAndCreateV2",
"decorationId": "com.linkedin.voyager.dash.deco.relationships.InvitationCreationResultWithInvitee-2",
}

res = self._post(
"/growth/normInvitations",
"/voyagerRelationshipsDashMemberRelationships",
data=json.dumps(payload),
headers={"accept": "application/vnd.linkedin.normalized+json+2.1"},
params=params,
)

return res.status_code != 201
# Check for connection_response.status_code == 400 and connection_response.json().get('data', {}).get('code') == 'CANT_RESEND_YET'
# If above condition is True then request has been already sent, (might be pending or already connected)
if res.ok:
return False
else:
return True

def remove_connection(self, public_profile_id: str):
"""Remove a given profile as a connection.
Expand Down

0 comments on commit aac62a2

Please sign in to comment.