Search code examples
apify

No `input` is fetched in the Apify cloud


I've loaded the project to the Apify cloud and as I run it with input, the problem is so funny: No input found!. It works smooth at my PC though.

Run log:

2019-08-20T13:17:57.313Z ACTOR: Creating Docker container.
2019-08-20T13:17:58.013Z ACTOR: Starting Docker container.
2019-08-20T13:17:59.614Z INFO: System info {"apifyVersion":"0.13.7","apifyClientVersion":"0.5.14","osType":"Linux","nodeVersion":"v10.16.0"}
2019-08-20T13:18:00.081Z input: null
2019-08-20T13:18:00.083Z The function passed to Apify.main() threw an exception:
2019-08-20T13:18:00.085Z TypeError: Cannot read property 'concurrency' of null
2019-08-20T13:18:00.086Z     at Apify.main (/home/myuser/main.js:71:36) 
2019-08-20T13:18:00.087Z     at process._tickCallback (internal/process/next_tick.js:68:7)

Input:

{   
"page_handle_max_wait_time" : 2,
"concurrency" : 6,
"max_requests_per_crawl" : 10000, 
"retireInstanceAfterRequestCount": 5000,
...
}

The code has a decent way to call for the INPUT:

const store = await Apify.openKeyValueStore('default'); 
const input = await store.getValue('INPUT'); 
console.log('input:', input);

The log shows the input variable is null...

Can you explain why?


Solution

  • In the cloud, the default store is not named "default" (that is basically just a dummy name in the local runs). To open a default store, you should simply call the openKeyValueStore without any params:

    const store = await Apify.openKeyValueStore();
    const input = await store.getValue('INPUT'); 
    

    This works locally too.

    There is a shorter version for records in the default store:

    const input = await Apify.getValue('INPUT'); 
    

    or preferred for input:

    const input = await Apify.getInput();
    

    All of this is documented and explained in Docs and tutorials for the SDK.