Go REST
L

How to create a comment using comments API

Lakshmi Sravanthi Namburi over 4 years ago 5730 views 6 replies

How to create a comment using comments API?

6 replies
Z
zeevy over 4 years ago

please try this

curl -i -H "Accept:application/json" -H "Content-Type:application/json" -H "Authorization: Bearer YOUR-ACCESS-TOKEN" -XPOST "https://gorest.co.in/public/v2/comments" -d '{"post_id":123, "name":"Sanya Varma", "email":"sanya_varma@schiller-konopelski.co", "body":"this is how we can create a comment"}'

Similar code should work with any other language also, just make sure the post_id used is available in GET /public/v2/posts

M
Misterios Person almost 3 years ago

{post_id:123, name:Sanya Varma, email:sanya_varma@schiller-konopelski.co, body:this is how we can create a comment}

If we this request body it is showing following error message.

{field: post, message: must exist}

M
Misterios Person almost 3 years ago

Irrespective of what we use, whether it is post_id or post, it is not working

L
Lallawmkima Tlau over 1 year ago

Is there solution already for this? Getting 404 even when I passed post ID from the previous posts call response.

Z
zeevy over 1 year ago

please use any of the post id from https://gorest.co.in/public/v2/posts

please find the working curl example

curl -i -H Accept:application/json -H Content-Type:application/json -H Authorization: Bearer USE YOUR TOKEN HERE -XPOST https://gorest.co.in/public/v2/comments -d '{post_id:193792, name:Sanya Varma, email:sanya_varma@schiller-konopelski.co, body:this is how we can create a comment}'

HTTP/2 201
date: Thu, 20 Feb 2025 04:21:18 GMT
content-type: application/json; charset=utf-8
content-length: 141
location: https://gorest.co.in/public/v2/comments/139884
cache-control: max-age=0, private, must-revalidate
etag: W/28006b6d4bd8e301ceb244ef215d0cad
feature-policy: camera 'none'; gyroscope 'none'; microphone 'none'; usb 'none'; fullscreen 'self'
referrer-policy: strict-origin-when-cross-origin
vary: Origin
x-content-type-options: nosniff
x-download-options: noopen
x-frame-options: SAMEORIGIN
x-permitted-cross-domain-policies: none
x-ratelimit-limit: 200
x-ratelimit-remaining: 199
x-ratelimit-reset: 0
x-request-id: 2164facc-074d-4864-b40e-39ce8420233b
x-runtime: 0.081327
x-xss-protection: 0
cf-cache-status: DYNAMIC
report-to: {endpoints:[{url:https:\/\/a.nel.cloudflare.com\/report\/v4?s=9pe7898k%2B%2BRNc5VUX0veA7mw6sAeECbc1Oe1Z%2FIng9UzvmsqiHuUbT%2FNqEg5gEGGwT6ofMe7hgUMhSIUJLceKEdHwGCdI4u1Tdae6RFMPYpFyzTBpBztjVT2M6Pp40k%3D}],group:cf-nel,max_age:604800}
nel: {success_fraction:0,report_to:cf-nel,max_age:604800}
server: cloudflare
cf-ray: 914bb5829fbe47b6-BOM
alt-svc: h3=:443; ma=86400
server-timing: cfL4;desc=?proto=TCP&rtt=20759&min_rtt=19875&rtt_var=4748&sent=8&recv=11&lost=0&retrans=0&sent_bytes=2913&recv_bytes=799&delivery_rate=194960&cwnd=252&unsent_bytes=0&cid=1de37998eccb50a7&ts=190&x=0

{id:139884,post_id:193792,name:Sanya Varma,email:sanya_varma@schiller-konopelski.co,body:this is how we can create a comment}%

Z
zeevy over 1 year ago

the post id given in the example may get deleted, please use the id from get posts api

Your reply

Markdown supported