# Enviar Comentarios Post (1) - [sendComment]

## 🧾 **Descripción**

*Registra un nuevo comentario dentro de una publicación del módulo de “Publicaciones” en ERP/Capacitación.*

*El servicio envía la información del comentario a un endpoint del ERP mediante autenticación por cookie.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fsend-comment"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /send-comment`**</span></div></div>> La ruta real depende del archivo de rutas Laravel (<span style="color: rgb(224, 62, 45);">**`api.php`**</span>).

---

# 🔐 **Seguridad**

- Requiere **cookie de sesión ERP** enviada por el cliente.
- La cookie se usa directamente en la cabecera:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-cookie%3A-session_id%3D."><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`<span class="hljs-section">Cookie: session_id=...</span>`**</span></div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22content%22%3A-%22string" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parent"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### **Descripción de campos**

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-requerido"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1192" data-start="864"><thead data-end="912" data-start="864"><tr data-end="912" data-start="864"><th data-col-size="sm" data-end="876" data-start="864">Campo</th><th data-col-size="sm" data-end="885" data-start="876">Tipo</th><th data-col-size="sm" data-end="897" data-start="885">Requerido</th><th data-col-size="md" data-end="912" data-start="897">Descripción</th></tr></thead><tbody data-end="1192" data-start="962"><tr data-end="1020" data-start="962"><td data-col-size="sm" data-end="974" data-start="962">content</td><td data-col-size="sm" data-end="983" data-start="974">string</td><td data-col-size="sm" data-end="995" data-start="983">Sí</td><td data-col-size="md" data-end="1020" data-start="995">Texto del comentario.</td></tr><tr data-end="1122" data-start="1021"><td data-col-size="sm" data-end="1033" data-start="1021">parent</td><td data-col-size="sm" data-end="1042" data-start="1033">string</td><td data-col-size="sm" data-end="1054" data-start="1042">Sí</td><td data-col-size="md" data-end="1122" data-start="1054">ID del documento `Publicaciones` al que pertenece el comentario.</td></tr><tr data-end="1192" data-start="1123"><td data-col-size="sm" data-end="1135" data-start="1123">cookie</td><td data-col-size="sm" data-end="1144" data-start="1135">string</td><td data-col-size="sm" data-end="1156" data-start="1144">Sí</td><td data-col-size="md" data-end="1192" data-start="1156">Cookie de sesión válida del ERP.</td></tr></tbody></table>

</div></div>**Otros campos se envían de forma fija al backend:**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22parenttype%22%3A-%22pub" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"parenttype"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Publicaciones"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parentfield"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"comments"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 📤 **Responses**

## ✔️ **200 – Comentario creado correctamente**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Creado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ... <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ **400 – Error en datos del cliente**

El servicio no valida explícitamente los campos, pero si backend rechaza:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22false%22%2C-" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"false"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error de servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Detalle del error del ERP"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

## ❌ **500 – Error al procesar la solicitud**

Cuando la API del ERP responde con error:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--10"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22false%22%2C--1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"false"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error de servidor"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"<mensaje de error>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧩 **Lógica interna del servicio**

1. Crea un cliente <span style="color: rgb(224, 62, 45);">**`ApiRest`** </span>con manejo de cookies.
2. Construye los datos del comentario:
    
    
    - `content`
    - `parent` (publicación)
    - `parenttype = Publicaciones`
    - `parentfield = comments`
3. Envía un <span style="color: rgb(224, 62, 45);">**`POST`** </span>al endpoint del ERP:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span style="color: rgb(224, 62, 45);"><strong>{APICAPACITACION}/resource/postComend2</strong></span>`</div></div>
4. Maneja error HTTP (BadResponseException).
5. Si la respuesta contiene `data`, devuelve éxito.
6. Si no, marca error de creación.

---

# 🗃 **Schemas**

### Request Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--13"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22content%22%3A-%22string-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"content"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"parent"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cookie"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

### Response Schema

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk--14"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div><table border="1" id="bkmrk-%7B-%22valor%22%3A-%22boolean%7C" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean|string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"object"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

---

# 🧪 **Ejemplo de uso (curl)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-curl--x-post-https%3A%2F"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`curl -X POST https://midominio.com/api/send-comment \-H <span class="hljs-string">"Content-Type: application/json"</span> \-d <span class="hljs-string">'{  "content":"Excelente publicación",  "parent":"PUB-00045",  "cookie":"sid=cd2312fa..."}'</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>