Skip to content

Instantly share code, notes, and snippets.

@berstend
Last active November 2, 2022 23:28
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save berstend/7760130 to your computer and use it in GitHub Desktop.
Save berstend/7760130 to your computer and use it in GitHub Desktop.
Withdraw all pending invitations from LinkedIn automatically in bulk. - Or "How I stopped spamming all of my contacts with invitations". This script is super ugly (like what LinkedIn does with your email data) but worked for me. Usage: - Go to https://www.linkedin.com/inbox/invitations/sent - Open DevInspector, paste the script to the console, h…
var INCR = 16; // Number of messages per page
var SENT_URL = '//www.linkedin.com/inbox/invitations/sent?startRow=';
var loMessageLinks = []; // Main array for all contacts
var fetchMessages = function(i, cb) {
console.log('Fetching message page #' + (i+1));
$.get(SENT_URL + (i*INCR), function(data){
var $dom = $(data);
var items = []
$dom.find('.inbox-item .detail-link').each(function(i){
items.push($(this).attr('href'));
});
if (items.length > 0) {
console.log(' > Found ' + items.length + ' messages on page #' + (i+1) + ', ' + (loMessageLinks.length+items.length) + ' in total.');
$.merge(loMessageLinks, items);
cb();
} else {
console.log(' > No messages found.')
cb(new Error);
}
})
}
var followMessageLink = function(link, cb){
$.get(link, function(data){
var $dom = $(data);
var $el = undefined;
var actionURL = undefined;
$el = $dom.find(".btn-quaternary:contains('Withdraw')");
if ($el.length > 0) {
console.log(' > Withdraw');
$.get($el.attr('href'), function(data){
cb();
});
} else {
$el = $dom.find(".btn-quaternary:contains('Archive')");
console.log(' > Archive');
$.get($el.attr('href'), function(data){
cb();
});
}
});
}
iRun = 0;
var iMessage = 0;
var z = undefined;
var fetchMessageCallback = function(err) {
if (err) {
console.log('Finished message collecting. One moment please..');
z = setInterval(function(){
console.log('Processing message #' + (iMessage+1) + '/' + loMessageLinks.length);
followMessageLink(loMessageLinks[iMessage], function(){ });
iMessage = iMessage + 1;
if (iMessage >= loMessageLinks.length) {
console.log('ALL DONE');
clearInterval(z);
}
}, 5000);
} else {
iRun = iRun+1;
fetchMessages(iRun, fetchMessageCallback);
}
}
fetchMessages(0, fetchMessageCallback);
@atziolas
Copy link

It runs and says its Archiving instead if Withdrawing, but even so in the end its not executed. Help please

@Tissot1
Copy link

Tissot1 commented Sep 18, 2016

Fetching message page #1
undefined
VM912:23 > No messages found.
VM912:59 Finished message collecting. One moment please..
VM912:63 Processing message #1/0
VM912:68 ALL DONE
js?h=a06jpss2hf43xwxobn0gl598m-44hhbxag3hinac547ym9vby09-a4lcy9x33w9gvnro4s0fw3e8z-9zz2lhu3eq1epk7s…:25 GET https://www.linkedin.com/messaging/ 400 (Bad Request)

got twice this bad request despite a clean all linkedin cookies in betweeen. any help would be very appreciated-

@anthonydelgado
Copy link

I went to https://www.linkedin.com/mynetwork/invitation-manager/sent/ and ran this $('.button-tertiary-medium-muted').click();

@david-strejc
Copy link

david-strejc commented May 23, 2017

Current REALLY ugly version as I am programmer copy paster goes as this:

var i = 1;                     //  set your counter to 1

function myLoop () {           //  create a loop function
   setTimeout(function () {    
      i++;                     //  increment the counter
      if (i < 50) {            //  if the counter < 10, call the loop function
         myLoop();             //  ..  again which will trigger another
         $('.button-tertiary-medium-muted').click();
         console.log(i);
      }                        //  ..  setTimeout()
   }, 4000)
}

myLoop();

@AndrewBatey
Copy link

This last script from David works great. Thanks man

@kefCastandCrew
Copy link

Works a treat. Thanks!

@laving1977
Copy link

anthonydelgado commented on 3 Apr:
I went to https://www.linkedin.com/mynetwork/invitation-manager/sent/ and ran this $('.button-tertiary-medium-muted').click();

Worked like charm :)

@goldstein22
Copy link

I used David's script with a chrome auto-scroller add on to go through and remove 8000 connection requests outstanding.

Thanks for the help guys

Autoscroller I used: https://chrome.google.com/webstore/detail/simple-autoscroll/fgecljolecpahpphjjhfhgiimljpkodo?hl=en

@Studiofotos
Copy link

I can confirm the script from david-strejc above worked fine for me, thanks also to goldstein22 for the tip on the chrome auto-scroller add on.

I left the browser open and let it run over night, when I came to check this morning all had been withdrawn and I was able to connect to others on LinkedIn again.

@PMPmentor
Copy link

As a non-technical person, can anybody help?
I have managed to install the autscroller and found the DevInspector and copied david-strejc code.
Is there a run botton or what do I do?
Thank you

@annielagang
Copy link

@anthonydelgado Thanks for the link. I was able to retract an invite I sent by mistake. Thanks again.

@yashkumaratri
Copy link

@anthonydelgado, Worked like charm, Thanks buddy

I went to https://www.linkedin.com/mynetwork/invitation-manager/sent/ and ran this $('.button-tertiary-medium-muted').click();

@ilandsat
Copy link

@anthonydelgado Thank you very much bro. You did a great job. :) 👍

@000011111111
Copy link

000011111111 commented Sep 19, 2017

HI all,

  1. @david-strejc I was able to get your script to work with a bit of modification using the auto scroller chrome extensions default settings.

//////////////////////////////////////////
`var i = 1; // set your counter to 1

function myLoop () { // create a loop function
setTimeout(function () {
i++; // increment the counter
if (i < 1000) { // if the counter < 1000, call the loop function. I like the counter at 1000 because I am typically removing them in batches of that amount. As the script will only remove one invite per loop.
myLoop(); // .. again which will trigger another
$('.button-tertiary-medium-muted').click();
console.log(i);
} // .. setTimeout()
}, 4000)
}

myLoop();`

//////////////////////////////////


  1. @anthonydelgado I an unable to get your script to work either.

Are others experiencing the same issues?

~ Buck

@anthonydelgado
Copy link

I ran Daves script and just got "Account Network Blocked: If you're seeing a "Request Denied" error page, it's because LinkedIn has detected an abnormally high number of requests coming from your network connection. This error will automatically disappear once the network activity returns to normal."

@laue0280
Copy link

Has anyone found an update for this code?

@masassali
Copy link

masassali commented Jul 15, 2020

Try this.
#Doens't need any scrollers. Just copy / paste the code in the console and press enter.
Happy withdrawing :)

var button1 = document.getElementsByClassName("invitation-card__action-btn artdeco-button artdeco-button--muted artdeco-button--3 artdeco-button--tertiary ember-view")
var button2 = document.getElementsByClassName("artdeco-modal__confirm-dialog-btn artdeco-button artdeco-button--2 artdeco-button--primary ember-view")
setInterval(()=>{
     for(var i=0;i<button1.length;i++){
          button1[i].click()
          button2[0].click()}},1000)

@DolorHunter
Copy link

Try this.
#Doens't need any scrollers. Just copy / paste the code in the console and press enter.
Happy withdrawing :)

var button1 = document.getElementsByClassName("invitation-card__action-btn artdeco-button artdeco-button--muted artdeco-button--3 artdeco-button--tertiary ember-view")
var button2 = document.getElementsByClassName("artdeco-modal__confirm-dialog-btn artdeco-button artdeco-button--2 artdeco-button--primary ember-view")
setInterval(()=>{
     for(var i=0;i<button1.length;i++){
          button1[i].click()
          button2[0].click()}},1000)

Thanks a lot

@ai2010
Copy link

ai2010 commented Aug 9, 2020

Is there any way to delete the 'oldest invites' and leaving the newest XX: so like delete invitations until XX newest invitations are left?

@3L1AS
Copy link

3L1AS commented Sep 10, 2020

Is there any way to delete the 'oldest invites' and leaving the newest XX: so like delete invitations until XX newest invitations are left?

Yeah! That would be awesome. 😃👍

@Isarstyle
Copy link

Is there any way to delete the 'oldest invites' and leaving the newest XX: so like delete invitations until XX newest invitations are left?

you can go the the page with the maximum age of pending invitations that you like to keep, for example 1 month old, and then run the script, as it takes only the buttons that are page elements in the current page loading state, it will then delete all requests that are older until it has finished till the last page. you just have to close the browser window if it starts to remove the requests that you want to keep :)

@3L1AS
Copy link

3L1AS commented Sep 14, 2020

Doesn't work so well. But found this which is perfect: https://support.dux-soup.com/article/143-cancel-pending-invites

@nijatmursali
Copy link

This worked for me in November 2020.

WEB:

var button1 = document.getElementsByClassName("invitation-card__action-btn artdeco-button artdeco-button--muted artdeco-button--3 artdeco-button--tertiary ember-view")
var button2 = document.getElementsByClassName("artdeco-modal__confirm-dialog-btn artdeco-button artdeco-button--2 artdeco-button--primary ember-view")
setInterval(()=>{
     for(var i=0;i<button1.length;i++){
          button1[i].click()
          button2[0].click()}},1000)

Mobile:

var button1 = document.getElementsByClassName("rect-btn rect-btn_muted_tertiary rect-btn_muted rect-btn_regular ripple invite-card-withdraw-btn js-withdraw-invite-btn  js-rect-btn")
var button2 = document.getElementsByClassName("rect-btn rect-btn_tertiary  rect-btn_regular ripple primary-action  js-rect-btn")
setInterval(()=>{
     for(var i=0;i<button1.length;i++){
          button1[i].click()
          button2[0].click()}},1000)

Good luck.

@kevonc
Copy link

kevonc commented Nov 8, 2020

Thanks @nijatmursali your web script worked for me :) It seems like it withdrew 98 invitations (on the single page) each time I ran it, so if you have multiple pages, repeat the script.

@devkumar326
Copy link

@nijatmursali Thanks, Brother!!
Your Web Script Worked for me :)

@nijatmursali
Copy link

Good luck guys. I also added it to my gists, I will make changes for it to work without refreshing.

@abhisheksarkar30
Copy link

A simple script to remove those pending sent invitations, can be found at https://github.com/abhisheksarkar30/js-stuffs/blob/master/Scripts/WithdrawAllSentRequestsOnLinkedIn.js

@gostgmaer
Copy link

This worked for me in November 2020.

WEB:

var button1 = document.getElementsByClassName("invitation-card__action-btn artdeco-button artdeco-button--muted artdeco-button--3 artdeco-button--tertiary ember-view")
var button2 = document.getElementsByClassName("artdeco-modal__confirm-dialog-btn artdeco-button artdeco-button--2 artdeco-button--primary ember-view")
setInterval(()=>{
     for(var i=0;i<button1.length;i++){
          button1[i].click()
          button2[0].click()}},1000)

Mobile:

var button1 = document.getElementsByClassName("rect-btn rect-btn_muted_tertiary rect-btn_muted rect-btn_regular ripple invite-card-withdraw-btn js-withdraw-invite-btn  js-rect-btn")
var button2 = document.getElementsByClassName("rect-btn rect-btn_tertiary  rect-btn_regular ripple primary-action  js-rect-btn")
setInterval(()=>{
     for(var i=0;i<button1.length;i++){
          button1[i].click()
          button2[0].click()}},1000)

Good luck.

July 6 2021
Working
Thanks

@ethicalhavoc
Copy link

This Worked for me in 2021- 2022

var button1 = document.getElementsByClassName("invitation-card__action-btn artdeco-button artdeco-button--muted artdeco-button--3 artdeco-button--tertiary ember-view")
var button2 = document.getElementsByClassName("artdeco-modal__confirm-dialog-btn artdeco-button artdeco-button--2 artdeco-button--primary ember-view")
setInterval(()=>{
for(var i=0;i<button1.length;i++){
button1[i].click()
button2[0].click()}},1000)

@Othership
Copy link

Othership commented Nov 2, 2022

Enjoy - from othership.com

var button1 = document.getElementsByClassName("invitation-card__action-btn artdeco-button artdeco-button--muted artdeco-button--3 artdeco-button--tertiary ember-view")
var button2 = document.getElementsByClassName("artdeco-modal__confirm-dialog-btn artdeco-button artdeco-button--2 artdeco-button--primary ember-view")
setInterval(()=>{
for(var i=0;i<button1.length;i++){
button1[i].click()
while(button2.length > 0) {
button2[0].click()
break
}
}},1000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment