0

Trying to override the Apify's Google Scraper actor's queries by passing the data object as given below. I am getting 400 and and 403 error message. When I remove the data playload, it works fine. It then returns the result with the default queries.

1) What is the right way to pass the playload to override the queries parameters.

2) How can I send multiple search queries like "link building", "link building service" ?

$.ajax({
      url : 'https://api.apify.com/v2/actor-tasks/XXXXXXX/runs?token=XXXXXXXX&waitForFinish=120,  
      method : 'POST',
      contentType: 'application/json',
       data : {   // when I add this I get 400 error.
          "queries" : "Outreach link building",
        },
       success:function(result) {
            console.log(result);
      } 

});

Thanks in advance.

Ben Jonson
  • 565
  • 7
  • 22
  • I'm sorry I had bad code example in https://stackoverflow.com/questions/57848672/how-to-call-apify-google-search-scrapper-task-using-jquery-ajax, I fixed it. – drobnikj Sep 10 '19 at 08:34
  • Status 400 means, that the task/actor doesn't exist. https://apify.com/docs/api/v2#/introduction/errors – drobnikj Sep 10 '19 at 08:39

1 Answers1

0

1) You need to stringified JSON and use proper dataType:

$.ajax({
      url : 'https://api.apify.com/v2/actor-tasks/XXXXXXX/runs?token=XXXXXXXX&waitForFinish=120',  
      method : 'POST',
      contentType: 'application/json',
      dataType: 'json',
      data : JSON.stringify ({
          "queries" : "Outreach link building"
      }),
      success:function(result) {
        console.log(result);
      } 
});

You can read about that in this post.

2) If you want to send multiple queries you need to separate them using the new line:

{
  "queries": "Outreach link building\nquery"
}
drobnikj
  • 448
  • 2
  • 7
  • It's working. Can you please also let me know how can I accomplish the flowing: Once a task is completed, trigger an event to read the dataset. The goal is to either know that the dataset is ready or autmatically get the dataset so that I can save them in database. – Ben Jonson Sep 10 '19 at 10:26