Closed Mykhailo-Zub closed 1 year ago
The documentation describes the possibility of declaring a global api_key.
api_key
Code that doesn't work:
import { config, getJson } from "serpapi"; config.api_key = process.env.API_KEY; const engine = "apple_app_store"; const params = { term: "image viewer", country: "us", lang: "en-us", device: "desktop", num: "10", page: 0, }; const json = await getJson(engine, params); console.log("JSON: ", json);
Output:
JSON: { error: 'Invalid API key. Your API key should be here: https://serpapi.com/manage-api-key' }
Code that works:
import { getJson } from "serpapi"; const engine = "apple_app_store"; const params = { api_key: process.env.API_KEY, term: "image viewer", country: "us", lang: "en-us", device: "desktop", num: "10", page: 0, }; const json = await getJson(engine, params); console.log("JSON: ", json);
JSON: { search_metadata: { id: '63971ad6e135088693c44f61', status: 'Success', json_endpoint: 'https://serpapi.com/searches/aaa6c13f6c0a76a0/63971ad6e135088693c44f61.json', created_at: '2022-12-12 12:13:10 UTC', processed_at: '2022-12-12 12:13:10 UTC', apple_app_store_url: 'https://itunes.apple.com/search?media=software&term=image+viewer&country=us&lang=en-us&entity=macSoftware&explicit=yes&limit=10&offset=0', raw_html_file: 'https://serpapi.com/searches/aaa6c13f6c0a76a0/63971ad6e135088693c44f61.html', prettify_html_file: 'https://serpapi.com/searches/aaa6c13f6c0a76a0/63971ad6e135088693c44f61.prettify', total_time_taken: 3.44 }, search_parameters: { engine: 'apple_app_store', term: 'image viewer', country: 'us', lang: 'en-us', device: 'desktop', num: '10', page: '0' }, ... }
P.S. my api_key was checked twice, it's valid.
Node version: 16.14.2
Thanks @Mykhailo-Zub for reporting this, I'll look into it!
@Mykhailo-Zub This has been fixed in 0.0.8, let me know if you still encounter issues! 🥂
@sebastianquek Everything is fine now, thanks!
The documentation describes the possibility of declaring a global
api_key
.Code that doesn't work:
Output:
Code that works:
Output:
P.S. my api_key was checked twice, it's valid.
Node version: 16.14.2