eZ Community » Forums » eZ Publish 5 Platform » Creating content using REST API in...
expandshrink

Creating content using REST API in Ezpublish 5.1

Creating content using REST API in Ezpublish 5.1

Saturday 08 June 2013 12:58:25 am - 3 replies

Hi community! 

I installed Ezpublish 5.1 from git and everything work fine (installed fine, web admin, etc).

 I can retrieve content just fine! , but I can't create  new content using the  Rest API. (post to content/objects)

every time I try to create content I get this error:

HTTP/1.1 404 Not Found
Content-Length: 29
Content-Type: application/json; charset=UTF-8
Date: Fri, 07 Jun 2013 21:46:54 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: eZ Publish
{
    "error_message": "Not Found"
}

I tried all the examples at hand (links below) and only the retrieving examples works. 

Any point in the right direction will be highly appreciated blunk.gif Emoticon

I used this sources:

https://github.com/ezsystems/ezpublish-kernel/blob/master/doc/specifications/rest/REST-API-V2.rst

https://gist.github.com/bdunogier/3918294

https://gist.github.com/bdunogier/603241

https://github.com/emodric/ezpRestScripts

 

Sunday 09 June 2013 4:47:28 pm

Hi,

First, you should make sure you're using the correct full URI. It should be something like: http://<yourhost.com>/api/ezp/v2/content/objects

Then if the URI is correct, from the specification, a POST to content/objects replies a 404 error when the parent location where you try to create the content can not be found. So you should verify that the resource (URI) in the LocationCreate struct is correct and points to an existing location. Maybe you can post the full HTTP Request (headers + body).

Besides, the sources you mentioned, I also wrote an article on how to use the eZ Publish REST API v2 with cURL, maybe this one can help you.

Cheers

Monday 10 June 2013 8:19:59 pm

Hi Damien,

Thanks for your reply.

I test your example for create image and I got the same error:

HTTP/1.1 404 Not Found
Date: Mon, 10 Jun 2013 18:02:30 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: eZ Publish
Content-Length: 29
Content-Type: application/json; charset=UTF-8
{"error_message":"Not Found"}

 

The maual say that error 404 is: "If a parent location in specified in the request body and it does not exist"

But the location in this case "/content/locations/1/43/51" exit in my ezpublish is "Media/Images" .

THE CODE

curl -u "admin:ez_password" -i -H "Accept: application/json" -H "Content-Type: application/vnd.ez.api.ContentCreate+json" -H "Expect:" -X POST -d @createimage.json http://ez5/api/ezp/v2/content/objects

**********************************************************************

createimage.json

{
  "ContentCreate": {
    "ContentType": {
      "_href": "/content/types/27"
    },
    "mainLanguageCode": "eng-GB",
    "LocationCreate": {
      "ParentLocation": {
        "_href": "/content/locations/1/43/51"
      },
      "sortField": "PATH",
      "sortOrder": "ASC"
    },
    "Section": {
      "_href": "/content/sections/3"
    },
    "fields": {
      "field": [
        {
          "fieldDefinitionIdentifier": "name",
          "fieldValue": "eZ Systems logo created with the REST API"
        },{
          "fieldDefinitionIdentifier": "image",
          "fieldValue": {
              "fileName": "ez-logo.gif",
              "fileSize": 622,
              "data": "R0lGODlhRQBGAIQTAAAAABEEASIJAkQTBCAgICIiIjMzM4gmCERERFVVVWRkZP9JD3d3d4iIiJmZmaqqqru7u8zMzO7u7v///////////////////////////////////////////////////yH5BAEKAB8ALAAAAABFAEYAAAX+ICKOZGmeaKqSzue+LyDPdG3feK7TDOzvwKAw1/PFhsikrmj8KJ9QGdNIa0yu2Kx2y+16tbymq/otm8/ZsJiMbrvTs+lvZn3b0eom+8735ql0fYJcf3MydYOJE4Uwe4qCjEeHj4mRY4GUkHFiTpiZfJadk5+gm2uepG+hjqltq6iteKZ6sLFmr6O2slKcrLpfuACIaBErxik0BCgMvmUQUdAyCM1fz9FR07XO19jUXtYyAgPj5OXm5+jpATPZuWjgAAcL8/T19vf4+QPs3l3w8vkCCtTHT1s1GgAHKhy4T1o/Lv8WSgzYEEA7YW8iTtxYr+LFYWc0cuTo8eEWkSPsJ5Y0+A1hSpIF3YV0+VJlTIxuUNZkeBOkGZ07KfbMSDMoT4cs/RU1KhSpzJ9LmeJb+XTbjIRSpw7NGTVrx61tgHqdRxVn2K5jF5T1aVUG1rRkwb5DO3Yt0atw7dnlijcvvb1n+/pVK3emYL+A5x7Om9iw28FxnZpV/BhyWQQNMmvezDmzArpey0Z7C1c0NNJpTUdBXffmaMiEpXGa/UJsa9m0Z9sOzS63btBZPfrmtDt47+FN4A04wLy58+fQo0sXcBy5D3jckCCwbgR7diHbucPw/h1IePEuyJfXcR79Bwjw48ufT7++/fsRQgAAOw=="
          }
        }
      ]
    }
  }
}

Modified on Wednesday 12 June 2013 1:55:45 am by Dailenis Frometa

Wednesday 10 July 2013 9:31:29 pm

Sorry - My Bad
Virtualhost setup has to be exactly as stated in this link : https://confluence.ez.no/display/EZP/Virtual+host+setup
Thanks! works perfect

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from