5. Agent data pushΒΆ
https://staging-swagger.maklaro.net/#/process/post_api_valuation_agent
Full PHP example, including token generation
<?php
// expects JWT dependency: composer require firebase/php-jwt
require_once 'vendor/autoload.php';
// supplied from maklaro
$sharedSecret = 'ASDF';
$partnerId = 'XYZ';
// supplied via token received from update request, or pushed to partners
$leadId = '123';
$leadToken = '456';
// target endpoint
$targetUrl = 'https://staging-v7.maklaro.net/api/valuation/agent';
$nonce = sha1(mt_rand(100000,999999).time());
$timestamp = date('Y-m-d H:i:s', time());
$exp = time() + 60;
$payload = array(
'type' => 'update',
'nonce' => $nonce,
'partner_id' => $partnerId,
'timestamp' => $timestamp,
'lead_id' => $leadId,
'lead_token' => $leadToken,
'exp' => $exp
);
$secret = $partnerSecret.$nonce;
$token = \Firebase\JWT\JWT::encode($payload, $secret, 'HS256');
$postData = array(
'lead_id' => $leadId,
'agent_data' => array(
'name' => 'John Smith',
'title' => 'Herr',
'job_title' => 'Immobilienexperte',
'email' => 'john-smith@email.com',
'phone' => '040 228 676 990',
'mobile' => '040 228 676 990',
'fax' => '040 228 676 990 - 1',
'picture' => 'https://link.to/some/agent/picture'
),
'callback' => array(
'url' => 'https://link.to/some/callback'
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $targetUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Content-Type: application/json',
'X-Auth-Token: Bearer '.$token,
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
var_export($response);
// status 200 on success and no content
// status 40* on failure and json with error message