Instead of ‘login’ and ‘password’ use your credentials from https://app.dataforseo.com/api-dashboard
<?php // You can download this file from here https://cdn.dataforseo.com/v3/examples/php/php_RestClient.zip require('RestClient.php'); $api_url = 'https://api.dataforseo.com/'; try { // Instead of 'login' and 'password' use your credentials from https://app.dataforseo.com/api-dashboard $client = new RestClient($api_url, null, 'login', 'password'); } catch (RestClientException $e) { echo "n"; print "HTTP code: {$e->getHttpCode()}n"; print "Error code: {$e->getCode()}n"; print "Message: {$e->getMessage()}n"; print $e->getTraceAsString(); echo "n"; exit(); } try { // using this method you can get a list of locations // GET /v3/serp/{{low_se_name}}/{{low_se_type}} // in addition to '{{low_se_name}}' you can also set other search engine // the full list of possible parameters is available in documentation $result = $client->get('/v3/serp/{{low_se_name}}/{{low_se_type}}'); print_r($result); // do something with result } catch (RestClientException $e) { echo "n"; print "HTTP code: {$e->getHttpCode()}n"; print "Error code: {$e->getCode()}n"; print "Message: {$e->getMessage()}n"; print $e->getTraceAsString(); echo "n"; } $client = null; ?>
The above command returns JSON structured like this:
{ "version": "0.1.20220428", "status_code": 20000, "status_message": "Ok.", "time": "0.3936 sec.", "cost": 0, "tasks_count": 1, "tasks_error": 0, "tasks": [ { "id": "06091446-1535-0096-0000-818e81f06fdf", "status_code": 20000, "status_message": "Ok.", "time": "0.2782 sec.", "cost": 0, "result_count": 117715, "path": [ "v3", "serp", "seznam", "locations" ], "data": { "api": "serp", "function": "locations", "se": "seznam" }, "result": [ { "location_code": 2004, "location_name": "Afghanistan", "location_code_parent": null, "country_iso_code": "AF", "location_type": "Country" }, { "location_code": 2008, "location_name": "Albania", "location_code_parent": null, "country_iso_code": "AL", "location_type": "Country" }, { "location_code": 2012, "location_name": "Algeria", "location_code_parent": null, "country_iso_code": "DZ", "location_type": "Country" }, { "location_code": 2016, "location_name": "American Samoa", "location_code_parent": null, "country_iso_code": "AS", "location_type": "Country" }, { "location_code": 2020, "location_name": "Andorra", "location_code_parent": null, "country_iso_code": "AD", "location_type": "Country" }, { "location_code": 2024, "location_name": "Angola", "location_code_parent": null, "country_iso_code": "AO", "location_type": "Country" }, { "location_code": 2028, "location_name": "Antigua and Barbuda", "location_code_parent": null, "country_iso_code": "AG", "location_type": "Country" }, { "location_code": 2031, "location_name": "Azerbaijan", "location_code_parent": null, "country_iso_code": "AZ", "location_type": "Country" }, { "location_code": 2032, "location_name": "Argentina", "location_code_parent": null, "country_iso_code": "AR", "location_type": "Country" }, { "location_code": 2036, "location_name": "Australia", "location_code_parent": null, "country_iso_code": "AU", "location_type": "Country" }, { "location_code": 2040, "location_name": "Austria", "location_code_parent": null, "country_iso_code": "AT", "location_type": "Country" }, { "location_code": 2044, "location_name": "The Bahamas", "location_code_parent": null, "country_iso_code": "BS", "location_type": "Country" }, { "location_code": 2048, "location_name": "Bahrain", "location_code_parent": null, "country_iso_code": "BH", "location_type": "Country" }, { "location_code": 2050, "location_name": "Bangladesh", "location_code_parent": null, "country_iso_code": "BD", "location_type": "Country" }, { "location_code": 2051, "location_name": "Armenia", "location_code_parent": null, "country_iso_code": "AM", "location_type": "Country" }, { "location_code": 2052, "location_name": "Barbados", "location_code_parent": null, "country_iso_code": "BB", "location_type": "Country" }, { "location_code": 2056, "location_name": "Belgium", "location_code_parent": null, "country_iso_code": "BE", "location_type": "Country" } ] } ] }
You will receive the list of locations by this API call. You can filter the list of locations by country when setting a task.
Note: All locations in Russia and Belarus are no longer supported across all DataForSEO services due to the invasion of Ukraine.
Description of the fields for setting a task:
Field name | Type | Description |
---|---|---|
country |
string | country ISO code optional field specify the ISO code if you want to filter the list of locations by country example: us |
As a response of the API server, you will receive JSON-encoded data containing a tasks
array with the information specific to the set tasks.
Field name | Type | Description |
---|---|---|
version |
string | the current version of the API |
status_code |
integer | general status code you can find the full list of the response codes here |
status_message |
string | general informational message you can find the full list of general informational messages here |
time |
string | execution time, seconds |
cost |
float | total tasks cost, USD |
tasks_count |
integer | the number of tasks in the tasks array |
tasks_error |
integer | the number of tasks in the tasks array returned with an error |
tasks |
array | array of tasks |
id |
string | task identifier unique task identifier in our system in the UUID format |
status_code |
integer | status code of the task generated by DataForSEO; can be within the following range: 10000-60000 you can find the full list of the response codes here |
status_message |
string | informational message of the task you can find the full list of general informational messages here |
time |
string | execution time, seconds |
cost |
float | cost of the task, USD |
result_count |
integer | number of elements in the result array |
path |
array | URL path |
data |
object | contains the parameters passed in the URL of the GET request |
result |
array | array of results |
location_code |
integer | location code |
location_name |
string | full name of the location |
location_code_parent |
integer | the code of the superordinate location only City location_type is supported for all countries except China (where Country is also supported);don’t match locations by location_code_parent because the results for Region and Country -level results for most countries are not supported by Baidu SERP API |
country_iso_code |
string | ISO country code of the location |
location_type |
string | location type |