var apiKey = 'yd6ystbw48qc5j6v75pu32nq'; $.ajax( { type: 'GET', url: "https://api.gettyimages.com/v3/search/videos/creative?phrase=helicopter flight&fields=display_set,id,referral_destinations,thumb,title&page_size=18&page=1", beforeSend: function (request) { request.setRequestHeader("Api-Key", apiKey); } }) .done(function (data) { var istockPhotoWidgetSource = '

istockphoto logo' + ' *iStockPhoto.com commercial (HQ) royalty free items

'; for (var i = 0; i < data.videos.length; i++) { if (data.videos[i].referral_destinations[0].site_name == "istockphoto") { var url = "https://istockphoto.7eer.net/c/378674/258824/4205?u=" + encodeURI(data.videos[i].referral_destinations[0].uri); istockPhotoWidgetSource += '
' + '' + '' + data.videos[i].title + '' + '' + '
'; } else { var url = "https://istockphoto.7eer.net/c/378674/258824/4205?u=" + encodeURI(data.videos[i].referral_destinations[1].uri); istockPhotoWidgetSource += '
' + '' + '' + data.videos[i].title + '' + '' + '
'; } } $("#istockphoto-container").html(istockPhotoWidgetSource); }) .fail(function (data) { console(JSON.stringify(data, 2)); });