Jump to content
ryan

Pages Web Service (ServicePages)

Recommended Posts

I think the latter would be preferred method to go (language specified in the request, otherwise default returned).

Share this post


Link to post
Share on other sites

I see what you mean apeisa, but in some cases, you might want to get all the data in a single call, no?

Share this post


Link to post
Share on other sites

I see that as an edge case. I would prefer serving default lang as a default. Serving all languages as a one might be preferable in some cases, but then why not use some switch there &allLang=1

Share this post


Link to post
Share on other sites

Good point - it's closer to how PW is handling languages that way. I like the idea of a lang=all for my edge case though ;-)

  • Like 1

Share this post


Link to post
Share on other sites

I haven't tried it, but you might be able to get this module to output in different languages by combining it with the LanguageSupportPageNames module. 

Share this post


Link to post
Share on other sites

I'm trying out the module to use it as a web-service for a mobile app. I'm querying pages that have images and attachments and the returning JSON output lists the "basename" but no URL or any other way to find the asset. Is there something missing? Should I need to query something else?

Share this post


Link to post
Share on other sites

I had the same issue and hard-coded the url pointing to the asset file (using the id and basename fields)... Actually, it seemed like a workaround to me. Getting a url from the module would be much better, but I couldn't firgure out how to do that :-(

Share this post


Link to post
Share on other sites

Is there somebody with experience with the multilanguage fields in modules ?

I tried to give the language as a GET var and chaging the user object language var, but no success

I recently wrote a tiny little frontend template script for querying a product catalogue, to get JSON results back (i.e. not a module - have just discovered the module and this forum thread today). It's supposed to feed an iOS app, sooner or later. 
 
As expected from working with PW, it was all easy and straightforward.
 
Since my site in querstion is also using multilang features (4 languages, PW 2.3.2 version), I simply query
german language data via domain.com/de/API/?foo=bar?etc.etc.
and french data with domain.com/fr/API/?foo=bar?etc.etc.
 
But it would be relatively easy to output all four languages with the same "web service" URL, if really needed. I guess something like this should be all that's needed:
 
$user->language = $languages->get("en"); // the following selector query will return english
$user->language = $languages->get("fr"); // the following selector query will return french
$user->language = $languages->get("default"); // the following selector query will return default lang.
 
And if you only want to use ONE service page URL, and decide to just get ONE language back, simply use another GET param (〈=en) and a switch / if-else statement in your code.
  • Like 1

Share this post


Link to post
Share on other sites

I'm trying out the module to use it as a web-service for a mobile app. I'm querying pages that have images and attachments and the returning JSON output lists the "basename" but no URL or any other way to find the asset. Is there something missing? Should I need to query something else?

Have a look at the $config stuff here: http://cheatsheet.processwire.com/ (e.g. $config->httpHost)

Share this post


Link to post
Share on other sites
I had the same issue and hard-coded the url pointing to the asset file (using the id and basename fields)... Actually, it seemed like a workaround to me. Getting a url from the module would be much better, but I couldn't firgure out how to do that :-(

I didn't realize this aspect of the file fields output. I've put this on my to-do list for the next version of the module (actually for ProcessPageSearch, which is what this module uses). 

  • Like 2

Share this post


Link to post
Share on other sites

Hi Ryan, 

I'm trying to use various operators in Pages Web Service, but some of the operators do not seem to be working. 

^= Contains the exact word or phrase at the beginning of the field 
The key-value pairs using this operator are completely ignored. The [selector] part of the response only includes other key-value pairs.

request:  ?template=industries&title^=Tire&debug=1

response: [selector] => template=industries, limit=50

...I tried with '%=' and it works fine:

request:  ?template=industries&title%=Tire&debug=1

response: [selector] => template=industries, title%=Tire, limit=50

...also with *= works fine:

request:  ?template=industries&title*=Tire&debug=1

response: [selector] => template=industries, title*=Tire, limit=50

and, of course '=' works:

 

request:  ?template=industries&title=Tire Manufacturing&debug=1

response: [selector] => template=industries, title=Tire Manufacturing, limit=50

 

 

$= Contains the exact word or phrase at the end of the field 
The key-value pairs using this operator are completely ignored. The [selector] part of the response only includes other key-value pairs. (as above)

~= Contains all the words 

Always throws an error because that field name is not searchable . The ‘~’ symbol is converted to ‘_’, is considered part of the field name and not treated as an operator. 

request: ?template=industries&title~=Tire&debug=1

response (error):   Field 'title_' is not allowed in queries

... I tried disabling the sanitizing of the field name before the error is displayed (line 189), and it then shows the error with the field name being  title~ 

request: ?template=industries&title~=Tire&debug=1

response (error):   Field 'title~' is not allowed in queries

 

I tried looking through the module, but I'm not seeing the cause of the problem. Any help would be greatly appreciated!

Thanks,

-Brent

Share this post


Link to post
Share on other sites

Hy guys,

i'm using Page Web Service module and everything is fine.

I'm querying for a template that has a repeater page field in it. 

I get json results with the array node for the repeater field. Every child of this array has these fields from the page:

- id

- name
- parent_id
- path
- template
- title
 
Is there a way to get other fields from that page?
 
Thanks....i hope my english is clear enough.
 
EDIT:
 
I've the same problem with the image field. I get the basename of the image but i don't get the path, so i don't know how top put it in my page. 

Share this post


Link to post
Share on other sites

If you use jQuery, you could try a little workaround to display your images. 

Not a very elegant way, but should work for small projects.

I started with a little php function to get my newsposts and generate the markup:

function getNewsfeed(){
  $curl = curl_init();
  curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'http://example.com/service-pages/?template=news&sort=-modified&limit=5'
  ));
  $result = curl_exec($curl);
  curl_close($curl);
  $data = '';
  $result = json_decode($result, true);
  if($result){
    foreach($result[matches] as $news){
      $data .='<div class="js-newsfeedentry s-newsfeedentry">';
      $data .='<h3>'.$news[title].'<small class="pull-right text-muted" style="padding-top:5px">Posted : '.date("d.m.Y - H:i",$news[created]).'</small></h3>';
      $data .= $news[text];
      $data .='<hr />';
      $data .='</div>';
    }
  }
  return $data;
}

as you can see, I wrap the entire newspost into a div with the class "js-newsfeed".

Now we iterate over all images inside this div and manipulate the img src, to match the correct url from the web-service.

Inside our document ready function we grab all news images and correct the src:

 /* fix urls for newsfeed img */
  var newsfeedimg = $('.js-newsfeed img');
  newsfeedimg.each(function(){
    var newimgsrc = 'http://example.com'+$(this).attr('src');
    $(this).attr('src',newimgsrc);
  });

et voila, working images. 

Remember that this isn´t a very good solution because you iterate over every image in your newspost via JavaScript and you shouldn´t do this on a project with many images. 

  • Like 1

Share this post


Link to post
Share on other sites

Hi everyone,

I try to test this module and it seems it does not work when I try the examples in the service-pages page that comes with this module. I have made sure that the template field is included in the config but it comes up with this error: Error: Template 'basic-page' is not allowed in queries

Not quiet sure what settings I did miss here. Here is the screenshot:

zBbexhl.png

Appreciate any help to solve this issue :) Cheers

Share this post


Link to post
Share on other sites

This module works great when I'm logged in as a superuser, when when logged out, I get the following error instead of viewing the JSON output:

Error: 	Exception: You do not have permission to execute this module - ProcessPageSearch (in /home/[...]/public_html/wire/core/Modules.php line 458)

This error message was shown because you are using the command line API. Error has been logged. 

I'm on 2.4.3.

Share this post


Link to post
Share on other sites

Hi jacmaes,

I have tracked down the issue. It is definitely a bug that should be reported to Ryan on Github.

There are newly added checks for module permissions around line#457 of Modules.php (https://github.com/ryancramerdesign/ProcessWire/commit/2c0762d1f346a3f01171b4f65fa97242f17fd916#diff-995c5c9ce48d4bff459f52363c6e190eR457)

The module that is blocking your access is actually ProcessPageSearch, which required page-edit permissions, which of course a guest user doesn't have.

If you temporarily remove the permission check, or change the ProcessPageSearch permissions to page-view, it works again (obviously this is not the appropriate solution :).

Once that hack is in place though, there is one other new bug:

{"errors":["Field 'it' is not allowed in queries"]}

This can be fixed easily by adding this line to ServicePages.module inside the loop starting at line#174

foreach($k as $name) {
   if($name=="it") continue; //add this line

Let us know if you want us to submit an issue of Github, or if you have taken care of it.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Adrian for looking into it and tracking down the bug. As efficient as always! You've saved me many times before. I will try your hack while Ryan gets a chance to fix this. And yes, I would appreciate it if you could open a bug report on GitHub as I'm certain that you will explain it a lot better than I possibly could.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks guys, I have fixed that issue by adding a new getModule($key, $options) method to the Modules class that lets you retrieve a module with $options. In this case an option called 'noPermissionCheck'. The ServicePages module has been updated to use the new method (when available).

Adrian, I wasn't seeing the "it" GET variable. That is a GET variable used internally by PW, but it gets removed before the request starts. So if you are seeing an "it" variable then you probably shouldn't be. At least I'm not seeing it here. I did go ahead and add that as something for ServicePages to ignore though, per your suggestion.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the fix Ryan - the noPermisionCheck should come in quite handy in other situations too :)

As for the "it" GET variable.

If I go to: 

http://pwtest.dev/service-pages/?name=about

with the following for debugging:

print_r($k);echo $_GET['it'];
foreach($k as $name) {
//if($name=="it") continue;

I get:

Array
(
[0] => it
)
<br />
<b>Notice</b>: Undefined index: it in <b>/Users/ajones/Sites/pwtest/site/modules/ServicePages/ServicePages.module</b> on line <b>175</b><br />
Array
(
[0] => name
)
<br />
<b>Notice</b>: Undefined index: it in <b>/Users/ajones/Sites/pwtest/site/modules/ServicePages/ServicePages.module</b> on line <b>175</b><br />

{"errors":["Field 'it' is not allowed in queries"]}

so $_GET['it'] doesn't exist, but it is part of the $k array.

Share this post


Link to post
Share on other sites

I need to generate a selector like this:

template=user, roles=faculty, roles=music

Where the result is users with the "faculty" role AND the "music" role.

Is that possible?

I tried:

?template=user&roles=faculty&roles=music

but only the last roles query seems to be included in the selector.

Share this post


Link to post
Share on other sites

We are currently using Service Pages to pull data and serve it on our front end. We can also remove null values by iterating to each fields and prepare new set of data with the formatted data we need. All is fine as of now, but it seems that a performance issue could occured if all available fields must return before formatting it. Is there any option to remove null fields via settings?


Share this post


Link to post
Share on other sites

Hi guys, hadn't tried this before, seems to be working great, just a couple of questions:

My query works as it should, but there's bunch of fields that include letters like Å, Ä and Ö and these letters are encoded, a title like "Riihimäki" is encoded to "Riihim\u00c5boki", how can I avoid this and just have the values as is?

Further on, the path value (a relative path) is added by default, any chance of overriding or adding to it, so I could get the absolute/full path for each page?

Share this post


Link to post
Share on other sites

I'm having a problem with the Web Service API. if i use a browser to hit the url http://localhost:8888/api/?id=1437 for example, it returns fine, with 1 match in the matches array.


 


However if i use CURL or hit the url from within PHP it returns but the matches array is empty.


 


Any help would be great.


 


Thanks  :)


 


post-2671-0-78056500-1410440885_thumb.pn

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...