interworks / sigmarest
This package allows simple REST API communication with Sigma.
Requires
- php: ^8.2
Requires (Dev)
- orchestra/testbench: ^9.9
- pestphp/pest: ^3.7
- phpstan/phpstan: ^2.1
README
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.