Access Exact Online API from Laravel

Work In Progress!

To work access Exact Online from Laravel there are quite a few steps to take. You could use the Picqer PHP package or Laravel package based on that PHP Package .

Initial Setup

In both cases you are told to

– Set up app at Exact App Center to retrieve credentials
– Authorize the integration from your app
– Parse callback and finish connection set up

yourself first. So starting at the beginning in the documentation:

  1. App Setup at Exact – Do an app setup with Exact using you developer account. This can be production or test application. One you need to name and add a callback url. You will then also get a client secret and client id
  2. Authorization request – Do a GET request to get the authorization code after login or bypass it using client credentials or no forced login
  3. Access token – Get your access token which you can then use to interact with Exact online usage the Laravel or PHP package. This token will be sent to your redirect or callback url
  4. Refresh token – Scenario to get a new refresh token to keep connection going

Callback URL

The callback url is used to store the access token. So in our routes we need to set this up. Without it and or without the refresh token we cannot access Exact Online nor use any of the Laravel Package Facades or other methods that the Picqer PHP Package provides. So how do we go about this?

A similar setup with Slack explains how to store the token in the callback url in cache https://medium.com/@bastones/integrating-slack-into-your-laravel-api-5b14b3b84bac :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Services\Slack\Slack;class SlackController extends Controller
{
   /**
    * Send the grant token authorisation URL.
    *
    * @param Request $request
    * @return \Illuminate\Http\JsonResponse
    */
   public function grant(Request $request)
   {
      $auth = (new Slack)->getAuthorisationUrl();      cache([
         "user.{$request->user()->id}.state" => $auth['token'],
      ], now()->addHour());      // Or with the helper class, if preferred:      // (new SecurityToken('slack'))->store($auth['token']);      return response()->json([
        'url' => $auth['url'],
      ]);
   }
}

OAUTH2.0 Test

Exact made a video how to test oauth 2.0 access to their api using Postman. Here is the video embedded:

Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.