- PHP: >= 5.6
- Laravel/ Lumen Framework: 4.* or newer
`composer require megaads/apify-client-php`
use Megaads\ApifyClient\Client;
$query = Client::endpoint("product", [
Client::OPTION_API_HOST => "https://api.domain.com",
Client::OPTION_API_AUTH => "token=dsfqwe123sdf2342c",
Client::OPTION_REQUEST_HEADER => ["Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l"]
]);Add a custom parameter to request URL
$query->addField("customer_id", 123);
$query->addField("version", "1.0.0");The simplest method to see the generated request URL
$query->toURL();| Parameter | Required | Default | Description |
|---|---|---|---|
| page_id | No | 0 | Page index, start at 0 |
| page_size | No | 50 | Number of rows to retrieve per page |
$query->pageId(0);
$query->pageSize(100);$query->sort("user_id");$query->sort("-created_at");$query->sort(["user_id", "-created_at"]);Select columns from the records. SQL aggregate functions such as COUNT, MAX, MIN, SUM, AVG, SQL aliases are also available
$query->select("id");
$query->select(["content", "user_id", "sum(view_count) as view_sum"]);Group the result-set by one or more columns and combine with aggregate functions using Selection
$query->select(["user_id", "sum(view_count) as view_sum"]);
$query->group("user_id");| Operator | Condition | For example |
|---|---|---|
| Client::SELECTION_EQUAL | Equal to | $query->filter("user_id", Client::SELECTION_EQUAL, 1); |
| Client::SELECTION_NOT_EQUAL | Not equal | $query->filter("user_id", Client::SELECTION_NOT_EQUAL, 1); |
| Client::SELECTION_GREATER | Greater | $query->filter("user_id", Client::SELECTION_GREATER, 1); |
| Client::SELECTION_GREATER_EQUAL | Greater or equal | $query->filter("user_id", Client::SELECTION_GREATER_EQUAL, 1); |
| Client::SELECTION_LESS | Less | $query->filter("user_id", Client::SELECTION_LESS, 1); |
| Client::SELECTION_LESS_EQUAL | Less or equal | $query->filter("user_id", Client::SELECTION_LESS_EQUAL, 1); |
| Client::SELECTION_IN | In | $query->filter("user_id", Client::SELECTION_IN, [1,2,3]); |
| Client::SELECTION_NOT_IN | Not in | $query->filter("user_id", Client::SELECTION_NOT_IN, [1,2,3]); |
| Client::SELECTION_BETWEEN | Between | $query->filter("user_id", Client::SELECTION_BETWEEN, [1,20]); |
| Client::SELECTION_NOT_BETWEEN | Not between | $query->filter("user_id", Client::SELECTION_NOT_BETWEEN, [1,20]); |
| Client::SELECTION_LIKE | Like | $query->filter("title", Client::SELECTION_LIKE, "hello"); |
| Client::SELECTION_NOT_LIKE | Not like | $query->filter("title", Client::SELECTION_NOT_LIKE, "hello"); |
Apify provides the ability to embed relational data into the results
For example
$query->embed("cities");
$query->embed(["nation", "districts"]);$query->filter("nation.location_code", Client::SELECTION_EQUAL, "EU");
$query->filter("districts.name", Client::SELECTION_LIKE, land);$query->find(1);$query->get();Response format
[
"meta" => [
"has_next" => true,
"total_count" => 100,
"page_count" => 2,
"page_size" => 50,
"page_id" => 0
],
"result" => [],
"status" => "successful"
]$query->first();
Response format
[
"result" => [],
"status" => "successful"
]$query->count();
Response format
[
"result" => 50,
"status" => "successful"
]Increment/ Decrement: Provides convenient methods for incrementing or decrementing the value of a selected column
$query->select("view_count");
$query->increment();
Response format
[
"result" => 1,
"status" => "successful"
]use Megaads\ApifyClient\Client;
$query = Client::request("https://api.domain.com/product",
Client::METHOD_POST,
[
"name" => "Hello",
"code" => "C0001"
],
[
"Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l"
]);The Apify is open-sourced software licensed under the MIT license
Email: [email protected]
Skype: phult.bk