This documentation is for a version that has reached its End Of Life. Such versions are no longer supported and don't receive security updates. Consider updating to a newer version.
Depending on the HTTP method used, different actions will be possible on the same resource. Example:
Action
Description
GET /content/objects/2/versions/3
Fetches data about version #3 of Content item #2
PATCH /content/objects/2/versions/3
Updates the version #3 draft of Content item #2
DELETE /content/objects/2/versions/3
Deletes the (draft or archived) version #3 from Content item #2
COPY /content/objects/2/versions/3
Creates a new draft version of Content item #2 from its version #3
PUBLISH /content/objects/2/versions/3
Promotes the version #3 of Content item #2 from draft to published
OPTIONS /content/objects/2/versions/3
Lists all the methods usable with this resource, the 5 ones above
The following list of available methods gives an overview of the kind of action a method triggers on a resource, if available.
For method action details per resource, see the REST API reference.
Using custom HTTP methods can cause issues with several HTTP proxies, network firewall/security solutions and simpler web servers.
To avoid issues with this, REST API allows you to set these using the HTTP header X-HTTP-Method-Override alongside the standard POST method
instead of using a custom HTTP method. For example: X-HTTP-Method-Override: PUBLISH
If applicable, both methods are always mentioned in the specifications.
In order to specify a SiteAccess when communicating with the REST API, provide a custom X-Siteaccess header.
Otherwise, the default SiteAccess is used.
The following example shows what could be a SiteAccess called restapi dedicated to REST API accesses:
1234
GET / HTTP/1.1
Host: api.example.com
Accept: application/vnd.ez.api.Root+json
X-Siteaccess: restapi
One of the principles of REST is that the same resource (such as Content item, Location, Content Type) should be unique.
It allows caching your REST API using a reverse proxy such as Varnish.
If the same resource is available in multiple locations, cache purging is noticeably more complex.
This is why SiteAccess matching with REST is not enabled at URL level (or domain).
On top of methods, HTTP request headers allow you to personalize the request's behavior.
On every resource, you can use the Accept header to indicate which format you want to communicate in, JSON or XML.
This header is also used to specify the response type you want the server to send when multiple types are available.
Accept: application/vnd.ez.api.Content+xml to get Content (full data, Fields included) as XML
Accept: application/vnd.ez.api.ContentInfo+json to get ContentInfo (metadata only) as JSON
The Destination request header is the request counterpart of the Location response header.
It is used for a COPY, MOVE or SWAP operation to indicate where the resource should be moved, copied to or swapped with by using the ID of the parent or target Location.
You can pass some short scalar parameters in the URIs or as GET parameters, but other resources need heavier structured payloads passed in the request body,
in particular the ones to create (POST) or update (PATCH) items.
In the REST API reference, request payload examples are given when needed.
When creating a Content item, a special payload is needed if the ContentType has some Image or BinaryFile Fields as files need to be attached. See the example of a script uploading images below.
When searching for Content items (or Locations), the query grammar is also particular. See the Search section below.
<?phpdeclare(strict_types=1);if($argc<2){// Print script usageecho"Usage: php {$argv[0]} <FILE_PATH> [<IMAGE_NAME>]\n";exit(1);}if(!is_file($argv[1])){echo"{$argv[1]} doesn't exist or is not a file.\n";exit(2);}// URL to Ibexa DXP installation and its REST API$host='api.example.com';$scheme='https';$api='/api/ezp/v2';$baseUrl="{$scheme}://{$host}{$api}";// User credentials$username='admin';$password='publish';// Targets$contentTypeId=5;// "Image"$parentLocationPath='1/43/51';// "Media > Images"$sectionId=3;// "Media"// Request payload$data=['ContentCreate'=>['ContentType'=>['_href'=>"$api/content/types/$contentTypeId",],'mainLanguageCode'=>'eng-GB','LocationCreate'=>['ParentLocation'=>['_href'=>"$api/content/locations/$parentLocationPath",],'sortField'=>'PATH','sortOrder'=>'ASC',],'Section'=>['_href'=>"$api/content/sections/$sectionId",],'fields'=>['field'=>[['fieldDefinitionIdentifier'=>'name','fieldValue'=>$argv[2]??basename($argv[1]),],['fieldDefinitionIdentifier'=>'image','fieldValue'=>[// Original file name'fileName'=>basename($argv[1]),// File size in bytes'fileSize'=>filesize($argv[1]),// File content must be encoded as Base64'data'=>base64_encode(file_get_contents($argv[1])),],],],],],];$curl=curl_init();$responseHeaders=[];curl_setopt_array($curl,[CURLOPT_USERPWD=>"$username:$password",CURLOPT_URL=>"$baseUrl/content/objects",CURLOPT_POST=>true,CURLOPT_POSTFIELDS=>json_encode($data),CURLOPT_HTTPHEADER=>['Content-Type: application/vnd.ez.api.ContentCreate+json','Accept: application/vnd.ez.api.ContentInfo+json',],CURLOPT_RETURNTRANSFER=>true,CURLOPT_HEADERFUNCTION=>staticfunction($curl,$header){global$responseHeaders;$responseHeaders[]=$header;returnstrlen($header);},]);$response=curl_exec($curl);if($error=curl_error($curl)){echo"cURL error: $error\n";curl_close($curl);exit(3);}if(201!==$responseCode=curl_getinfo($curl,CURLINFO_RESPONSE_CODE)){$response=json_decode($response,true);if(is_array($response)&&array_key_exists('ErrorMessage',$response)){echo"Server error: {$response['ErrorMessage']['errorCode']}{$response['ErrorMessage']['errorMessage']}\n";echo"\t{$response['ErrorMessage']['errorDescription']}\n";curl_close($curl);exit(4);}$error=$responseHeaders[0]??$responseCode;echo"Server error: $error\n";curl_close($curl);exit(5);}$response=json_decode($response,true);if(!(array_key_exists('Content',$response)&&array_key_exists('_id',$response['Content']))){echo"Response error: Unexpected response structure\n";curl_close($curl);exit(6);}$contentId=$response['Content']['_id'];curl_reset($curl);$responseHeaders=[];curl_setopt_array($curl,[CURLOPT_USERPWD=>"$username:$password",CURLOPT_URL=>"$baseUrl/content/objects/$contentId/versions/1",CURLOPT_POST=>true,CURLOPT_HTTPHEADER=>['X-HTTP-Method-Override: PUBLISH','Accept: application/json',],CURLOPT_RETURNTRANSFER=>true,CURLOPT_HEADERFUNCTION=>staticfunction($curl,$header){global$responseHeaders;$responseHeaders[]=$header;returnstrlen($header);},]);$response=curl_exec($curl);if($error=curl_error($curl)){echo"cURL error: $error\n";curl_close($curl);exit(7);}if(204!==$responseCode=curl_getinfo($curl,CURLINFO_RESPONSE_CODE)){$response=json_decode($response,true);if(is_array($response)&&array_key_exists('ErrorMessage',$response)){echo"Server error: {$response['ErrorMessage']['errorCode']}{$response['ErrorMessage']['errorMessage']}\n";echo"\t{$response['ErrorMessage']['errorDescription']}\n";curl_close($curl);exit(8);}$error=$responseHeaders[0]??$responseCode;echo"Server error: $error\n";exit(9);}echo"Success: Image Content item created with ID $contentId and published\n";curl_close($curl);exit(0);
The model allows combining criteria using the logical operators AND, OR and NOT.
Almost all Search Criteria are available in REST API. The suffix Criterion is added when used with REST API.
Almost all Sort Clauses are available too. They require no additional prefix or suffix.
The search request has a Content-Type: application/vnd.ez.api.ViewInput+xml or +json header to specify the format of its body's payload.
The root node is <ViewInput> and it has two mandatory children: <identifier> and <Query>.
You can add version=1.1 to the Content-Type header to support the distinction between ContentQuery and LocationQuery instead of just Query which implicitly looks only for Content items.
The following examples search for article and news typed Content items everywhere or for Content items of all types directly under Location 123. All those Content items must be in the standard Section.
In JSON, the structure for ContentTypeIdentifierCriterion with multiple values has a slightly different format as keys must be unique.
In JSON, if there is only one item in SortClauses, it can be passed directly without an array to wrap it.
You can omit logical operators. If Criteria are of mixed types, they are wrapped in an implicit AND.
If they are of the same type, they are wrapped in an implicit OR.
For example, the AND operator from previous example's Filter could be removed.