ballerinax/commercetools.auditlog Ballerina library

2.0.0

Overview

commercetools is a composable commerce platform that provides API-first building blocks for storefronts, carts, orders, customers and catalogs. Its Change History API records every change made to the resources of a Project, including who changed what and when.

The commercetools Audit Log connector lets applications query this change history with REST requests or GraphQL queries. It supports version 1 of the commercetools Change History API.

Key features

  • List the change history across the resources of a Project
  • Read the full change trail of a single resource of a given type
  • Query the change history with GraphQL for exactly the fields you need
  • Authenticate with the OAuth 2.0 client credentials grant using a commercetools API client

Setup guide

To use the commercetools Audit Log connector, you need a commercetools Project and an API client that can read its change history. If you do not have a commercetools account, you can sign up for a trial here.

Step 1: Create an API client

  1. Open the Merchant Center and select your Project.

  2. Go to Settings → Developer settings and select Create new API client.

  3. Give the client a name and select the scope View audit log (view_audit_log). To read the history of a resource type, also grant the view scope of that type, for example view_products for products.

Step 2: Note down the credentials

After the client is created, copy the following values. The client secret is shown only once.

  • Project key
  • Client ID
  • Client secret
  • Auth URL, for example https://auth.us-central1.gcp.commercetools.com
  • Change History API URL, for example https://history.us-central1.gcp.commercetools.com

The token URL is the auth URL followed by /oauth/token.

Quickstart

To use the commercetools Audit Log connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

Import the commercetools.auditlog module.

Copy
import ballerinax/commercetools.auditlog;

Step 2: Instantiate a new connector

  1. Create a Config.toml file and configure the credentials obtained in the steps above:
Copy
clientId = "<Client ID>"
clientSecret = "<Client Secret>"
tokenUrl = "<Auth URL>/oauth/token"
apiUrl = "<Change History API URL>"
projectKey = "<Project key>"
  1. Create an auditlog:ConnectionConfig with the OAuth 2.0 client credentials and initialize the connector with it.
Copy
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string tokenUrl = ?;
configurable string apiUrl = ?;
configurable string projectKey = ?;

final auditlog:Client commercetools = check new ({
    auth: {
        tokenUrl,
        clientId,
        clientSecret
    }
}, apiUrl);

Step 3: Invoke the connector operation

Now, utilize the available connector operations.

List the change history of a Project

Copy
public function main() returns error? {
    auditlog:RecordPagedQueryResponse _ = check commercetools->listChangeHistory(projectKey);
}

Step 4: Run the Ballerina application

Copy
bal run

Examples

The commercetools Audit Log connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:

  1. Recent changes report - Read the Project's change history for a recent time window, follow every page, and report how many changes each user made.

  2. Resource change trail - Find the most recently changed resource of a type and print its full change trail.

Import

import ballerinax/commercetools.auditlog;Copy

Other versions

See more...

Metadata

Released date: 1 day ago

Version: 2.0.0

License: Apache-2.0


Security

Direct vulnerabilities: No known direct vulnerabilities

Indirect vulnerabilities: 

Checked on 2026-11-21 via OSV.dev


Compatibility

Platform: any

Ballerina version: 2201.12.0

GraalVM compatible: Yes


Pull count

Total: 54

Current verison: 1


Weekly downloads


Source repository


Keywords

Vendor/Commercetools

Area/E-Commerce

Type/Connector


Contributors