Skip to content

TRANSCEND IAM + Pay + Profiles con Dynamics 365

Con Power Automate y la API de Business Central, puedes conectar los datos de TRANSCEND Platform (IAM, Pay, Profiles) con tus procesos en Dynamics 365.

Power Automate Flow

Trigger: "Cuando se crea una factura en TRANSCEND Pay" (webhook) Acción: Crear asiento de ingreso en Dynamics 365 Business Central

json
{
  "trigger": {
    "webhook": {
      "inputs": {
        "schema": {
          "properties": {
            "event": {"type": "string"},
            "data": {
              "properties": {
                "invoiceId": {"type": "string"},
                "companyId": {"type": "string"},
                "total": {"type": "number"},
                "date": {"type": "string"},
                "description": {"type": "string"}
              }
            }
          }
        }
      }
    }
  },
  "actions": [
    {
      "type": "OpenApiConnection",
      "inputs": {
        "host": {
          "connectionName": "shared_dynamic365businesscentral"
        },
        "parameters": {
          "companyId": "@{triggerBody().data.companyId}",
          "journalLine": {
            "accountType": "G/L Account",
            "accountNumber": "705000",
            "amount": "@{triggerBody().data.total}",
            "description": "@{triggerBody().data.description}",
            "documentDate": "@{triggerBody().data.date}"
          }
        }
      }
    }
  ]
}

API Directa a Business Central

bash
# Obtener perfil de empresa desde TRANSCEND Profiles
curl -X GET "https://back.transcend.cargoffer.com/profiles/api/companies/{company_id}" \
  -H "Authorization: Bearer *** usuario autenticado
curl -X GET "https://back.transcend.cargoffer.com/iam/api/auth/me" \
  -H "Authorization: Bearer *** factura en Business Central desde TRANSCEND Pay
curl -X POST "https://api.businesscentral.dynamics.com/v2.0/.../journalLines" \
  -H "Authorization: Bearer *** \
  -H "Content-Type: application/json" \
  -d '{
    "accountType": "G/L Account",
    "accountNumber": "705000",
    "amount": 99.90,
    "description": "Suscripción TRANSCEND - Plan Premium",
    "dimensionValues": [{"code": "PRODUCT", "valueCode": "TRANSCEND"}]
  }'

Python: Integración completa

python
import requests

TOKEN = "tu_token_transcend"
BC_TOKEN = "tu_token_business_central"
BC_API = "https://api.businesscentral.dynamics.com/v2.0/..."

def integrar_facturas_pay_a_dynamics():
    """Obtiene facturas de TRANSCEND Pay y las registra en Dynamics."""
    facturas = requests.get(
        "https://back.transcend.cargoffer.com/pay/api/invoices?status=paid",
        headers={"Authorization": f"Bearer {TOKEN}"}
    ).json()

    for f in facturas:
        payload = {
            "accountType": "G/L Account",
            "accountNumber": "705000",
            "amount": f["total"],
            "description": f.get("description", "Suscripción TRANSCEND"),
            "documentDate": f.get("date", "")[:10],
            "dimensionValues": [
                {"code": "CUSTOMER", "valueCode": f.get("companyId", "")}
            ]
        }

        requests.post(
            f"{BC_API}/journalLines",
            json=payload,
            headers={"Authorization": f"Bearer {BC_TOKEN}"}
        )

def sincronizar_perfiles():
    """Sincroniza empresas de TRANSCEND Profiles a Dynamics."""
    empresas = requests.get(
        "https://back.transcend.cargoffer.com/profiles/api/companies",
        headers={"Authorization": f"Bearer {TOKEN}"}
    ).json()

    for e in empresas:
        payload = {
            "number": e["id"],
            "displayName": e.get("legalName", e.get("displayName", "")),
            "email": e.get("email", ""),
            "phone": e.get("phone", ""),
            "address": e.get("address", {}).get("street", ""),
            "city": e.get("address", {}).get("city", ""),
            "country": e.get("address", {}).get("country", "ES"),
            "taxId": e.get("taxId", "")
        }

        requests.patch(
            f"{BC_API}/companies(companyId={e['id']})",
            json=payload,
            headers={"Authorization": f"Bearer {BC_TOKEN}"}
        )

Documentación relacionada

Documentación de Cargoffer