Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion scryfall-google-sheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

const MAX_RESULTS_ = 700; // a safe max due to Google Sheets timeout system

// ---- Configure these ----
const SCRYFALL_USER_AGENT_ =
"GoogleSheets-Scryfall/1.0 via https://github.com/scryfall/google-sheets";
const SCRYFALL_ACCEPT_ = "application/json;q=0.9,*/*;q=0.8";
// -------------------------

/**
* Inserts the results of a search in Scryfall into your spreadsheet
*
Expand Down Expand Up @@ -119,7 +125,13 @@ const scryfallSearch_ = (params, num_results = MAX_RESULTS_) => {
// try to get the results from scryfall
try {
while (true) {
response = JSON.parse(UrlFetchApp.fetch(`${scryfall_url}&page=${page}`).getContentText());
response = JSON.parse(UrlFetchApp.fetch(`${scryfall_url}&page=${page}`, {
method: "get",
headers: {
"User-Agent": SCRYFALL_USER_AGENT_,
"Accept": SCRYFALL_ACCEPT_,
},
}).getContentText());

if (!response.data) {
throw new Error("No results from Scryfall");
Expand Down