Appearance
API Entry
Compatibility
- EE2
- EE3
- EE4
- EE5
- EE6
- EE7
Installation
The Auth API comes natively with Webservice module.
Methods
create_entry
Short name | Description | |
---|---|---|
channel_name | The name of the channel where the entry must be inserted | Required |
title | The title for the entry | Required |
status | The status of the entry | Optional |
allow_comments | Allow comments? | Optional |
sticky | Is the entry sticky? | Optional |
custom_fields | Any custom fields can be added | Optional |
category | array of category ids | Optional |
member_id | member_id | Optional, otherwise this is the logged user |
Request
Array
(
[status] => Closed
[title] => Test entry
[sticky] => y
[allow_comments] => n
//custom fields
[news_body] => This is a full body text
[news_extended] => This is some small text
[category] => Array(
1,2,3,4
)
[custom_file_field] => Array(
'filedata' => base64_encode(file_get_contents('path_to_image.jpg')),
'filename' => 'filename.jpg',
'dir_id' => 6
)
)
read_entry
See search_entry method because of v3.5 they are the same
update_entry
Short name | Description | |
---|---|---|
entry_id | The entry ID of the entry that you are going to update | Required |
search[] | You can also identify the entry with a search param (See https://docs.reinos.nl/webservice/#search-mechanism) | Required |
title | The title for the entry | Optional |
status | The status of the entry | Optional |
allow_comments | Allow comments? | Optional |
sticky | Is the entry sticky? | Optional |
custom_fields | Any custom field(s) | Optional |
category | array of category ids | Optional |
member_id | member_id | Optional, otherwise this is the logged user |
Request with ENTRY_ID
Array
(
[entry_id] => 1
[status] => Closed
[title] => Test entry
[sticky] => y
[allow_comments] => n
//custom fields
[news_body] => This is a full body text
[news_extended] => This is some small text
)
Request with SEARCH When you are using the search param, The webservice will return an error if multiple errors are found. To ignore this error you can use the force
param.
Please note that updating by Entry_id is safer, but it will cost you an extra request.
Array
(
[search] => Array
(
[custom_field] => =test // = sign is for an explicit search. See the https://docs.reinos.nl/webservice/#search-mechanism for more info
[force] => true // marked that in case of mulitple entries, you will update the first one.
)
[status] => Closed
[title] => Test entry
[sticky] => y
[allow_comments] => n
//custom fields
[news_body] => This is a full body text
[news_extended] => This is some small text
)
delete_entry
Short name | Description | |
---|---|---|
entry_id | The entry ID | Required |
Request
Array
(
[entry_id] => 14
)
search_entry
Note: the order of the request will be the order of the query
Short name | Description | |
---|---|---|
channel | If you use only the channel_name you wil get all entries in this channel | Optional |
channel_id | Search on Channel ID | Optional |
limit | The limit, can be used in conjunction with the offset | Optional |
offset | the offset, can be used in conjunction with the limit | Optional |
custom_fields | any other custom field | Optional |
orderby | sorting data based on a field | Optional |
sort | set the sort | Optional |
entry_id | If selecting just one entry by entry_id | Optional |
url_title | Search on an URL Title | Optional |
status | The status of an entry | Optional |
grid_field/matrix_field | Search in any grid/matrix field with the regular search | Optional |
grid_field[col_name]/matrix_field[cell_name] | Search in any grid/matrix cell where you can search on an exact col_name/cell_name with the use of the search mechanism below | Optional |
output_fields | specify the field to output (applied also on the relationships) | Optional |
search_all | Magic keyword that will search in all entry custom fields | Optional |
start_on | give a date to start from | Optional |
stop_before | give a date to stop before | Optional |
cat:[field_name] | search on category fields (values are cat_id group_id cat_name cat_url_title your_custom_field ) | Optional |
include | include more data in the result data[include]=channel|categories|author | Optional |
return | To return only the stats, use this param data[return]=meta | Optional |
Search mechanism
Basic
Type | Operator | Example |
---|---|---|
Contains | <empty> | data[body]=test |
Contains with wildcard | <empty> | data[body]=~test what result in %test |
Contains NOT | <empty> | data[body]=not test |
"Exact" Matching | = | data[body]==test |
Numeric Matching | < > <= >= | data[body]=>10 |
Including / Excluding Empty Fields | IS_EMPTY | data[body]=IS_EMPTY |
Including / Excluding Empty Fields NOT | IS_EMPTY | data[body]=not IS_EMPTY |
OR / AND
By default we build the query with AND. To change this to OR, simply add or
to a value.
data[title]=or john
Multiple values
To use multiple values for a field, just use a pipeline |
or a comma ,
AND values for the same field are not possible due EE limitation
data[title]=test|john
will be in MySQL
title = 'test' OR title = 'john'
Groups
You can also using to group values together like you can do in a normal Database query (field_1 = '4' OR field_1 = '5') AND (field_1 = '2' OR field_1 = '3'')'
AND values for the same field are not possible due EE limitation
Group name can be anything, it should be unique so you can create multiple groups
Request group
data[group_one_name_just_pick_one][group_and][][title]=test|john&ata[group_two_name_just_pick_one][group_and][][title]=willem|doe
(title = 'test' OR title = 'john') AND (title = 'willem' OR title = 'doe')
Request
Array
(
[channel] => news_channel
[limit] => 25
[offset] => 5
[start_on] => 01-01-2015
[stop_before] => 31-12-2015
)
Array
(
[channel] => news_channel
[limit] => 25
[offset] => 5
[start_on] => 01-01-2015
[stop_before] => 31-12-2015
[group_and] => Array
(
[group_title] => Array
(
[0] => Array
(
[title] = john,doe
)
)
)
)
Hooks
webservice_create_entry_start
(added in v3.2.1)
$entry_data = ee()->extensions->call('webservice_create_entry_start', $entry_data);
webservice_create_entry_end
(added in v2.2)
ee()->extensions->call('webservice_create_entry_end', $entry_id, $post_data);
webservice_read_entry_start
(added in v3.2.1)
$entry_data = ee()->extensions->call('webservice_read_entry_start', $entry_data);
webservice_read_entry
(added in v4.4.2)
Runs after the validation
$entry_data = ee()->extensions->call('webservice_read_entry', $entry_data, $post_data);
webservice_read_entry_end
(added in v2.2)
$entry_data = ee()->extensions->call('webservice_read_entry_end', $entry_data);
webservice_update_entry_start
(added in v3.2.1)
$entry_data = ee()->extensions->call('webservice_update_entry_start', $entry_data);
webservice_update_entry
(added in v4.4.2)
Runs after the validation
$entry_data = ee()->extensions->call('webservice_update_entry', $entry_data, $post_data);
webservice_update_entry_end
(added in v2.2)
ee()->extensions->call('webservice_update_entry_end', $entry_data, $post_data);
webservice_delete_entry_start
(added in v3.2.1)
$entry_data = ee()->extensions->call('webservice_delete_entry_start', $entry_data);
webservice_delete_entry_end
(added in v2.2)
ee()->extensions->call('webservice_delete_entry_end', '');
webservice_modify_search
(added in v4.0)
With this hook you can extend the search by your own. Just make sure the hook will return an array of entry_ids.
$entry_ids = ee()->extensions->call('webservice_search_entry_per_entry', $values, $fields);
webservice_search_entry_per_entry
(added in v3.2)
$entry_data = ee()->extensions->call('webservice_search_entry_per_entry', $entry_data);
webservice_search_entry_per_entry
(added in v3.2)
$entry_data = ee()->extensions->call('webservice_search_entry_per_entry', $entry_data);
webservice_search_entry_start
(added in v3.2.1)
$entry_data = ee()->extensions->call('webservice_search_entry_start', $entry_data);
webservice_search_entry_end
(added in v2.2)
$entry_data = ee()->extensions->call('webservice_search_entry_end', $entry_data);
webservice_entry_row
(added in v3.5)
WIll be called when reading an entry
$entry_data = ee()->extensions->call('webservice_entry_row', $entry_data);
webservice_read_entry_matrix
(added in v4.0)
ee()->extensions->call('webservice_read_entry_matrix', $value, $col_settings);
webservice_read_entry_grid
(added in v4.0)
ee()->extensions->call('webservice_read_entry_grid', $value, $col_settings);
Examples
Create entry SOAP
<?php
//file data
$image = 'file.jpg';
$file = base64_encode(file_get_contents($image));
$client = new SoapClient('http://domain.com/index.php/webservice/soap?wsdl', array('trace' => 1));
$reponse = $client->create_entry(array(
'username' => 'testUsername',
'password' => 'testPassword'
), array(
'channel_name' => 'news',
'status' => 'Open',
'title' => 'test entry',
'sticky' => 'y',
'allow_comments' => 'n',
'category' => '1|2|3',
'filefield' => array(
'filedata' => $file,
'filename' => 'file.jpg',
'dir_id' => 6
)
));
?>
Create entry REST (with an image)
<?php
$url = 'http://domain.com/index.php/webservice/rest/create_entry';
//set POST variables
$fields = array(
'auth' => array(
'username' => 'admin',
'password' => 'test123',
),
'data' => array(
'channel_name' => 'test_channel',
'title' => 'Test entry',
)
);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, urldecode(http_build_query($fields)));
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
Create entry XMLRPC
<?php
//http://gggeek.github.io/phpxmlrpc/
include("xmlrpc/xmlrpc.inc");
$c = new xmlrpc_client('http://domain.com/index.php/webservice/xmlrpc');
$x = new xmlrpcmsg('create_entry', array(
php_xmlrpc_encode(array(
'username' => 'admin',
'password' => 'test123',
)),
php_xmlrpc_encode(array(
'channel_name' => 'test_channel',
'title' => 'Test entry',
)),
));
$c->return_type = 'phpvals';
$r =$c->send($x);
?>