Details
-
Bug
-
Resolution: Duplicate
-
High
-
2015.03
-
CentOS 7
PHP 5.4.16
MariaDB 15.1 Distrib 5.5.37
Description
On the Github doc that exemplifies the several usages of Rest Api 2 to handle content on eZ Publish, there are several errors and slips-of-mind.
Example:
On the "Update Content" example, using the REST request as the doc exemplifies:
I have the data source file (content.update.section.xml) according to the format on the doc:
<?xml version="1.0" encoding="UTF-8"?> <ContentUpdate> <Section href="/content/sections/3"/> </ContentUpdate>
and I run the command:
curl -X POST -i -H 'X-HTTP-Method-Override: PATCH' -H 'Accept: application/vnd.ez.api.ContentInfo+xml' -H 'Content-Type: application/vnd.ez.api.ContentUpdate+xml' -d @update.content.section.xml http://ezp5.dev.vagrant/api/ezp/v2/content/objects/58 -H 'Cookie: eZSESSID=bqo6h9msga38mliqcpls7tukq1' -H 'X-CSRF-Token: dvqBqwOn1ar4llVQZWi5Z365NzDXUHmG2DGcOdXzWlw'
I get error:
HTTP/1.1 400 Bad Request Date: Mon, 23 Mar 2015 14:50:17 GMT Server: Apache/2.4.6 (CentOS) PHP/5.4.16 X-Powered-By: PHP/5.4.16 Cache-Control: private Vary: Cookie,Authorization Content-Length: 3693 Connection: close Content-Type: application/vnd.ez.api.ErrorMessage+xml <?xml version="1.0" encoding="UTF-8"?> <ErrorMessage media-type="application/vnd.ez.api.ErrorMessage+xml"><errorCode>400</errorCode><errorMessage>Bad Request</errorMessage><errorDescription>Invalid format for <Section> reference in <ContentUpdate>.</errorDescription><trace>#0 /var/www/html/ezpublish5/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/REST/Common/Input/ParsingDispatcher.php(79): eZ\Publish\Core\REST\Server\Input\Parser\ContentUpdate->parse(Array, Object(eZ\Publish\Core\REST\Common\Input\ParsingDispatcher)) #1 /var/www/html/ezpublish5/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/REST/Common/Input/Dispatcher.php(115): eZ\Publish\Core\REST\Common\Input\ParsingDispatcher->parse(Array, 'application/vnd...') #2 /var/www/html/ezpublish5/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/REST/Server/Controller/Content.php(126): eZ\Publish\Core\REST\Common\Input\Dispatcher->parse(Object(eZ\Publish\Core\REST\Common\Message)) #3 [internal function]: eZ\Publish\Core\REST\Server\Controller\Content->updateContentMetadata('58') #4 /var/www/html/ezpublish5/ezpublish/bootstrap.php.cache(3022): call_user_func_array(Array, Array) #5 /var/www/html/ezpublish5/ezpublish/bootstrap.php.cache(2984): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #6 /var/www/html/ezpublish5/ezpublish/bootstrap.php.cache(3133): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #7 /var/www/html/ezpublish5/ezpublish/bootstrap.php.cache(2377): Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #8 /var/www/html/ezpublish5/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php(490): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #9 /var/www/html/ezpublish5/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php(60): Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(Object(Symfony\Component\HttpFoundation\Request), true, NULL) #10 /var/www/html/ezpublish5/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php(261): Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache->forward(Object(Symfony\Component\HttpFoundation\Request), true) #11 /var/www/html/ezpublish5/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php(278): Symfony\Component\HttpKernel\HttpCache\HttpCache->pass(Object(Symfony\Component\HttpFoundation\Request), true) #12 /var/www/html/ezpublish5/vendor/ezsystems/ezpublish-kernel/eZ/Bundle/EzPublishCoreBundle/HttpCache.php(39): Symfony\Component\HttpKernel\HttpCache\HttpCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true) #13 /var/www/html/ezpublish5/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php(207): eZ\Bundle\EzPublishCoreBundle\HttpCache->invalidate(Object(Symfony\Component\HttpFoundation\Request), true) #14 /var/www/html/ezpublish5/vendor/friendsofsymfony/http-cache-bundle/SymfonyCache/EventDispatchingHttpCache.php(101): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 /var/www/html/ezpublish5/web/index.php(81): FOS\HttpCacheBundle\SymfonyCache\EventDispatchingHttpCache->handle(Object(Symfony\Component\HttpFoundation\Request)) #16 {main}</trace><file>/var/www/html/ezpublish5/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/REST/Server/Input/Parser/ContentUpdate.php</file><line>47</line></ErrorMessage>
I have to change the data to be sent to the following format (change the path):
<?xml version="1.0" encoding="UTF-8"?> <ContentUpdate> <Section href="/api/ezp/v2/content/sections/3"/> </ContentUpdate>
to get a:
HTTP/1.1 200 OK Date: Mon, 23 Mar 2015 14:51:12 GMT Server: Apache/2.4.6 (CentOS) PHP/5.4.16 X-Powered-By: PHP/5.4.16 Cache-Control: private Accept-Patch: application/vnd.ez.api.ContentUpdate+xml Vary: Cookie,Authorization Content-Length: 1288 Content-Type: application/vnd.ez.api.ContentInfo+xml <?xml version="1.0" encoding="UTF-8"?> <Content media-type="application/vnd.ez.api.ContentInfo+xml" href="/api/ezp/v2/content/objects/58" remoteId="115536b84726ddb2184014682753b794" id="58"><ContentType media-type="application/vnd.ez.api.ContentType+xml" href="/api/ezp/v2/content/types/16"/><Name>footer</Name><Versions media-type="application/vnd.ez.api.VersionList+xml" href="/api/ezp/v2/content/objects/58/versions"/><CurrentVersion media-type="application/vnd.ez.api.Version+xml" href="/api/ezp/v2/content/objects/58/currentversion"/><Section media-type="application/vnd.ez.api.Section+xml" href="/api/ezp/v2/content/sections/1"/><MainLocation media-type="application/vnd.ez.api.Location+xml" href="/api/ezp/v2/content/locations/1/2/60"/><Locations media-type="application/vnd.ez.api.LocationList+xml" href="/api/ezp/v2/content/objects/58/locations"/><Owner media-type="application/vnd.ez.api.User+xml" href="/api/ezp/v2/user/users/14"/><lastModificationDate>2012-11-12T17:31:44+00:00</lastModificationDate><publishedDate>2012-11-12T15:54:38+00:00</publishedDate><mainLanguageCode>eng-GB</mainLanguageCode><alwaysAvailable>false</alwaysAvailable><ObjectStates media-type="application/vnd.ez.api.ContentObjectStates+xml" href="/api/ezp/v2/content/objects/58/objectstates"/></Content>
as expected.
This was a found-and-tried example. Many more may exist and perhaps these should be tested and revised when incorrectly documented.