I want to import JSON data into Google Sheets using the ImportJSON function. The host requires declaring a "User-Agent" with each call:
Per the ImportJSON docs, I've extended the ImportJSONAdvanced function with a custom function to pass headers to the host:
/**
@customfunction
**/
function ImportJSON_SEC(url, query, parseOptions) {
var header = {headers: {'User-Agent': 'My Company my_company@example.com',}}
return ImportJSONAdvanced(url, header, query, parseOptions, includeXPath_, defaultTransform_)
}
I used the following formula in Google Sheets to import the file:
=ImportJSON_SEC("https://data.sec.gov/api/xbrl/companyconcept/CIK0000320193/us-gaap/Assets.json","/","noInherit,noTruncate,allHeaders")
This results in a 403 error, even though the User-Agent should have been declared:
Exception: Request failed for https://data.sec.gov returned code 403.
QUESTIONS:
Why am I getting a 403 error? What am I doing wrong?
