{"id":18300615,"date":"2025-02-12T06:47:13","date_gmt":"2025-02-12T06:47:13","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/how-to-add-attachment-via-rest-api\/"},"modified":"2025-02-12T06:47:13","modified_gmt":"2025-02-12T06:47:13","slug":"how-to-add-attachment-via-rest-api","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/how-to-add-attachment-via-rest-api\/","title":{"rendered":"How to add attachment via REST API?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I see that the REST API is supported, but I don&#8217;t see any documentation on how to call it with attachments via javascript\/json. Is there a tutorial somewhere? Currently, I&#8217;m creating comments anonymously with the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fetch(<code>${wordpressUrl}\/wp-json\/wp\/v2\/comments<\/code>, {<br \/>       method: 'POST',<br \/>       headers: {<br \/>           'Content-Type': 'application\/json'<br \/>       },<br \/>       body: JSON.stringify({<br \/>           post: postId,<br \/>           content: content,<br \/>           author_name: authorName,<br \/>           author_email: authorEmail,<br \/>           author_url: authorUrl<br \/>       })<br \/>})<br \/><br \/>.then (...)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks again for all you&#8217;re doing here, I know I&#8217;ve asked a bunch of questions as I just discovered your plugin!<\/p>\n","protected":false},"template":"","class_list":["post-18300615","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18300615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18300615\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18300615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}