Zum Hauptinhalt springen

Daten welche Enneo an ihren Code übergibt (Input)

{
  "contractId": "VN-00001"
}

Datenstruktur welche Enneo als Rückgabewert erwartet (Output)

{
    // Mandatory properties. Must be defined or enneo to work
    "id": "VN-00001", // must be integer or string up to 50 chars
    "customerId": "C-abcd-123", // must be integer or string up to 50 chars. If "null", then a placeholder contract is created for the customer
    "business": false, // boolean, if the customer is a company or private person
    "lastname": "Smith", // last name of customer, can be null ONLY if business is true
    "company": null, // company name, e.g. "ACME Corp.", can be null ONLY if business is false

    // Recommended properties. Should be defined if possible and is used by Enneo's AI and customer identification logic. Default to null if not set
    "firstname": "John", // first name of customer, can be null
    "email": "[email protected]",
    "deliveryAddress": "Horst-Kohl-Str. 15a, 12157 Berlin", // address of customer
    "billingAddress": null, // Optional separate billing address. If null, then billing address is the same as delivery address
    "phone": "+49190332332",
    "zip": "12157", // Used by the default call/phone identifaction based on contract id and zip code

    // Optional preview section for the agent that is shown in top right corner on ticket page
    "agentPreview": [
        {
            "url": "https://my-erp/customers/1234#tab=billing",
            "type": "string",
            "label": "Abschlag",
            "value": "39 €",
            "tooltip": null
        },
        {
            "url": null,
            "type": "string",
            "label": "Verbrauch",
            "value": "1085 kWh",
            "tooltip": "Abschlagsrelevant: 1085 kWh<br>NB-JVP: 1637 kWh<br>Vorjahr: 1637 kWh<br>Lt. Kd.: 3500 kWh"
        }
    ],

    // Links to any systems holding client data you want your agents to have quick access to
    "erpUrls": [
        {
            "url": "https://my-erp.com/contract-details/1234",
            "icon": "/icons/powercloud.svg"
        },
        {
            "url": "https://my-marketing-crm.com/customer-details/c123",
            "icon": "/icons/link.svg"
        }
    ],

    // You may define any other properties you want enneo to be aware of here.
    // See below some examples as inspiration from the energy sector
    "iban": "DE0000000000000000",
    "energy": "electricity",
    "status": "expired",
    "endDate": "2021-10-28",
    "orderId": 752050,
    "vatRate": 0.19,
    "basePrice": 49.41
}

Beispielimplementierung

<?php

// Load enneo SDK. Input is made available through $in
use EnneoSDK\ApiEnneo;
use EnneoSDK\Setting;
use EnneoSDK\Api;
require(getenv()['SDK']);

$contractId = $in->contractId; // Populated with the data received, e.g. 1234 or "C-212"

// Here you can call your API and/or add your data processing logic

// Option 1: Directly
// $contractRawData = Api::call(method: 'POST',url: 'https://xxx', headers: ['Authorization: AbC'], params: http_build_query(['contractId' => $contractId]));
$contractRawData = Api::call(method: 'GET', url: 'https://admin.enneo.ai/api/seed-contracts/' . $contractId);

// Option 2: Through a user-defined-function that handles e.g. OAuth2 session tokens
// $contractRawData = ApiEnneo::executeUdf('erpApiCall', ["method" => "GET", "api" => "vertrag/$contractId", "params" => false]);

// Option 3: By using enneo user storage object as database (only recommended for testing)
// $userDataObject = Setting::get('udfStorage');
// $contractRawData = array_search($contractId, array_column($userDataObject->contracts, 'contractId')) or throw new Exception("Contract $contractId not found");

// This is the data format you should return
$contract = [
    // Mandatory properties. Must be defined or enneo to work
    'id' => $contractId, // must be integer or string up to 50 chars
    'customerId' => $contractRawData->customerId, // must be integer or string up to 50 chars
    'business' => $contractRawData->processedData->business, // boolean, if the customer is a company or private person
    'lastname' => $contractRawData->processedData->lastname, // last name of customer, can be null ONLY if business is true
    'company' => $contractRawData->processedData->company, // company name, e.g. "ACME Corp.", can be null ONLY if business is false

    // Recommended properties. Should be defined if possible and is used by Enneo's AI and customer identification logic. Default to null if not set
    'firstname' => $contractRawData->processedData->firstname, // first name of customer, can be null
    'email' => $contractRawData->processedData->email,
    'deliveryAddress' => $contractRawData->processedData->deliveryAddress, // address of customer
    'billingAddress' => $contractRawData->processedData->billingAddress, // Optional separate billing address. If null, then billing address is the same as delivery address
    'letterAddress' => ($contractRawData->processedData->company ?: $contractRawData->processedData->firstname.' '.$contractRawData->processedData->lastname).', '.($contractRawData->processedData->billingAddress ?? $contractRawData->processedData->deliveryAddress),
    'phone' => $contractRawData->processedData->phone,

    // Preview section for the agent that is shown in top right corner on ticket page
    'agentPreview' => array_map(function($item) {
        return [
            'url' => $item->url, // e.g. "https://my-erp/customers/1234#tab=billing"
            'type' => $item->type, // e.g. "string"
            'label' => $item->label, // e.g. "Abschlag"
            'value' => $item->value, // e.g. "39 €"
            'tooltip' => $item->tooltip, // e.g. "Ab 1. Januar 2025"
        ];
    }, $contractRawData->processedData->agentPreview),

    // Links to any systems holding client data you want your agents to have quick access to
    'erpUrls' => [
        [
            'url' => 'https://my-erp.com/contract-details/1234',
            'icon' => '/icons/powercloud.svg'
        ],
        [
            'url' => 'https://my-marketing-crm.com/customer-details/c123',
            'icon' => '/icons/link.svg'
        ]
    ],
    'erpUrls' => array_map(function($item) {
        return [
            'url' => $item->url, // e.g. "https://sap.example.com/contracts/100001"
            'icon' => $item->icon, // e.g. "/icons/sap.svg",
            'title' => $item->title, // e.g. SAP
        ];
    }, $contractRawData->processedData->erpUrls),
];

// You may define any other properties you want enneo to be aware of here. 
$contract = [
    ...$contract,
    ...array_diff_key((array) $contractRawData->processedData, $contract)
];

echo json_encode($contract);