• Resolved gunther12

    (@gunther12)


    I have some Downloads in Download Monitor, which receive new versions, whenever I release a new version of my Software.

    If have the whole build process automated including the upload of the file to the ftp server.

    The only manual thing I need to do every time, is to go to the Download Moniitor Backend, open the Download, create a new version, navigate to the correct folder on the server, select the new version of the file and update the download. Then I need to do this for the next download and so on.

    This is a tedious and time consuming process.

    If Download Monitor would offer a Rest API Endpoint, I could automate this whole process.

    I already tried some things, but nothing worked.

    For example I tried to create a new Post in WordPress via REST and give it the post type “dlm_download”.

    DOWNLOAD_ID=62092

    curl -X POST “$SITE_URL/wp-json/wp/v2/posts” -d “title=$TITLE&content=$CONTENT&post_type=dlm_download&meta[download_id]=$DOWNLOAD_ID&meta[file_path]=$FILE_PATH” -H “Authorization: Bearer $TOKEN”

    $DOWNLOAD_ID is the ID of the current download, I was hoping that this would link the new file as new version to the download.

    $FILE_PATH is the path of the new file on the server.

    Unfortunately this creates a post, no download.

    Maybe you could point me in the right direction on how to add a new version to an existing download from a shell script.

    Thank you very much!

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Razvan Aldea

    (@raldea89)

    Hey @gunther12 ,

    The correct REST API endpoint for Downloads would be $SITE_URL/wp-json/wp/v2/dlm_download and the WordPress’ REST API should work for Downloads same as it does for Posts.

    Now, there is another custom post type, called dlm_download_version, that handles the versioning of downloads, so in order to create a new version or edit the current one you’ll need to modify this and not the dlm_download post type. $SITE_URL/wp-json/wp/v2/dlm_download_version is the endpoint for this one and, as dlm_download, the WordPress’ REST API should work just fine. If you want to create a dlm_download_version post type it will be necessary to set the post_parent as the dlm_download post ID to which it belongs.

    One thing though, for the dlm_download_version to be visible in the REST API you’ll need to tap into the dlm_cpt_dlm_download_version_args filter found here and add the show_in_rest parameter to true.

    Hope this helps!
    Warmly,
    Razvan

    Thread Starter gunther12

    (@gunther12)

    Thanks for coming back to me, this is very valuable.

    I’m already able to create a new Post version this way, it appears in the database but unfortunately, the post_parent is not set, it’s always 0 in the database and therefore the new download version doesn’t get linked.

    This is the JSON that I’m submitting to the endpoint
    $SITE_URL/wp-json/wp/v2/dlm_download_version
    where post_parent receives the ID of the parent download post itself.

    {
      "status": "publish",
      "post_parent": "63338",
      "title": "Download #63338 File Version",
      "file_path": "/var/www/......",
      "post_name": "download-63338-file-version"
    }

    Any ideas, why this doesn’t work as expected? Is there a documentation of the parameters for the endpoint somewhere?

    Plugin Author Razvan Aldea

    (@raldea89)

    Here you can see documentation for endpoint references. Seems that Posts don’t have the parent parameter, but Pages do. Could you please try with parent parameter and let me know if the newly added version is correctly added in the database?

    Warmly,
    Razvan

    Thread Starter gunther12

    (@gunther12)

    Yeah, I had tried this also. And I also tried to pass the ID as int and not as string like this, unfortunately nothing fills the post_parent in the database.

    {
      "status": "publish",
      "parent": 63338,
      "title": "Download #63338 File Version",
      "file_path": "/var/www/.....",
      "post_name": "download-63338-file-version"
    }
    Plugin Author Razvan Aldea

    (@raldea89)

    Think you’ll need to use the wp_update_post function and send the post parent ID and Version ID in order to do this. I’m not sure if updating post parent can be done with REST API directly.

    Warmly,
    Razvan

    Thread Starter gunther12

    (@gunther12)

    Hmm, isn’t this a bug in the implementation of the REST API of the Download Monitor Plugin then, which should be fixed?

    Thread Starter gunther12

    (@gunther12)

    Also, even if I fill in the post_parent manually in the database, the Download Monitor doesn’t show the version although the whole DB row in wp_posts table is correct like the row of the version that I created from the backend.

    There must be something else missing?

    Plugin Author Razvan Aldea

    (@raldea89)

    Hello @gunther12 ,

    Sadly Download Monitor doesn’t have a REST API that handles downloads, it relies on WordPress’ so can’t really fix that ??

    What we should and probably will do will be to create endpoints that will target strictly the plugin’s functionality and add the possibility to create Downloads/Versions. I went ahead and opened a ticket on github ( https://github.com/WPChill/download-monitor/issues/1215 ) where you can see its evolution, but I can’t really tell you when this will be launched.

    Regarding the versions not being shown after insert it is mainly because of transients. You’ll either need to clear this transient , dlm_file_version_ids_{download_id}, after you add the version , go to dashboard > Downloads > Settings > Advanced > Miscellaneous > Clear transients or not use transients at all returning false to this filter, dlm_download_use_version_transient .

    Hope this clears things out.

    Warmly,
    Razvan

    Thread Starter gunther12

    (@gunther12)

    Thanks, currently trying a work around, this is the current status:

    I can create the download version, just the parent is 0. The post appears in the database.

    Then I read the ID ($versionID) of the new download version and try to pass it to the POST endpoint in order to update the parent ID. To do so, I send this:

    {
      "post_parent": 63338
    }

    to this endpoint:

    $SITE_URL/wp-json/wp/v2/posts/$versionID"

    Unfortunately I get:

    {
      "code": "rest_post_invalid_id",
      "message": "Invalid post ID.",
      "data": {
        "status": 404
      }
    }

    …although the ID is set according to the database.

    Any ideas?

    Plugin Author Razvan Aldea

    (@raldea89)

    The endpoint should be $SITE_URL/wp-json/wp/v2/dlm_download_version/$versionID

    Thread Starter gunther12

    (@gunther12)

    Thanks, that helped. It comes though now without error, but unfortunately the parent is not being set. Transients are disabled now, when I enter the parent manually in the database the version appears in the backend.

    Now it’s just about getting that parent ID being set…

    • This reply was modified 1 year, 9 months ago by gunther12.
    Thread Starter gunther12

    (@gunther12)

    I’ve finally found a solution by developing an own plugin that provides a proper rest api and then creates a download version. It’s a pity that Download Monitor doesn’t offer this by itself.

    But I still have one problem: when adding the Download version programmatically it always appear sorted at the second position right below the last active version. Therefore it’s not active and I still need to enter the backend to drag it up one position for it to get activated.

    I cannot find out where that sort order is saved. Could you please enlighten me how to change that sort order programmatically? Thanks!

    Plugin Author Razvan Aldea

    (@raldea89)

    Hello @gunther12

    The order of the Versions is based ascending on menu order, so you can manipulate the order if you manipulate the menu order.

    Hope this helps!
    Warmly,
    Razvan

    Thread Starter gunther12

    (@gunther12)

    What do you mean with “Menu order”? How would I do that?

    Hello,

    In the wp_posts table you will see a column named “menu_order” you need to update that column to order the versions how you want.

    George.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Batch Create Downloads from Script’ is closed to new replies.