Jump to content
ryan

Pages Web Service (ServicePages)

Recommended Posts

This is absolutely perfect for a property listing site I'm currently working on. Now estate agents can use the API to get their data. Amazing work as always Ryan! :)

Share this post


Link to post
Share on other sites

Little tip - because this modules page is just a page (everything's a page), it can have children.

One thing that I don't think you can get back through it is a count of all the pages that would match a selector, to use for pagination, for example. But you can easily make a child page that returns $pages(selector)->count() and maybe other meta information (perhaps as a json object).

Share this post


Link to post
Share on other sites

I've been trying to wrap my head around multilanguage, which was discussed in this thread previously. But I have no luck importing (the English one in this example) into my template(s). NOTE: The domain is just an example, the real domain is different.

I have two languages:

Norwegian: http://domain.no/service-pages/?template=subject

English: http://domain.no/en/service-pages/?template=subject

When I paste these links into the browser, I get the JSON in the correct language as I hope for from each of them. But when I try to import it somewhere (even on domain.no itself), I can only get the Norwegian one to work.

The code (with /en/) that wont work is this, simply remove /en/ and it works.

<?php 

    // Get JSON string
    $json_output = file_get_contents("http://domain.no/en/service-pages/?template=subject");
    
    // Convert JSON string to Array
    $someArray = json_decode($json_output, true);

    echo "<pre>";
    print_r($someArray);
    echo "</pre>";

?>

Any suggestions?

Share this post


Link to post
Share on other sites
On 7/18/2014 at 2:10 AM, Christian said:

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?

 

@Christian Did you ever find a solution for this? Would like to get rid of the empty values too. 

Share this post


Link to post
Share on other sites

Second question. The ServicePages API seems to return images (or any file) like this.

reel_poster: {
    basename: "breakdown-2015-poster.jpg",
    description: "",
    tags: "",
    formatted: false,
    modified: 1468541707,
    created: 1468541707
},

How do I get the actual path / URL of the file referenced? I need to get the path in a JS app, so I can't use the PHP API. 

Share this post


Link to post
Share on other sites
On 8/7/2015 at 0:21 PM, sforsman said:

@doolak:

It is important to realize that the JSON-data returned by the module will be decoded into a "dummy" PHP object (an instance of stdClass), based purely on the raw information that can be seen in the JSON-representation. Such an object has nothing to do with ProcessWire's objects/classes. So the consuming service has absolutely no idea of any other properties other than those that are given to it by the module. You can basically compare it to an array. Hence you cannot use any properties related to a ProcessWire class, such as FieldtypeImage.

The simplest option is to build the URL manually, e.g.


<img src="http://xyz.de/site/assets/<?php echo ($post->id . '/' . $post->mf_termin_image->basename); ?>">

Although this is in PHP, and doesn't completely answer my question, I think this is the only possible solution. Posted a question and my own solution on StackOverflow here.

  • Like 1

Share this post


Link to post
Share on other sites

Is there a way to get pages in another language yet?

My situation:
file_get_contents('http://www.mydomain.com/en/service-pages/?template=%22subpage%22&id=51970');
works on the serving sites instruction page & in FF browser direct call.
but does not work within the template or Chrome / Safari (Osx) directly.
without /en/ ... works flawless (same situation as Laban).

So I've tried various httpheader / useragent options (also via curl) , the content application/json, debug=1, ... solutions suggested in this thread.
Still "failed to open stream: HTTP request failed! HTTP/1.1 404 Page Not Found" from PW.

update:
Once again, the "active" button at the settings > language page of the "pages web services" page. omg.
Does Superuser login ignore this setting?


thanks!

Share this post


Link to post
Share on other sites

Looks like an issue with the File Compiler - it is trying to compile the "include" from this: $this->input->get->include

Simple fix is to add namespace ProcessWire; to the top of that file and the module installs just fine. I also did a quick test and queries also seem to be working properly, but be sure to test thoroughly.

Share this post


Link to post
Share on other sites

Many thanks , Adrian! 

After adding that namespace and changed all wire("config") to $config , wire("fields") to $fields and wire("templates") to $template in instructions.php , all is OK!

Thanks, again!

  • Like 2

Share this post


Link to post
Share on other sites
Just now, awebcreature said:

Many thanks , Adrian! 

After adding that namespace and changed all wire("config") to $config , wire("fields") to $fields and wire("templates") to $template in instructions.php , all is OK!

Thanks, again!

Ah yes - I didn't mention all the errors in the instructions.php file because the functionality of the module seemed to be fine :) 

  • Like 1

Share this post


Link to post
Share on other sites

cheers,

Someone maybe found a way how to select a page (current year) withing two datetime fields (event_start/event_ende) while event_ende datetime-field might not be set (='')?
I'd like to limit traffic by using only one call.

&!event_ende<=timestamp

seems not supported by PWS?

any way to "pipe / OR" selectors in PWS (event_ende>=timestamp OR event_ende='')?

thanks!

Share this post


Link to post
Share on other sites

Hi,

I play with something similar to service-pages and need to transport a selector and optional a field filter (for example to only get id, name, title instead of all the page fields). I set the selector as query string,

/api/path?template=basic-page,field1=val1,limit=10

but how to set the field filter or split selector string from the field filter in parameters?

/api/path?fields=id,name,title

Can't combine the query string with selector and fields filter because of multiple "=" signs... How should it be done a clean / easy way?

 

EDIT:

Optional I use predefined selectors (more secure way too) only selected by path / urlSegments instead of selector in query, but would be nice to know how to handle it most flexible...

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
      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:
       
    • By ukyo
      FieldtypeFontIconPicker
      Supported Icon Libraries
      FontAwesome 4.7.0 Uikit 3.0.34 IonicIcons 2.0.1 Cahangelog
      NOTE: Module store data without prefix, you need to add "prefix" when you want to show your icon on front-end, because some of front-end frameworks using font-awesome with different "prefix".
      Module will search site/modules/**/configs/IconPicker.*.php and site/templates/IconPicker.*.php paths for FieldtypeFontIconPicker config files.
      All config files need to return a PHP ARRAY like examples.
      Example config file : create your own icon set.
      File location is site/configs/IconPicker.example.php
      <?php namespace ProcessWire; /** * IconPicker : Custom Icons */ return [ "name" => "my-custom-icons", "title" => "My Custom Icon Set", "version" => "1.0.0", "styles" => array( wire("config")->urls->templates . "dist/css/my-custom-icons.css" ), "scripts" => array( wire("config")->urls->templates . "dist/js/my-custom-icons.js" ), "categorized" => true, "attributes" => array(), "icons" => array( "brand-icons" => array( "title" => "Brand Icons", "icons" => array( "google", "facebook", "twitter", "instagram" ) ), "flag-icons" => array( "title" => "Flag Icons", "icons" => array( "tr", "gb", "us", "it", "de", "nl", "fr" ) ) ) ]; Example config file : use existing and extend it.
      File location is site/configs/IconPicker.altivebir.php
      <?php namespace ProcessWire; /** * IconPicker : Existing & Extend */ $resource = include wire("config")->paths->siteModules . "FieldtypeFontIconPicker/configs/IconPicker.uikit.php"; $url = wire("config")->urls->templates . "dist"; $resource["scripts"] = array_merge($resource["scripts"], ["{$url}/js/Altivebir.Icon.min.js"]); $resource["icons"]["flag-icons"] = [ "title" => "Flag Icons", "icons" => array("tr", "en", "fr", "us", "it", "de") ]; $resource["icons"]["brand-icons"]["icons"] = array_merge($resource["icons"]["brand-icons"]["icons"], array( "altivebir" )); return $resource; After you add your custom config file, you will see your config file on library select box. Library Title (Location Folder Name).

      If your library categorized and if you have categorized icons set like uikit and fontawesome libraries, you will have category limitation options per icon field or leave it empty for allow all categories (default).

      Example : output
      if ($icon = $page->get("iconField")) { echo "<i class='prefix-{$icon}' />"; } MarkupFontIconPicker Usage
      // MarkupFontIconPicker::render(YourIconField=string, Options=array) echo MarkupFontIconPicker::render($page->YourIconField, [ 'prefix' => 'uk-icon-', // Icon class prefix, if you have different prefix, default is : "fa fa-" 'tag' => 'span', // Icon tag default is : "i" 'class' => 'fa-lg', // If you have extra cutom classes, for example : icons sizes, Array or Sting value 'style' => 'your custom styles if you have' // Array or String Value ]); Theme support

      Search support

      Category support

       
×
×
  • Create New...