{
  "name": "DeCAred · Preparar operación para revisión",
  "nodes": [
    {
      "parameters": {
        "content": "# Preparar y revisar · API 1.3\n\nConfigura el ID, la acción y sus campos en «Propuesta». Lee primero el documento y toma su revisión vigente. `issue` consulta el borrador.\n\nEste flujo solo prepara: revisa `summary`, `expires_at`, ID y acción antes de abrir la plantilla de confirmación. No conectes ambos flujos automáticamente.\n\n**Clave de API.** Crea una credencial *Header Auth* llamada «Clave de API de DeCAred»:\n- Name: `Authorization`\n- Value: `Bearer dcr_…` (tu clave de DeCAred → Más → Integraciones)\n\nPermiso explícito de la acción; `documents:read` o `drafts:read` para consultar la revisión. No lo heredan read/write. Guarda el token solo en ejecuciones restringidas y con retención corta.",
        "height": 500,
        "width": 430,
        "color": 4
      },
      "id": "9469fa56-e95d-5722-9209-17fa2dd629a0",
      "name": "Nota",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -450,
        -230
      ]
    },
    {
      "parameters": {},
      "id": "23c2ed8c-2ba2-52c3-9dcd-7bccfcdb8153",
      "name": "Manual",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const documentId = 0; // Sustituir por el ID real.\nconst action = 'message';\nconst fields = {body: 'Texto que revisará la persona responsable', visibility: 'internal'};\nif (!Number.isInteger(documentId) || documentId < 1) throw new Error('Configura documentId');\nreturn [{json: {document_id: documentId, action, fields}}];"
      },
      "id": "cb7de1e2-d135-5805-ab79-17ef64c6979a",
      "name": "Propuesta",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ \"https://decared.com/api/v1\" + ($json.action === 'issue' ? '/drafts/' : '/documents/') + $json.document_id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "0da127f3-d159-594b-8321-5c222f4f19c8",
      "name": "Revisión vigente",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Clave de API de DeCAred"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ \"https://decared.com/api/v1\" + '/documents/' + $('Propuesta').first().json.document_id + '/actions' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({...$('Propuesta').first().json.fields, action: $('Propuesta').first().json.action, revision: $json.data.revision}) }}"
      },
      "id": "48eea349-97ed-5a2a-b11e-1b75fd43726d",
      "name": "Preparar operación",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Clave de API de DeCAred"
        }
      }
    }
  ],
  "connections": {
    "Manual": {
      "main": [
        [
          {
            "node": "Propuesta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Propuesta": {
      "main": [
        [
          {
            "node": "Revisión vigente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Revisión vigente": {
      "main": [
        [
          {
            "node": "Preparar operación",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "pinData": {}
}
