• I see that the REST API is supported, but I don’t see any documentation on how to call it with attachments via javascript/json. Is there a tutorial somewhere? Currently, I’m creating comments anonymously with the following:

    fetch(${wordpressUrl}/wp-json/wp/v2/comments, {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json'
    },
    body: JSON.stringify({
    post: postId,
    content: content,
    author_name: authorName,
    author_email: authorEmail,
    author_url: authorUrl
    })
    })

    .then (...)

    Thanks again for all you’re doing here, I know I’ve asked a bunch of questions as I just discovered your plugin!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Denis Yanchevskiy

    (@denisco)

    Hello @turbodb,

    Unfortunately, there is no documentation ?? .

    About REST API. It’s a difficult question. REST API support was added several years ago and since then there have been no requests on this matter. Therefore, I don’t have a ready-made recipe now. I plan to deal with REST API in the next version.

    Regarding the current version. Try to pass formData to body.

    Something like this:


    const formData = new FormData();

    formData.append('post', postId);
    formData.append('content', content);
    formData.append('author_name', authorName);
    formData.append('author_email', authorEmail);
    formData.append('author_url', authorUrl);

    formData.append('attachment', attachmentFile); // https://developer.mozilla.org/en-US/docs/Web/API/File

    fetch(${wordpressUrl}/wp-json/wp/v2/comments, {
    method: 'POST',
    body: formData
    })

    .then (...)
    Thread Starter turbodb

    (@turbodb)

    Thanks! If a better REST API support is coming in the next version, I’m happy to wait for that.

    Cheers,

    Plugin Author Denis Yanchevskiy

    (@denisco)

    Just a note. This plugin is my pet project. So I’m developing it in my free time and can’t give a time frame for when the next version might come out. The third version is intended as a maintenance release to rethink the code and tidy things up, so I’ll be glad when it comes out too. But if you need REST API support in the near future, it will probably be more reliable to use what is available in the existing version.

    Thread Starter turbodb

    (@turbodb)

    I appreciate the work you’ve done on it, and totally understand the project aspect of it.

    Also, from my end, the ability to add a description would be higher priority/nicer than the REST API. (Not that I should get any say in your ordering/project ??)

    Thanks again for a great plugin!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.