# Schedule Search

All POST data should be sent in the JSON format (UTF-8 encoding). The task setting is done using the POST method when the array of tasks is sent into json format. We recommend to set up to 100 tasks at a time. Such limits were set due to the variations of task setting methods that you may use.

{% hint style="danger" %}
Requires authentication
{% endhint %}

<mark style="color:green;">`POST`</mark> `https://api.serphouse.com/trends/schedule`

#### Headers

| Name                                            | Type   | Description              |
| ----------------------------------------------- | ------ | ------------------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer \<YOUR\_API\_KEY> |
| Content-Type<mark style="color:red;">\*</mark>  | String | application/json         |

#### Request Body

| Name                                                 | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ---------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| time\_zone\_offset<mark style="color:red;">\*</mark> | integer | <p>Pass Timezone offset.<br>You can receive the list of available timezone of google trend with their offset value by making a separate request to the  <a href="timezone-list">List of timezone and offset</a></p>                                                                                                                                                                                                                                                                                        |
| keywords<mark style="color:red;">\*</mark>           | string  | <p>Search keyword single <code>google</code> or multiple <code>google, youtube, yahoo</code><br>Note:- maximum 5 string search. </p><p><br></p>                                                                                                                                                                                                                                                                                                                                                            |
| time<mark style="color:red;">\*</mark>               | string  | <p><code>now 1-H</code> - Return past hour result<br><code>now 4-H</code> Return past 4 hours result<br><code>now 1-d</code> Return past 1 day result<br><code>now 7-d</code> Return past 7 days result<br><code>today 1-m</code> Return past 1 month result<br><code>today 3-m</code> Return past 3 months result<br><code>today 12-m</code> Return past 1 year result<br><code>today 5-y</code> Return past 5 years result<br><code>2021-01-24 2021-02-25</code> To extract custom date range result</p> |
| property                                             | string  | <p>property should contain bellow list only.<br><code>""</code> - Web Search(Default)<br><code>images</code> - Image Search<br><code>news</code> - News Search<br><code>froogle</code> - Google Shopping<br><code>youtube</code> - YouTube Search</p>                                                                                                                                                                                                                                                      |
| category                                             | integer | <p>by Default category is <code>0</code> for all categories.<br>You can receive the list of available categories of google trend with their sub category by making a separate request to the <a href="categories-list">List of Categories</a></p>                                                                                                                                                                                                                                                          |
| geo                                                  | string  | <p>by Default geo is <code>""</code> for Worldwide.<br>You can receive the list of available geo of google trend with their state by making a separate request to the <a href="country-and-state-list">List of Country and State</a>.</p>                                                                                                                                                                                                                                                                  |
| langauge\_code                                       | string  | <p>by Default language code is <code>"en"</code>.<br>You can receive the list of available language of google trend with their ids by making a separate request to the <a href="language-list">List of Language</a>.</p>                                                                                                                                                                                                                                                                                   |
| postback\_url                                        | url     | <p>return URL for sending task results<br>If you specify the <a href="../../introduction/webhook#postback-url">Postback URL</a> there will be no need to use Get Trend search Tasks Results for obtaining results. We will send the result of a completed task by a POST request to the URL as soon as the task is completed.<br>You can change your webhook setting from <a href="https://app.serphouse.com/wehook-setting">Webhook Settings Page</a>.</p>                                                |
| pingback\_url                                        | url     | <p><a href="../../introduction/webhook#pingback-url">Pingback URL</a> is Notification URL of a completed task,<br><strong>When a task is completed we will notify you by GET request sent to the URL you have specified.</strong> You can change your webhook setting from <a href="https://app.serphouse.com/wehook-setting">Webhook Settings Page</a>.</p>                                                                                                                                               |

{% tabs %}
{% tab title="200: OK Successful operation" %}

```json
{
    "status": "success",
    "msg": "Task(s) successfully scheduled",
    "results": [
        {
            "status": 0,
            "cronned": 0,
            "user_id": 4281,
            "se": "",
            "q": "google",
            "domain": "trends.google.com",
            "lang": "en",
            "country_iso": null,
            "loc": "US",
            "lat": null,
            "long": null,
            "device": "desktop",
            "serp_type": "trends",
            "verbatim": 0,
            "pingback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58",
            "postback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58",
            "is_scheduled": 1,
            "page": 0,
            "time_zone_offset": -330,
            "time": "now 1-d",
            "category": 0,
            "property": "youtube",
            "updated_at": "2023-05-27T06:43:44.000000Z",
            "created_at": "2023-05-27T06:43:44.000000Z",
            "id": 76849564
        }
    ]
}
```

{% endtab %}

{% tab title="400: Bad Request Failed validation" %}

```json
{
    "status": "error",
    "msg": "validation_error",
    "error": {
        "data.0.time_zone_offset": [
            "The data.0.time_zone_offset field is required."
        ]
    }
}
```

{% endtab %}

{% tab title="402: Payment Required Failed operation" %}

```json
{
    "status": "error",
    "msg": "Your SERPHouse account has either run out of available credits (try upgrading your Plan), or there is a payment problem.",
    "error": ""
}
```

{% endtab %}

{% tab title="401: Unauthorized Unauthenticated" %}

```json
{
    "status": "error",
    "msg": "Unauthenticated"
}
```

{% endtab %}
{% endtabs %}

## Example request:

{% tabs %}
{% tab title="BASH" %}

```bash
curl --location --request POST 'https://api.serphouse.com/trends/schedule' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "data" : [
        {
            "time_zone_offset": -330,
            "keywords": "google",
            "time": "now 1-d",
            "property": "youtube",
            "category": 0,
            "geo": "us",
            "langauge_code": "en",
            "postback_url": "https:\/\/webhook.site\/277a9716-691d-4255-be89-a5f8f0240b58",
            "pingback_url": "https:\/\/webhook.site\/277a9716-691d-4255-be89-a5f8f0240b58"
        }
    ]
}'
```

{% endtab %}

{% tab title="RUBY" %}

```ruby
require "uri"
require "json"
require "net/http"

url = URI("https://api.serphouse.com/trends/schedule")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer <YOUR_API_KEY>"
request.body = JSON.dump({
  "data": [
    {
      "time_zone_offset": "-330",
      "keywords": "google",
      "time": "now 1-d",
      "property": "youtube",
      "category": "0",
      "geo": "us",
      "langauge_code": "en",
      "postback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58",
      "pingback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58"
    }
  ]
})

response = https.request(request)
puts response.read_body

```

{% endtab %}

{% tab title="PYTHON" %}

```python
import requests
import json

url = "https://api.serphouse.com/trends/schedule"

payload = json.dumps({
  "data": [
    {
      "time_zone_offset": -330,
      "keywords": "google",
      "time": "now 1-d",
      "property": "youtube",
      "category": 0,
      "geo": "us",
      "langauge_code": "en",
      "postback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58",
      "pingback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58"
    }
  ]
})
headers = {
  'Authorization': 'Bearer <YOUR_API_KEY>',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

{% endtab %}

{% tab title="NODE.JS" %}

```javascript
var axios = require('axios');
var data = JSON.stringify({
  "data": [
    {
      "time_zone_offset": "-330",
      "keywords": "google",
      "time": "now 1-d",
      "property": "youtube",
      "category": "0",
      "geo": "us",
      "langauge_code": "en",
      "postback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58",
      "pingback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58"
    }
  ]
});

var config = {
  method: 'post',
  url: 'https://api.serphouse.com/trends/schedule',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Bearer <YOUR_API_KEY>'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$serphouse = new SERPHouse\SERPHouseClient('YOUR_API_KEY');
$body = [
  "data" => [
      [
          'time_zone_offset' => '-330',
          'keywords' => 'google,youtube',
          'time' => 'now 1-d',
          'property' => 'youtube',
          'category' => '0',
          'geo' => 'us',
          'language_code' => 'en',
          "postback_url" =>  "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58",
          "pingback_url" => "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58"
      ]
  ]
];
$res = $serphouse->trends->schedule($body);
echo $res->getResponse();

```

{% endtab %}

{% tab title="JAVA" %}

```java
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");

JSONObject jsonObject = new JSONObject();
jsonObject.put("data", new JSONArray()
        .put(new JSONObject()
                .put("time_zone_offset", -330)
                .put("keywords", "google")
                .put("time", "now 1-d")
                .put("property", "youtube")
                .put("category", 0)
                .put("geo", "us")
                .put("langauge_code", "en")
                .put("postback_url", "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58")
                .put("pingback_url", "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58")
        )
);

String bodyJson = jsonObject.toString();

RequestBody body = RequestBody.create(mediaType, bodyJson);

Request request = new Request.Builder()
  .url("https://api.serphouse.com/trends/schedule")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Bearer <YOUR_API_KEY>")
  .build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
```

{% endtab %}

{% tab title="JAVASCRIPT" %}

```javascript
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <YOUR_API_KEY>");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "data": [
    {
      "time_zone_offset": -330,
      "keywords": "google",
      "time": "now 1-d",
      "property": "youtube",
      "category": 0,
      "geo": "us",
      "langauge_code": "en",
      "postback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58",
      "pingback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58"
    }
  ]
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://api.serphouse.com/trends/schedule", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

{% endtab %}

{% tab title="GO" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.serphouse.com/trends/schedule"
  method := "POST"

  payload := strings.NewReader(`{
    "data": [
        {
            "time_zone_offset": "-330",
            "keywords": "google",
            "time": "now 1-d",
            "property": "youtube",
            "category": "0",
            "geo": "us",
            "langauge_code": "en",
            "postback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58",
            "pingback_url": "https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58"
        }
    ]
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("Authorization", "Bearer <YOUR_API_KEY>")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="C#/.NET" %}

```csharp
var client = new RestClient("https://api.serphouse.com/trends/schedule");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer <YOUR_API_KEY>");
var body = @"
{
    ""data"": [
        {
            ""time_zone_offset"": ""-330"",
            ""keywords"": ""google"",
            ""time"": ""now 1-d"",
            ""property"": ""youtube"",
            ""category"": ""0"",
            ""geo"": ""us"",
            ""language_code"": ""en"",
            ""postback_url"": ""https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58"",
            ""pingback_url"": ""https://webhook.site/277a9716-691d-4255-be89-a5f8f0240b58""
        }
    ]
}";
request.AddParameter("application/json", body,  ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
```

{% endtab %}
{% endtabs %}
