• Resolved benjamen02

    (@benjamen02)


    Hi Team,

    Another Question – generally about calling the AlexaCRM api in php code (i am using the dataverse integration and have this plug in enabled). Are there any good examples here? I have been trying to code from this tutorial but with no luck

    https://github.com/AlexaCRM/dynamics-webapi-toolkit/wiki/Tutorial

    This example i want to run the php function – call_order_status_completed when an order to complete and create a contact. I know the action works just not the code i have for Alexacrm integration

    // define woocommerce_order_status_completed callback function
    function call_order_status_completed( $array ) {

    $contact = new \AlexaCRM\Xrm\Entity( ‘contact’ );
    $contact[‘firstname’] = ‘Nancy’;
    $contact[‘lastname’] = ‘Anderson’;
    $contact[’emailaddress1′] = ‘[email protected]’;

    $contactId = $client->Create( $contact );

    };

    // Call our custom function with the action hook
    add_action( ‘woocommerce_order_status_completed’, ‘call_order_status_completed’, 10, 1);

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author alexacrm

    (@alexacrm)

    @benjamen02

    when you say code does not work, what exactly is the problem?

    And how do you instantiate $client?

    Thanks
    George

    Thread Starter benjamen02

    (@benjamen02)

    I just have the code in the function.php and wasn’t sure how much i need to initialize or how to include the Alexa Libraries. Do i need to include all of this in the funciton.php

    use AlexaCRM\CRMToolkit\Client as OrganizationService;
    use AlexaCRM\CRMToolkit\Settings;
    use AlexaCRM\CRMToolkit\Client;
    use AlexaCRM\CRMToolkit\Entity\MetadataCollection;
    use AlexaCRM\CRMToolkit\Entity\EntityReference;

    $options = include( ‘config.php’ );

    $serviceSettings = new Settings( $options );
    $service = new OrganizationService( $serviceSettings );

    $clientSettings = new Settings( $options );
    $client = new Client( $clientSettings );`

    Do you have a complete example of calling any create function in the wordpress function.php?

    Plugin Author alexacrm

    (@alexacrm)

    @benjamen02 we already do the heavy lifting for you, you don’t need to instantiate the client

    use AlexaCRM\Nextgen\ConnectionService;
    use AlexaCRM\Xrm\{
      EntityReference,
      Entity,
      KeyAttributeCollection,
      ColumnSet
    };
    
    function call_order_status_completed( $array ) {
    
    $client = ConnectionService::instance()->getClient();
    
    $contact = new Entity( 'contact' );
    $contact['firstname'] = 'Nancy';
    $contact['lastname'] = 'Anderson';
    $contact['emailaddress1′] = '[email protected]';
    
    $contactId = $client->Create( $contact );
    };
    
    // Call our custom function with the action hook
    add_action( 'woocommerce_order_status_completed', 'call_order_status_completed', 10, 1);

    If that does not work, I’d need to see the errors you’re getting.

    • This reply was modified 3 years, 6 months ago by alexacrm.
    Thread Starter benjamen02

    (@benjamen02)

    George, You are awesome! Worked Well

    • This reply was modified 3 years, 6 months ago by benjamen02.
    Plugin Author alexacrm

    (@alexacrm)

    @benjamen02 glad to hear that. For event handling we’re bringing in webhooks that will be better suited to trigger something like Power Automate or Zapier. That should be much friendlier than messing around with php code ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Use AlexaCRM Api to Create record on Order Completion’ is closed to new replies.