-
-
Save freakdesign/a1636414cce682c2c444 to your computer and use it in GitHub Desktop.
/* | |
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(); | |
})(); |
Epic! Will have to do as Shopify doesn't have access to files through the API - which is crazy.
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?
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.
Hi, looks like this has stopped working now. Would you be able to update please?
Thanks
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.
Awesome mate, thank you for the script, it worked like charm.
Ubuntu 18 & Chrome