Jump to content

Pages Web Service (ServicePages)


ryan

Recommended Posts

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?

Link to comment
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 :-(

Link to comment
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
Link to comment
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)

Link to comment
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
Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
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. 
Link to comment
Share on other sites

  • 2 months later...

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
Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • 5 weeks later...

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.

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

  • 4 weeks later...

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.

Link to comment
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?


Link to comment
Share on other sites

  • 1 month later...

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?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

       
    • By tcnet
      Session Viewer is a module for ProcessWire to list session files and display session data. This module is helpful to display the session data of a specific session or to kick out a logged in user by simply delete his session file. After installation the module is available in the Setup menu.

      The following conditions must be met for the module to work properly:
      Session files
      Session data must be stored in session files, which is the default way in ProcessWire. Sessions stored in the database are not supported by this module. The path to the directory where the session files are stored must be declared in the ProcessWire configuration which is by default: site/assets/sessions.
      Serialize handler
      In order to transform session data easier back to a PHP array, the session data is stored serialized. PHP offers a way to declare a custom serialize handler. This module supports only the default serialize handlers: php, php_binary and php_serialize. WDDX was dropped in PHP 7.4.0 and is therefore not supported by this module as well as any other custom serialize handler. Which serialize handler is actually used you can find out in the module configuration which is available under Modules=>Configure=>SessionViewer.

      Session data
      The session data can be displayed in two different ways. PHP's default output for arrays print_r() or by default for this module nice_r() offered on github: https://github.com/uuf6429/nice_r. There is a setting in the module configuration if someone prefers print_r(). Apart from the better handling and overview of the folded session data the output of nice_r() looks indeed nicer.

      Links
      ProcessWire module directory
      github.com
    • By Robin S
      Repeater Easy Sort
      Adds a compact "easy-sort" mode to Repeater and Repeater Matrix, making those fields easier to sort when there are a large number of items.
      The module also enhances Repeater Matrix by allowing a colour to be set for each matrix type. This colour is used in the item headers and in the "add new" links, to help visually distinguish different matrix types in the inputfield.
      Screencasts
      A Repeater field

      A Repeater Matrix field with custom header colours

      Easy-sort mode
      Each Repeater/Matrix item gets an double-arrow icon in the item header. Click this icon to enter easy-sort mode.
      While in easy-sort mode:
      The items will reduce in width so that more items can be shown on the screen at once. The minimum width is configurable in the field settings. Any items that were in an open state are collapsed, but when you exit easy-sort mode the previously open items will be reopened. You can drag an item left/right/up/down to sort it within the items. The item that you clicked the icon for is shown with a black background. This makes it easier to find the item you want to move in easy-sort mode. You can click an item header to open the item. An "Exit easy-sort mode" button appears at the bottom of the inputfield. Configuration
      In the field settings for Repeater and Repeater Matrix fields you can define a minimum width in pixels for items in easy-sort mode. While in easy-sort mode the items will be sized to neatly fill the available width on any screen size but will never be narrower than the width you set here.
      In the field settings for Repeater Matrix you can define a custom header colour for each matrix type using an HTML "color" type input. The default colour for this type of input is black, so when black is selected in the input it means that no custom colour will be applied to the header.
      Exclusions
      The easy-sort mode is only possible on Repeater/Matrix fields that do not use the "item depth" option.
       
      https://github.com/Toutouwai/RepeaterEasySort
      https://processwire.com/modules/repeater-easy-sort/
×
×
  • Create New...