Skip to content

Instantly share code, notes, and snippets.

@arfaram
Last active July 17, 2017 15:25
Show Gist options
  • Save arfaram/d2914bf089f6fa4db1eb23cf23fe1844 to your computer and use it in GitHub Desktop.
Save arfaram/d2914bf089f6fa4db1eb23cf23fe1844 to your computer and use it in GitHub Desktop.
RichText_REST_API_ezpublish
curl -i -X POST http://site.ezplatform.com/api/ezp/v2/content/objects --data @content.xml -H 'Content-Type:application/vnd.ez.api.ContentCreate+xml' -H 'Accept:application/xml' --user admin:publish
#REST API Tested with ezplatform 1.5 (using RichTextField )
<?xml version="1.0" encoding="UTF-8"?>
<ContentCreate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ContentType href="/api/ezp/v2/content/types/14"/>
<mainLanguageCode>eng-GB</mainLanguageCode>
<LocationCreate>
<ParentLocation href="/api/ezp/v2/content/locations/1/2/58/59/61" />
<priority>0</priority>
<hidden>false</hidden>
<sortField>PATH</sortField>
<sortOrder>ASC</sortOrder>
</LocationCreate>
<Section href="/api/ezp/v2/content/sections/1"/>
<alwaysAvailable>true</alwaysAvailable>
<remoteId></remoteId>
<fields>
<field>
<fieldDefinitionIdentifier>name</fieldDefinitionIdentifier>
<languageCode>eng-GB</languageCode>
<fieldValue>This is a title6</fieldValue>
</field>
<field>
<fieldDefinitionIdentifier>body</fieldDefinitionIdentifier>
<languageCode>eng-GB</languageCode>
<fieldValue>
<value key="xml"><![CDATA[<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit"><h1>gtz</h1><p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet</p></section>]]></value>
</fieldValue>
</field>
</fields>
</ContentCreate>
Tested with ezplatform 1.5.1
See Fix: https://github.com/ezsystems/ezpublish-kernel/commit/1163b53059329cd9a22ae3a2d92d709a1f48fc88 ( eZ version < 1.5.1)
eZPublish5 REST API Doc: https://github.com/ezsystems/ezpublish-kernel/blob/master/doc/specifications/rest/REST-API-V2.rst#contentupdate-xml-schema
Basic authentication in security.yml:
ezpublish_rest:
pattern: ^/api/ezp/v2
stateless: true
ezpublish_http_basic:
realm: eZ Publish REST API
Note: this example will just create a draft !
To publish the draft USE:
POST
http://site.ezplatform.com/api/ezp/v2/content/objects/108/versions/1
with Header:
- Basic Auth
- X-HTTP-Method-Override:Publish
CURL publish example:
curl -i -X POST http://site.ezplatform.com/api/ezp/v2/content/objects/106/versions/1 -H 'X-HTTP-Method-Override:Publish' --user admin:publish
PS: 106 is the ObjectId returning by the first draft Response.
Response Example:
HTTP/1.1 204 No Content <--- everything is OK
Date: Sun, 23 Oct 2016 19:52:38 GMT
Server: Apache/2.4.7 (Ubuntu)
Cache-Control: no-cache
X-Cache-Debug: 1
Vary: Cookie,Authorization
X-Debug-Token: 76a43b
X-Debug-Token-Link: http://site.ezplatform.com/_profiler/76a43b
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8
More Info on ezpublish5, ezplatform REST API publish content:
https://github.com/ezsystems/ezpublish-kernel/blob/master/doc/specifications/rest/REST-API-V2.rst#publish-a-content-version
Status Code: 201 Created
Accept-Patch: application/vnd.ez.api.ContentUpdate+xml
Cache-Control: no-cache
Connection: close
Content-Length: 1131
Content-Type: application/vnd.ez.api.ContentInfo+xml
Date: Sun, 23 Oct 2016 16:23:22 GMT
Location: /api/ezp/v2/content/objects/104
Server: Apache/2.4.7 (Ubuntu)
Vary: Cookie,Authorization
X-Cache-Debug: 1
X-Debug-Token: d02431
X-Debug-Token-Link: http://site-ezplatform.com/_profiler/d02431
@bdunogier
Copy link

bdunogier commented Oct 19, 2016

The input for RichText should look like this (don't forget to wrap it into <![CDATA[...]]> in XML):

<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit">
    <h2>Welcome to eZ Platform</h2>
    <p>Congratulations, you just installed eZ Platform. eZ Platform is the new generation Content Management Platform
        from eZ Systems and the eZ Community replacing eZ Publish, our previous software.
    </p>
    <h3>Need some guidance?</h3>
    <p>Check out the following resources:</p>
    <h4>
        <a href="https://doc.ez.no/display/USER/">User Manual</a>
        for eZ Platform (and eZ Studio)
    </h4>
    <h4>
        <a href="https://doc.ez.no/display/DEVELOPER/">Technical doc</a>
        for eZ Platform (and eZ Publish Platform new stack)
    </h4>
    <h4>
        <a href="https://doc.ez.no/display/DEVELOPER/Building+a+Bicycle+Route+Tracker+in+eZ+Platform">eZ Platform</a>
        developer tutorial
    </h4>
    <h4>
        <a href="https://doc.ez.no/display/MAIN/Transitioning+from+eZ+Publish+to+eZ+Platform+and+eZ+Studio%3A+Feature+Comparison">
            Comparison guide
        </a>
        between eZ Platform and eZ Publish Platform
    </h4>
    <h3>Contribute to the project?</h3>
    <p>Join the community:</p>
    <h4>
        <a href="https://github.com/ezsystems">Github repositories</a>
        open to the public
    </h4>
    <h4>Register to the community on <a href="http://share.ez.no">share.ez.no</a>, the community site, to access forums,
        tutorials and blogs
    </h4>
    <h4>Join the conversation on
        <a href="http://ez-community-on-slack.herokuapp.com/">the eZ Community Slack</a>
    </h4>
    <p>Good luck!</p>
</section>

@arfaram
Copy link
Author

arfaram commented Oct 19, 2016

Thanks for your update. Now getting validation error "Argument '$inputValue' is invalid: Could not create XML document: Extra content at the end of the document"
I added the XML Tag at the file beginn and checked your gist also hier: https://gist.github.com/bdunogier/3918294
everything looks good !
I think from 1.5.0 to 1.5.1 this is not the only Fix (ezsystems/ezpublish-kernel@1163b53). something still missed

@arfaram
Copy link
Author

arfaram commented Oct 23, 2016

Okay get it works today

  • < paragraph > Tag not allowed
  • Content must be within < p > or valid HTML Tag < h1 > etc
  • Line break will not works between < value key="xml" > and < ![CDATA ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment