Save Images from Unsplash

This base uses the Unsplash API to search for images and save them to your base for review.

The base is published on the Airtable Universe here.

To use this base, copy it from the Universe into your workspace. You will need an Airtable Pro account and access to the scripting block to make it work.

To get going, go to the Unsplash Developer pages, create an account, then create an Unsplash application. This will create an access key and a secret key for the app (we only need the access key).

Open the script block in Airtable, click on “Edit” and replace the access key default string with your access key:

Close the script editor and run the script. You will be prompted to enter a search term:

Enter your term and click on “Next”. The script will pull 10 images from Unsplash using their API based on your search term. These will be stored in the “Photos” table:

For a nicer look, switch to the gallery view:

The script saves the image, the image link, the photographer’s name and the search term you entered.

The script is marked up with comments to explain what it is doing at each step, but any questions, please add a comment below.

Happy photo hunting!

JB

1 Like

This is the script:

// Add your Unsplash API access key here
let access_key = "YOUR_API_ACCESS_KEY";

// set the unsplash search url
let unsplash_url = 'https://api.unsplash.com/search/photos?query=';

// get the search term from the user
let query = await input.textAsync('Enter a photo search term');

// make the full unsplash url to be queried
let url = unsplash_url + query.toLowerCase();

// set the headers required to make the API call to Unsplash
let headers = {
    "Accept-Version": "v1",
    "Authorization": "Client-ID " + access_key
}

// set the table that stores the photos
let table = base.getTable("Photos");

// make the API call
let response = await fetch(url, {
    method: "GET",
    headers: headers
})

// get the API response
let data = await response.json();

// for each result in the response, create a record in Airtable
// saving the photographer's name, link to the photo on Unsplash 
// and save the photo into Airtable
// Other fields are returned - uncomment the console.log below to see options
data.results.forEach(async photo => {
    // console.log(photo);
    let newRecord = await table.createRecordAsync({
        "Search Term": query,
        "Photographer": photo.user.name,
        "Link": photo.links.html,
        "Photo": [{"url": photo.urls.regular}]
    });    
})

This is pretty nifty.

Makes me think what can be done with automated pdf creation.

ie:

  1. http post html string with airtable field data
  2. response -> upload pdf into attachment field

this would sort of solve the feature request where folks would like to “save the PDF from page designer” to the record


https://pdfcrowd.com/

1 Like

I’ve had to unpublish the base from the Airtable Universe for now. There were some breaking changes to the Script Block (see here). Not a big deal for my example above, but now when you access the base from the Universe the script is lost and the default script shown.

In the meantime, here’s a link that users can access the base with:

JB

@JonathanBowen we just added a setting for controlling when scripts should be shared:

Do you mind turning that on in your shared base & re-publishing to Universe? Thank you!

@Kasra - thanks, now working here:

1 Like