+ Reply to Thread
Results 1 to 5 of 5

Thread: cannot save page properties via API

  1. #1
    Join Date
    Dec 2010
    Posts
    19

    Question cannot save page properties via API

    Hey there,

    I am trying to save my pageproperties via API-Call.

    Unfortunately it doesn't work

    When I try to save I get a 207 status and the properties are not saved



    Here is my Code in JavaScript:
    Code:
    /**
     * Sets the Page Properties
     * @param page_path path of the new page
     * @param properties map of properties
     */
    var setPageProperties = function(page_path, properties) {
      
      var api_properties = Deki.$('<properties></properties>');
      
      for(var key in properties) {
        var propertyname = key;
        var propertytext = properties[key];
        $('<property></property>').attr('name', propertyname)
          .append('<contents>'+propertytext+'</contents>').attr('type','text/plain')
          .appendTo(api_properties);
      }
      
      api_properties = '<properties>'+api_properties.html()+'</properties>';
      
      alert(api_properties);
      
      var pageapi = '/@api/deki/pages/=' + Deki.url.encode(Deki.url.encode(page_path));
      $.ajax({
        url: pageapi + '/properties',
        type: 'PUT',
        contentType: 'text/xml',
        processData: true,
        data: api_properties,
        complete: function(xhr) {
          if(xhr.status == 200) {
            //gets executed when properties get set successfully.
            loadPage(page_path);
          } else {
            //alert('Unable to create/modify Page Properties. Perhaps you do not have permission.');
            alert(xhr.status);
          }
        }
      });
    }
    Thanks in advance.

    Regards,
    Senad

  2. #2
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    Use PUT if you want to update a property and POST if you want to create one. Or pass in ?abort=never to tell the API to ignore these constraints.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  3. #3
    Join Date
    Dec 2010
    Posts
    19

    Default

    Quote Originally Posted by SteveB View Post
    Use PUT if you want to update a property and POST if you want to create one. Or pass in ?abort=never to tell the API to ignore these constraints.
    okay, thank you.

    ---

    I found an error in my implementation.
    the ".attr" function works differently than i expected it to. now I've modified everything to do what I want it to do.

    Code:
    /**
     * Sets the Page Properties
     * @param page_path path of the new page
     * @param properties map of properties
     */
    var setPageProperties = function(page_path, properties) {
      
      var api_properties = Deki.$('<properties></properties>');
      
      for(var key in properties) {
        var propertyname = key;
        var propertytext = properties[key];
        $('<property></property>').attr('name', propertyname)
          .append('<contents type="text/plain">'+propertytext+'</contents>')
          .appendTo(api_properties);
      }
      
      api_properties = '<properties>'+api_properties.html()+'</properties>';
      
      alert(api_properties+' | '+page_path);
      
      var pageapi = '/@api/deki/pages/=' + Deki.url.encode(Deki.url.encode(page_path));
      $.ajax({
        url: pageapi + '/properties?abort=never',
        type: 'PUT',
        contentType: 'text/xml',
        processData: true,
        data: api_properties,
        complete: function(xhr) {
          if(xhr.status == 200) {
            //gets executed when properties get set successfully.
            loadPage(page_path);
          } else {
            //alert('Unable to create/modify Page Properties. Perhaps you do not have permission.');
            alert(xhr.status+': '+xhr.responseText);
          }
        }
      });
    }
    That piece of code works once.
    No matter whether the property has previously been created or not. It then however does not execute the "complete"-statement.

    when I try to execute the function a second time I get an Error-Message:
    207: <properties count="0" href="http://mydomain.com/21891/properties"><property name="name"><status code="409">Given ETag '' for resource id '26138' does not match ETag for HEAD revision.</status></property><property name="region"><status code="409">Given ETag '' for resource id '26139' does not match ETag for HEAD revision.</status></property></properties>
    I don't understand what is going on.

    Thanks in advance.

    regards,
    Senad
    Last edited by senad; 01-03-2012 at 06:32 PM.

  4. #4
    Join Date
    Dec 2010
    Posts
    19

    Unhappy

    I still can't figure out why my code doesn't work...

    the concatenated String looks just like the curl sample to me.

    Code:
    <properties>
      <property name="x">
        <contents type="text/plain">123</contents>
      </property>
      <property name="y">
        <contents type="text/plain">321</contents>
      </property>
    </properties>
    Please help me.

    Regards,
    Senad

  5. #5
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    Did you look at the code in this js file? I used it for some prototyping and it worked well: http://scripts.mindtouch.com/res/deki/mindtouch.deki.js
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts