Skip to content

Instantly share code, notes, and snippets.

@freakdesign
Last active March 17, 2022 14:43
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save freakdesign/a1636414cce682c2c444 to your computer and use it in GitHub Desktop.
Save freakdesign/a1636414cce682c2c444 to your computer and use it in GitHub Desktop.
Get a CSV list of all files within the Files section of a Shopify account
/*
Get a list of all files within the Shopify Admin (/admin/settings/files)
This needs to be run within the Chrome Browser. Paste into the debug console and run...
A text file will download when done.
*/
(function(){
var debug = false; // enable logging
var fileArray = [];
var saveList = function(fileArray){
console.log('============ DONE. DOWNLOAD FILE ============');
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var blob = new Blob(["\ufeff",fileArray],{type:'text/plain'}),
link = window.URL.createObjectURL(blob);
a.href = link;
a.download = 'shopify-files-list' + '.txt';
a.click();
window.URL.revokeObjectURL(link);
};
var getFiles = function(url){
if(typeof(url) === 'undefined'){ var url = '/admin/settings/files?limit=250' }
$.ajax({
url: url,
success: function(d){
var html = $(d);
var fields = html.find('.next-input.next-input--readonly');
for (var i = 0; i < fields.length; i++) {
if(debug){ console.log('Adding ' + fields[i].value) }
fileArray.push(fields[i].value);
};
var next = html.find('#pagination-links li:last a');
if(!next.length || next.hasClass('disabled')){
if(fileArray.length){ saveList(fileArray) }
return;
}
var nextUrl = next[0].href;
console.log(nextUrl)
if(nextUrl.indexOf('direction=next')>-1){
if(debug){ console.log('Fields grabbed. Next page now...') }
getFiles(nextUrl);
}else{
saveList(fileArray);
}
}
});
}
getFiles();
})();
@DonExo
Copy link

DonExo commented Feb 22, 2019

Awesome mate, thank you for the script, it worked like charm.

Ubuntu 18 & Chrome

@diva-D
Copy link

diva-D commented Jan 30, 2020

Epic! Will have to do as Shopify doesn't have access to files through the API - which is crazy.

@Graciepalm
Copy link

I'm sorry to be stupid but I really need to get all my URL's from shopify files down on to a csv or spreadsheet, and I don't know how to do this using the above? Can you give me any help what to actually do please?

@th0rgall
Copy link

th0rgall commented Feb 1, 2021

Thanks loads, this still worked for me. I used this Bash script to actually download the files automatically, using CURL and the shopify-files-list.txt as input: https://gist.github.com/th0rgall/9a7ac0667cc28652f076fa71c6ae6421.

@aungar93
Copy link

Hi, looks like this has stopped working now. Would you be able to update please?
Thanks

@Hujjat
Copy link

Hujjat commented May 4, 2021

Seems like jquery is not anymore on Shopify Admin

Here is the fix.

Before running the above code, you can add jquery to console

fetch('https://code.jquery.com/jquery-latest.min.js').then(r => r.text()).then(r => eval(r))

Might help others.

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