PHP code example of softcomtecnologia / softcom-api-php

1. Go to this page and download the library: Download softcomtecnologia/softcom-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

softcomtecnologia / softcom-api-php example snippets


    {
        "oftcomtecnologia/softcom-api-php": "*"
        }
    }

    $options = [
        'domain'        => 'http://<url-softcom>/softauth',
        'clientId'      => '<your-client-id>',
        'clientSecret'  => '<your-client-secret>',
        'deviceId'      => '<your-device-id>',
        'deviceName'    => '<name-for-your-device>',
    ];
    
    $provider = new SoftcomProvider($options);
    $token = $provider->getAccessToken(new SoftcomCredentials());
    
    echo $token;//your token ex.: 301b7689eb926495a02fe4ba4932d7bfa80aa202

    $options = [...];
    $provider = new SoftcomProvider($options);
    $token = 'your-token-string';//or SoftcomAccessToken object
    $url = '/api/example';//without domain
    $params = [
        'key' => 'value',
        //...
    ];
    
    $resource = $provider->get($token, $url, $params);
    
    echo json_decode($resource->getContents(), 1);
    /*
     * [
     *      "code" => 1,
     *      "message" => "OK",
     *      "human" => "Sucesso",
     *      "data" => [
     *          "username" => "my username",
     *          "name" => "softcom",
     *      ],
     *      "meta" => []
     * ]
     */

    $options = [...];
    $provider = new SoftcomProvider($options);
    $token = 'your-token-string';//or SoftcomAccessToken object
    $url = '/api/example';//without domain
    $params = [
        'key' => 'value',
        //...
    ];
    
    $resource = $provider->post($token, $url, $params);
    
    echo json_decode($resource->getContents(), 1);
    /*
     * [
     *      "code" => 1,
     *      "message" => "OK",
     *      "human" => "Sucesso",
     *      "data" => [
     *          "username" => "my username",
     *          "name" => "softcom",
     *      ],
     *      "meta" => []
     * ]
     */