REST API

Author Message

B Pierre

Friday 17 June 2011 2:53:48 am

Hi,

I try to do a REST API but i have a problem... I used this documentation : http://share.ez.no/learn/ez-publish/extending-ez-publish-s-rest-api-developer-preview-2, http://doc.ez.no/eZ-Publish/Technical-manual/4.5/Features/Rest-API.

 

Problem is : when i try to access a ressource i have an error message :

http://xxx.xxx.xxx.xxxx/api/ezp/content/node/63

"No Authorization header found"

 

This is my virtual host config :

"
 NameVirtualHost xxx.xxx.xxx.xxx

<VirtualHost *:80>

    DocumentRoot /ezFolder
    ServerName xxx.xxx.xxx.xxx
    ServerAlias xxx.xxx.xxx.xxx

    <Directory  /ezFolder>
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <IfModule mod_php5.c>
        php_admin_flag safe_mode Off
        php_admin_value register_globals 0
        php_value magic_quotes_gpc 0
        php_value magic_quotes_runtime 0
        php_value allow_call_time_pass_reference 0
    </IfModule>

    DirectoryIndex index.php

    # Rewrite rules to enable virtual host mode of eZ Publish
    # Secures eZ Publish by making sure only certain folders is accessible directly
    <IfModule mod_rewrite.c>
        RewriteEngine On
        # REST API
        RewriteRule ^/api/ /index_rest\.php [L]
        
        RewriteRule ^/([^/]+/)?content/treemenu.* /index_treemenu\.php [L]
        RewriteRule ^/var/([^/]+/)?storage/images(-versioned)?/.* - [L]
        RewriteRule ^/var/([^/]+/)?cache/(texttoimage|public)/.* - [L]
        RewriteRule ^/design/[^/]+/(stylesheets|images|javascript)/.* - [L]
        RewriteRule ^/share/icons/.* - [L]
        RewriteRule ^/extension/[^/]+/design/[^/]+/(stylesheets|flash|images|lib|javascripts?)/.* - [L]
        RewriteRule ^/packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L]
        RewriteRule ^/packages/styles/.+/thumbnail/.* - [L]
        RewriteRule ^/var/storage/packages/.* - [L]

        # Makes it possible to placed your favicon at the root of your
        # eZ Publish instance. It will then be served directly.
        RewriteRule ^/favicon\.ico - [L]
        # Uncomment the line below if you want you favicon be served from the standard design.
        # You can customize the path to favicon.ico by replacing design/standard/images/favicon.ico
        # by the adequate path.
        #RewriteRule ^/favicon\.ico /design/standard/images/favicon\.ico [L]
        RewriteRule ^/design/standard/images/favicon\.ico - [L]

        # Give direct access to robots.txt for use by crawlers (Google, Bing, Spammers..)
        RewriteRule ^/robots\.txt - [L]

        # Platform for Privacy Preferences Project ( P3P ) related files for Internet Explorer
        # More info here : http://en.wikipedia.org/wiki/P3p
        RewriteRule ^/w3c/p3p\.xml - [L]

        # Uncomment the following lines when using popup style debug.
        # RewriteRule ^/var/cache/debug\.html.* - [L]
        # RewriteRule ^/var/[^/]+/cache/debug\.html.* - [L]

        RewriteRule .* /index\.php
    </IfModule>

    # Everything below is optional to improve performance by forcing clients to cache
    # image and design files, change the expires time to suite project needs.
    <IfModule mod_expires.c>
        <LocationMatch "^/var/[^/]+/storage/images/.*">
        # eZ Publish appends the version number to image URL (ezimage datatype)
        # so when an image is updated, its URL changes to
            ExpiresActive on
            ExpiresDefault "now plus 10 years"
        </LocationMatch>

        <LocationMatch "^/extension/[^/]+/design/[^/]+/(stylesheets|images|javascripts?|flash)/.*">
        # A good optimization if you normally don't change your design often
            ExpiresActive on
            ExpiresDefault "now plus 5 days"
        </LocationMatch>

        <LocationMatch "^/extension/[^/]+/design/[^/]+/lib/.*">
        # Libraries get a new url (version number) on updates
            ExpiresActive on
            ExpiresDefault "now plus 90 days"
        </LocationMatch>

        <LocationMatch "^/design/[^/]+/(stylesheets|images|javascripts?|lib|flash)/.*">
        # Same as above for bundled eZ Publish designs
            ExpiresActive on
            ExpiresDefault "now plus 7 days"
        </LocationMatch>

        <LocationMatch "^/share/icons/.*">
        # Icons as used by admin interface, barly change
            ExpiresActive on
            ExpiresDefault "now plus 7 days"
        </LocationMatch>

        # Depends on ezjscore.ini/[Packer]/AppendLastModifiedTime=enabled
        # so that file names change when source files are modified
        #<LocationMatch "^/var/[^/]+/cache/public/.*">
        # Force ezjscore packer js/css files to be cached 30 days at client side
            #ExpiresActive on
            #ExpiresDefault "now plus 30 days"
        #</LocationMatch>
    </IfModule>
</VirtualHost>

This is my rest.ini.append.php config :

 <?php
#?ini charset="utf-8"?

[System]
PrefixFilterClass=ezpRestDefaultRegexpPrefixFilter
ApiPrefix=/api

[ApiProvider]
ProviderClass[]

[DebugSettings]
Debug=enabled

[OutputSettings]
RendererClass[xhtml]=ezpContentXHTMLRenderer

[ezpRestContentController_viewContent_OutputSettings]
Template=rest_pagelayout.tpl

[CacheSettings]
ApplicationCache=enabled
ApplicationCacheDefault=enabled
DefaultCacheTTL=600
RouteApcCache=enabled
RouteApcCacheTTL=3600

[Authentication]
RequireAuthentication=disabled
AuthenticationStyle=ezpRestOauthAuthenticationStyle
#AuthenticationStyle=ezpRestBasicAuthStyle
RequireHTTPS=disabled

[RouteSettings]
RouteSettingImpl=ezpRestIniRouteFilter

SkipFilter[]
SkipFilter[]=ezpRestErrorController_show
SkipFilter[]=ezpRestAuthController_basicAuth
SkipFilter[]=ezpRestAuthController_oauthRequired
SkipFilter[]=ezpRestOauthTokenController_handleRequest
SkipFilter[]=myController_*;2

# RunFilter[]

[PreRoutingFilters]
Filters[]

[RequestFilters]
Filters[]

[ResultFilters]
Filters[]

[ResponseFilters]
Filters[]
?>
"

And my oauth :

     Nom:New REST application
     Description:Test REST
     Client identifier:3720b653cea47bcd09b0f2a38524c661
     Client secret:2837d9104863438aeba7eb1533ea621d
     Endpoint URI:http://xxx.xxx.xxx.xxx

 

But i think it's not necessary because i have disable the authentication.

Where i'm wrong ?

 

Thanks for your answers

Thiago Campos Viana

Saturday 18 June 2011 1:06:04 pm

Hi

I get it working, please follow the instructions on this post, also check my blog post about using basic http auth (or no auth) with jquery.

eZ Publish Certified Developer: http://auth.ez.no/certification/verify/376924

Twitter: http://twitter.com/tcv_br

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 29 2025 14:42:37
Script start
Timing: Jan 29 2025 14:42:37
Module start 'layout'
Timing: Jan 29 2025 14:42:37
Module start 'content'
Timing: Jan 29 2025 14:42:37
Module end 'content'
Timing: Jan 29 2025 14:42:37
Script end

Main resources:

Total runtime0.0143 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 588.0078151.1953
Module start 'layout' 0.00520.0023 739.203136.6016
Module start 'content' 0.00750.0051 775.804798.7656
Module end 'content' 0.01260.0016 874.570337.9766
Script end 0.0142  912.5469 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002215.1135140.0002
Check MTime0.00107.3535140.0001
Mysql Total
Database connection0.00075.249210.0007
Mysqli_queries0.003021.342930.0010
Looping result0.00000.056910.0000
Template Total0.00128.410.0012
Template load0.00096.468610.0009
Template processing0.00031.930410.0003
Override
Cache load0.00064.461310.0006
General
dbfile0.00107.214780.0001
String conversion0.00000.041840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs