Skip to main content

MFR ApiService & Clients

Drei Bausteine, je nach Use-Case:

KlasseZweckAuth
App\Http\Clients\GuzzleClientdirekter REST-Call (POST/PUT/DELETE)Basic Auth
App\Http\Clients\ODataClientOData-Queries (from, expand, where)Basic Auth
App\Services\MfrApiServiceOrchestrator (kapselt beide)

GuzzleClient — Direct REST

Wird in jedem Mfr/<Entity>Controller instantiiert:

public function __construct() {
$this->guzzle = new GuzzleClient('mfr');
}

// Verwendung
$body = json_encode($request->all(), true);
$mfrResponse = $this->guzzle->post('Companies', $body);

$mfrResponse = $this->guzzle->put(
'Companies(' . $company->Id . 'L)',
$company->makeHidden(['created_at','updated_at'])->toJson()
);

$this->guzzle->delete('Companies(' . $company->Id . 'L)');

Achtung: MFR (OData) erwartet IDs in der URL als (123L) — nicht (123). Das L markiert in OData ein 64-bit-Integer-Literal.

Vollständige Methoden-Liste in Common HTTP-Clients.

ODataClient — Query-Builder

Für Reads / komplexe Filter:

use App\Http\Clients\ODataClient;

$mfr = (new ODataClient())->mfr;

// Liste mit Expand
$companies = $mfr->from('Companies')
->skip(0)
->order('ExternalId')
->expand('Contacts,Tags,ServiceObjects,MainContact')
->get();

// Single-Record by Id
$company = $mfr->from('Companies(61149446314L)')
->expand(\App\Http\Helpers\Mfr\Helper::getExpand('Companies'))
->get()
->first();

// Filter
$active = $mfr->from('ServiceObjects')
->where('Active', true)
->get();

Standard-Expand-Strings

Pro Entity gibt's einen vorkonfigurierten Expand in Mfr\Helper::getExpand():

EntityExpand
CompaniesContacts,Tags,ServiceObjects,MainContact
ContactsCompany,User
DocumentsServiceRequest
ItemTypesUnit
ProductsCustomValueStepTemplate/Steps
ServiceObjectsContacts,Company,Product,Tags
ServiceRequestsQualifications,ServiceObjects,Customer,Reports,Items,Appointments/Contacts,Steps,Comments,StockMovements,Tags
StepListTemplatesSteps
TimeEventsContact,ServiceRequest
UsersContact
$expand = \App\Http\Helpers\Mfr\Helper::getExpand('Companies');
$companies = $mfr->from('Companies')->expand($expand)->get();

MfrApiService

App\Services\MfrApiService

Höhere Orchestrator-Klasse, die Helper, ODataClient und GuzzleClient zusammenpackt — aktuell sehr schlank, gedacht als Erweiterungspunkt.

namespace App\Services;

class MfrApiService
{
public function __construct(
?Mfr\Helper $mfrHelper = null,
?ODataClient $oDataClient = null,
?GuzzleClient $guzzleClient = null,
) {
$this->mfrHelper = $mfrHelper ?? new Helper();
$this->oDataClient = $oDataClient ?? new ODataClient();
$this->guzzleClient = $guzzleClient ?? new GuzzleClient();
}

public function run(string $entity, int $skip = 0, string $expand = ''): void
{
// domänen-spezifische Sync-Logik hier
}
}

Wenn du eine neue, mehrstufige MFR-Sync-Operation kapseln willst, ist das der Ort dafür. Nicht für simple CRUD — das gehört in den jeweiligen Resource-Controller.

Authentication

Beide Clients nutzen Basic-Auth über config('services.mfr.{username,password,base_url}'):

'Authorization' => 'Basic ' . base64_encode($username . ':' . $password),
'Accept' => 'application/json',
'Content-Type' => 'application/json',

Setze in .env:

MFR_BASE_URL="https://portal.mobilefieldreport.com/odata/"
MFR_API_USERNAME="..."
MFR_API_PASSWORD="..."