Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-65978

New Web Services for managing blog entries

XMLWordPrintable

    • MOODLE_37_STABLE
    • MOODLE_404_STABLE
    • MDL-65978-master
    • Hide
      1. As an admin, enable “Web services for mobile devices” on Site administration ► Advanced features
      2. Enable the following option under Site administration > Appearance > Blog: “Enable blog associations” and “Enable comments”
      3. Create a Token in the mobile app service for any user on the site (not an admin account)
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      4. Open the console and execute this new curl request, replacing WS_TOKEN with the token you just created and the SITE_URL with yours.

        curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=tool_mobile_get_config&wstoken=WS_TOKEN' | python -m "json.tool"

      5. Confirm that:
        • You see the following fields set to 1: “useblogassociations” and “blogusecomments”, you also see the field “bloglevel” (the value is not relevant)
      6. Now, execute the following course request

        curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_get_access_information&wstoken=WS_TOKEN' | python -m "json.tool"

      7. Confirm that:
        • You see the following field with the indicated values
          • "cancreate": true,
          • "canmanageentries": false,
          • "canmanageexternal": true,
          • "cansearch": true,
          • "canview": true,
          • "canviewdrafts": false,
            Now we are going to create a blog entry attaching a .txt file by doing the following:
      8. Now, create a local file called “test.txt and place it in your main documents folder
      9. Execute the following request to upload a file to a temporary folder in the server , replacing the URL and token values, YOURDOCUMENTSPATH with the path to the file in your computer

        curl -i -F name=testomelette.txt -F filedata=@YOURDOCUMENTSPATH/test.txt "SITE_URL/webservice/upload.php?token=WS_TOKEN&filearea=draft"

      10. Confirm that:
        • the response of the previous curl request is a JSON structure that contains the file name “test.txt” and also a itemid value you need to copy because it will be used later
      11. Now, execute the following curl request to create the entry replacing as usual the URL and wstoken values and DRAFTITEMID with the value of the “itemid” you copied before

        curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_add_entry&wstoken=WS_TOKEN&subject=Test&summary=TestSummary&summaryformat=1&options[0][name]=tags&options[0][value]=tag1,tag2&options[1][name]=attachmentsid&options[1][value]=DRAFTITEMID' --compressed | python -m "json.tool"

      12. Confirm that:
        • The response includes a value “entryid” with an integer value
        • If you go to the website blogs section: SITE_URL/blog/ you see the blog entry with subject “Test”, and two tags, (tag1 and tag2) and an attachment “test.txt”
      13. Now repeat the same process of uploading first a file to get an “itemid” and then call the previous Web Service to create a blog post (remember to indicate the new itemid) so you will have two similar blog entries
        Now let’s delete one of them
      14. In order to do so you just need to do the following curl request replacing ENTRYID with any of the blog entries ids that you just created

        curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_delete_entry&wstoken=WS_TOKEN&entryid=ENTRYID' | python -m "json.tool"

      15. Confirm that:
        • The blog post does not appear anymore in the site blogs page at SITE_URL/blog/
          Now we are going to update the blog entry, adding additional attachments
      16. Execute first the following CURL request replacing ENTRYID with the remaining blog entry

        curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_prepare_entry_for_edition&wstoken=WS_TOKEN&entryid=ENTRYID' | python -m "json.tool"

      17. From the result previous request annotate the value of the “attachmentsid” field
      18. Create a newtest.txt file and upload it using the following command, this time you have to replace also the DRAFTITEMID value with the value of “attachmentsid”

        curl -i -F name=testomelette.txt -F filedata=@YOURDOCUMENTSPATH/test.txt "SITE_URL/webservice/upload.php?token=WS_TOKEN&filearea=draft&itemid=DRAFTITEMID"

      19. Now, execute the following curl request to update the entry replacing as usual the URL and wstoken values and DRAFTITEMID with the value of the “attachmentsid” you copied before, and ENTRYID with the remaining blog entry

        curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_update_entry&wstoken=WS_TOKEN&entryid=ENTRYID&subject=TestUpdated&summary=TestSummaryUpdated&summaryformat=1&options[0][name]=tags&options[0][value]=tag1,tag2&options[1][name]=attachmentsid&options[1][value]=DRAFTITEMID' --compressed | python -m "json.tool"

      20. Confirm that:
        • In the blogs page you see the blog post updated with the subject “TestUpdated” and among the attachments there is a new file “newtest” SITE_URL/blog/
      Show
      As an admin, enable “Web services for mobile devices” on Site administration ► Advanced features Enable the following option under Site administration > Appearance > Blog: “Enable blog associations” and “Enable comments” Create a Token in the mobile app service for any user on the site (not an admin account) Click on Site administration ► Plugins ► Web services ► Manage tokens Open the console and execute this new curl request, replacing WS_TOKEN with the token you just created and the SITE_URL with yours. curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=tool_mobile_get_config&wstoken=WS_TOKEN' | python -m "json.tool" Confirm that: You see the following fields set to 1: “useblogassociations” and “blogusecomments”, you also see the field “bloglevel” (the value is not relevant) Now, execute the following course request curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_get_access_information&wstoken=WS_TOKEN' | python -m "json.tool" Confirm that: You see the following field with the indicated values "cancreate": true, "canmanageentries": false, "canmanageexternal": true, "cansearch": true, "canview": true, "canviewdrafts": false, Now we are going to create a blog entry attaching a .txt file by doing the following: Now, create a local file called “test.txt and place it in your main documents folder Execute the following request to upload a file to a temporary folder in the server , replacing the URL and token values, YOURDOCUMENTSPATH with the path to the file in your computer curl -i -F name=testomelette.txt -F filedata=@YOURDOCUMENTSPATH/test.txt "SITE_URL/webservice/upload.php?token=WS_TOKEN&filearea=draft" Confirm that: the response of the previous curl request is a JSON structure that contains the file name “test.txt” and also a itemid value you need to copy because it will be used later Now, execute the following curl request to create the entry replacing as usual the URL and wstoken values and DRAFTITEMID with the value of the “itemid” you copied before curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_add_entry&wstoken=WS_TOKEN&subject=Test&summary=TestSummary&summaryformat=1&options [0] [name] =tags&options [0] [value] =tag1,tag2&options [1] [name] =attachmentsid&options [1] [value] =DRAFTITEMID' --compressed | python -m "json.tool" Confirm that: The response includes a value “entryid” with an integer value If you go to the website blogs section: SITE_URL/blog/ you see the blog entry with subject “Test”, and two tags, (tag1 and tag2) and an attachment “test.txt” Now repeat the same process of uploading first a file to get an “itemid” and then call the previous Web Service to create a blog post (remember to indicate the new itemid) so you will have two similar blog entries Now let’s delete one of them In order to do so you just need to do the following curl request replacing ENTRYID with any of the blog entries ids that you just created curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_delete_entry&wstoken=WS_TOKEN&entryid=ENTRYID' | python -m "json.tool" Confirm that: The blog post does not appear anymore in the site blogs page at SITE_URL/blog/ Now we are going to update the blog entry, adding additional attachments Execute first the following CURL request replacing ENTRYID with the remaining blog entry curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_prepare_entry_for_edition&wstoken=WS_TOKEN&entryid=ENTRYID' | python -m "json.tool" From the result previous request annotate the value of the “attachmentsid” field Create a newtest.txt file and upload it using the following command, this time you have to replace also the DRAFTITEMID value with the value of “attachmentsid” curl -i -F name=testomelette.txt -F filedata=@YOURDOCUMENTSPATH/test.txt "SITE_URL/webservice/upload.php?token=WS_TOKEN&filearea=draft&itemid=DRAFTITEMID" Now, execute the following curl request to update the entry replacing as usual the URL and wstoken values and DRAFTITEMID with the value of the “attachmentsid” you copied before, and ENTRYID with the remaining blog entry curl 'SITE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_update_entry&wstoken=WS_TOKEN&entryid=ENTRYID&subject=TestUpdated&summary=TestSummaryUpdated&summaryformat=1&options [0] [name] =tags&options [0] [value] =tag1,tag2&options [1] [name] =attachmentsid&options [1] [value] =DRAFTITEMID' --compressed | python -m "json.tool" Confirm that: In the blogs page you see the blog post updated with the subject “TestUpdated” and among the attachments there is a new file “newtest” SITE_URL/blog/

      • New WebService core_blog_get_access_information
      • New WebService core_blog_create_entry
      • New WebService core_blog_update_entry
      • New WebService core_blog_delete_entry
      • New WebService core_blog_prepare_draft_area_for_entry
      • Update existing WS to retrieve posts to indicate whether a user canedit a post

            jleyva Juan Leyva
            jleyva Juan Leyva
            Rodrigo Mady Rodrigo Mady
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days, 7 hours, 26 minutes
                2d 7h 26m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.