This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Blogs » Piotr Nalepa » How to get article URL with eZ JS...


How to get article URL with eZ JS REST Client?

Monday 29 December 2014 6:53:33 pm

  • Currently 3 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Do you remember my last article about eZ JS REST Client? If not, I recommend you to read it first before continuing on this one. In this, rather short, blog post I'm going to give you a code sample how to get the article user-friendly URL when creating a new content using REST Client.

The use case

Imagine, that you are creating a new article within your JS application and you are using eZ JS REST Client to store data when saving content. In return, you will get response information which does not contain any user-friendly URL to have a quick look at how the new page looks like on the website.

The solution is quite easy to implement but complex in form. You should use eZ JS REST Client to get the information about it and to be able to display a just created page in the user’s browser.


I’m going to give you an example of how to create a content from the start. Look at the piece of code below:

As you can see, to create a new content you ought to have parent location REST id and content type REST id, then you should create 2 structures: one for location and one for content. When the structures are ready, you have to make 4 subsequent requests:

  1. The first one, to create a content,
  2. The second one, to load a list of locations where a new article is reachable,
  3. Then you have to make a request to get a list of location aliases,
  4. And finally, you have to make a request to load URL alias for selected location.

The last request gives you the desired information, which is a user-friendly URL to a newly created content (a new article in that case).

Summing up

I hope you find the code sample, above, useful. The reason for making 4 subsequent request to collect required data is the REST API defines the data granularly, I mean a content data is divided into many separate pieces which can be reached separately using different requests.

Proudly Developed with from