Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Connector Laravel Package

dynamicscrm/connector

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package to your composer.json:

    "require": {
        "dynamicscrm/connector": "dev-master"
    }
    

    Run:

    composer update
    
  2. First Connection Initialize the connector in a Laravel service or controller:

    use DynamicsCrm\DynamicsCrm;
    
    $crm = new DynamicsCrm(
        env('DYNAMICS_CRM_URL'), // e.g., 'https://yourorg.crm.dynamics.com'
        env('DYNAMICS_CRM_USER'),
        env('DYNAMICS_CRM_PASSWORD')
    );
    
  3. First Use Case: Fetch a Single Record Retrieve a contact by ID:

    $contact = $crm->Retrieve('contact', 123, ['fullname', 'emailaddress1']);
    

Implementation Patterns

Core Workflows

  1. CRUD Operations

    • Create: Insert a new record (e.g., lead or opportunity):
      $params = [
          'subject' => 'New Opportunity',
          'description' => 'Test lead',
          'customerid' => '123' // Contact ID
      ];
      $newOpportunity = $crm->Create('opportunity', $params);
      
    • Update: Modify an existing record:
      $crm->Update('opportunity', ['subject' => 'Updated Subject'], 456);
      
    • Delete: Remove a record:
      $crm->Delete('opportunity', 456);
      
  2. Querying Data

    • RetrieveMultiple: Fetch filtered records with joins:
      $results = $crm->RetrieveMultiple(
          'account',
          "name = 'Acme Corp'",
          ['name', 'revenue'],
          ['join' => 'contact ON accountid = parentcustomerid'],
          'name asc'
      );
      
  3. Integration with Laravel

    • Service Provider: Bind the connector to Laravel’s container for dependency injection:
      // app/Providers/AppServiceProvider.php
      public function register()
      {
          $this->app->singleton(DynamicsCrm::class, function ($app) {
              return new DynamicsCrm(
                  config('services.dynamics.url'),
                  config('services.dynamics.user'),
                  config('services.dynamics.password')
              );
          });
      }
      
    • Config File: Store credentials in config/services.php:
      'dynamics' => [
          'url' => env('DYNAMICS_CRM_URL'),
          'user' => env('DYNAMICS_CRM_USER'),
          'password' => env('DYNAMICS_CRM_PASSWORD'),
      ],
      
  4. Error Handling Wrap CRM calls in try-catch blocks to handle NTLM/auth failures:

    try {
        $data = $crm->Retrieve('account', 789);
    } catch (\Exception $e) {
        Log::error("Dynamics CRM Error: " . $e->getMessage());
        return response()->json(['error' => 'CRM Unavailable'], 500);
    }
    

Gotchas and Tips

Pitfalls

  1. NTLM Authentication

    • Ensure your server supports NTLM (common in legacy CRM setups). Modern Dynamics 365 may require OAuth.
    • Test credentials manually first via tools like Postman or cURL.
  2. Case Sensitivity

    • Table/column names in RetrieveMultiple filters are case-sensitive (e.g., "name = 'Acme'" vs "NAME = 'Acme'").
  3. Rate Limiting

    • Dynamics CRM may throttle requests. Implement exponential backoff for retries:
      use Symfony\Component\HttpClient\RetryableHttpClient;
      
      $client = new RetryableHttpClient(
          new CurlHttpClient(),
          [
              'max_retries' => 3,
              'delay' => 1000,
          ]
      );
      
  4. Deprecated Methods

Debugging Tips

  1. Enable cURL Debugging Add this to your DynamicsCrm constructor to log raw requests:

    curl_setopt($ch, CURLOPT_VERBOSE, true);
    $debug = fopen('php://temp', 'w+');
    curl_setopt($ch, CURLOPT_STDERR, $debug);
    
  2. Validate SOAP Responses Dynamics CRM returns SOAP envelopes. Use SimpleXMLElement to parse:

    $response = $crm->Retrieve('account', 123);
    $xml = simplexml_load_string($response);
    $error = $xml->xpath('//Fault');
    
  3. Environment-Specific Config Use Laravel’s .env for credentials:

    DYNAMICS_CRM_URL=https://yourorg.crm.dynamics.com
    DYNAMICS_CRM_USER=youruser@domain.com
    DYNAMICS_CRM_PASSWORD=yourpassword
    

Extension Points

  1. Custom Headers Extend the connector to add headers (e.g., for API versioning):

    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Accept: application/xml',
        'OData-MaxVersion: 4.0',
        'OData-Version: 4.0',
    ]);
    
  2. Bulk Operations For large datasets, implement batch processing:

    $batchSize = 500;
    $offset = 0;
    do {
        $results = $crm->RetrieveMultiple('account', null, null, null, null, $batchSize, $offset);
        $offset += $batchSize;
    } while (!empty($results));
    
  3. Event Listeners Hook into Laravel’s events to sync CRM data on model updates:

    // app/Listeners/SyncCrmData.php
    public function handle($event)
    {
        $crm = app(DynamicsCrm::class);
        $crm->Update('account', $event->model->toArray(), $event->model->id);
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky