Help

Scrape/upload directly from Chrome to Airtable via bookmarklet

4984 2
cancel
Showing results for 
Search instead for 
Did you mean: 

I needed to update Airtable with info pulled from a custom CMS that doesn’t have the export feature I needed, so I wrote a quick Javascript bookmarklet that scrapes the values from the page, looks up the corresponding record and updates it. Not the most robust script, but it’s saving me lots of time! Now all I have to do is browse to the page of each contact that I’m looking for and click on this bookmark.

Could easily be adapted to use Airtable as a bookmark manager, or a way to save snippets and images.

javascript:(function(){
	fields = {};
	fields["Email Address"] = jQuery("#email").val().toLowerCase();
	fields["Address"]	= jQuery("#addressstreet1").val();
	fields["Address 2"] = jQuery("#addressstreet2").val();
	fields["City"]		= jQuery("#addresscity").val();
	fields["State"]		= jQuery("#addressstate").val();
	fields["Zip"]		= jQuery("#addresspostalcode").val();
	fields["Country"]	= jQuery("#addresscountry").val();

	if (jQuery("#gender_female").is(':checked')){
		fields["Gender"]	= ["Female"];
	} else {
		fields["Gender"]	=  ["Male"];
	}

	fields["Birth Date"]	= jQuery("#birthdate").val();

	jQuery.ajax({
	  url: "https://api.airtable.com/v0/appav73I4abTMeqVh/Contacts",
	  data: { filterByFormula: "{Email Address}='"+fields["Email Address"]+"'" },
	  headers: {"Authorization": "Bearer keyxxxxxxxxxxxxxx"},
	  success: function(data){
		jQuery.ajax({
		  url: "https://api.airtable.com/v0/appav73I4abTMeqVh/Contacts/"+data.records[0].id,
		  data: {fields:fields},
		  type: 'PATCH',
		  headers: {"Authorization": "Bearer keyxxxxxxxxxxxxxxx"},
		  dataType: 'json'
		});

	  },
	  dataType: 'json'
	});

})();

For those who don’t know what bookmarklets are, here’s a quick primer: http://www.howtogeek.com/189358/beginner-geek-how-to-use-bookmarklets-on-any-device/

2 Replies 2
uu_dk
4 - Data Explorer
4 - Data Explorer

Could you talk more detail, teach me how to change the code to use ?

This is a little easier and visual: