interworks/sigmarest

This package allows simple REST API communication with Sigma.

v0.0.2 2025-01-29 22:08 UTC

This package is auto-updated.

Last update: 2025-03-29 01:09:43 UTC


README

GitHub Workflow Status (Pest) GitHub Workflow Status (PHPStan) Latest Version License

This is a simple API for calling REST API's against Sigma. It handles authentication for you so install, add the environment variables, and start making REST API calls!

Getting Started

Installation

Requires PHP >= 8.2.

composer require interworks/sigmarest

Next, add the following required environment variables to your .env file:

SIGMA_API_URL="https://YOUR-API-URL.com"
SIGMA_CLIENT_ID="YOUR-CLIENT-ID"
SIGMA_CLIENT_SECRET="YOUR-CLIENT-SECRET"

Use the following doc from Sigma to find these values: Get started with the Sigma REST API

Usage Guide

There is a function for each documented Sigma REST API endpoint. Those endpoints can be found here: Sigma REST API Documentation

Basic Usage

Instantiate a SigmaREST object and start making calls!

use InterWorks\SigmaREST\SigmaREST;

// Instantiate
$sigma = new SigmaREST();

// Get first 100 users and create a collection.
$users = $sigma->getMembers(['limit' => 100]);
$users = collect($users['entries']);

// Get first 10 workbooks, loop through each and get their sources
$workbooks = $sigma->getWorkbooks(['limit' => 10]);
$sources   = [];
foreach ($workbooks['entries'] as $workbook) {
    $sources[] = $sigma->getWorkbookSource($workbook['workbookId']);
}

Unsupported Endpoints

If there's an endpoint missed, you can use the call function to specify the URL, arguments, and method. The function returns a Illuminate\Http\Client\Response object.

$response = $sigma->call(
    url   : 'cool/unknown/endpoint',
    args  : ['name' => 'Cool thing'],
    method: 'POST'
);
$response->json();

Function Return Type Options

By default, either an array or boolean will be returned depending on the endpoint. If you'd like more control over how the response is processed, you can set returnResponseObject to true in the constructor to always receive the Illuminate\Http\Client\Response object.

$sigma    = new SigmaREST(returnResponseObject: true);
$response = $sigma->getMembers(['limit' => 100]);
$success  = $response->successful();
$body     = $response->body();
$users    = $response->json();

License

This package is released under the MIT License. See LICENSE for details.