Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Examples

This directory contains example code and tutorials for using the Exact Online Client.

Note: This client is read-only and designed for fetching data from Exact Online. It does not support creating, updating, or deleting data in Exact Online.

Getting Started Examples

Basic OAuth2 Flow

See oauth2-example.md for a step-by-step guide on setting up OAuth2 authentication.

Using the API Client

See api-client-example.md for examples of fetching accounts, subscriptions, and transactions.

Webhook Setup

See webhook-example.md for setting up and handling webhooks.

Code Examples

Example 1: Fetch All Accounts

@RestController
@RequiredArgsConstructor
public class AccountController {
    
    private final ExactOnlineApiClient apiClient;
    
    @GetMapping("/accounts")
    public ResponseEntity<List<ExactOnlineAccountDto>> getAllAccounts() {
        List<ExactOnlineAccountDto> accounts = apiClient.fetchAllAccounts().block();
        return ResponseEntity.ok(accounts);
    }
}

Example 2: Subscribe to Webhooks

@RestController
@RequiredArgsConstructor
public class WebhookController {
    
    private final ExactOnlineWebhookService webhookService;
    
    @PostMapping("/subscribe")
    public ResponseEntity<String> subscribe() {
        UUID subscriptionId = webhookService.subscribeToWebhook(
            "https://your-app.com/webhook",
            "Accounts"
        ).block();
        
        return ResponseEntity.ok("Subscribed with ID: " + subscriptionId);
    }
}

Example 3: Handle Webhook Notifications

@RestController
@RequiredArgsConstructor
public class WebhookHandlerController {
    
    private final ExactOnlineWebhookRouter webhookRouter;
    
    @PostMapping("/webhook")
    public ResponseEntity<Void> handleWebhook(
            @RequestBody WebhookNotificationDto notification) {
        webhookRouter.routeNotification(notification);
        return ResponseEntity.ok().build();
    }
}

Integration Examples

Spring Boot Configuration

# application.yml
exact-online:
  oauth2:
    client-id: ${EXACT_ONLINE_CLIENT_ID}
    client-secret: ${EXACT_ONLINE_CLIENT_SECRET}
    division-id: ${EXACT_ONLINE_DIVISION_ID}
    redirect-uri: ${EXACT_ONLINE_REDIRECT_URI:http://localhost:8080/callback}

Docker Compose Example

See the root docker-compose.yml for a complete example with all services.

Advanced Examples

Custom Webhook Handler

@Component
public class CustomAccountHandler implements WebhookTopicHandler {
    
    @Override
    public String getTopic() {
        return "Accounts";
    }
    
    @Override
    public void handleNotification(JsonNode data, String key) {
        // Your custom logic here
        log.info("Account updated: {}", key);
    }
}

Event Publishing

@Service
@RequiredArgsConstructor
@ConditionalOnProperty(name = "exact-online.events.enabled", havingValue = "true")
public class CustomEventService {
    
    private final AmqpTemplate amqpTemplate;
    
    public void publishCustomEvent(MyEvent event) {
        amqpTemplate.convertAndSend(
            "exact-online-events",
            "custom.routing.key",
            event
        );
    }
}

More Examples

  • Check the test files in src/test/java for more usage examples
  • Review the controller implementations in src/main/java/io/exactonline/client/controller/
  • See the service layer for business logic examples