Laravel 11 and Netsuite REST API SuiteQL

Environment

- Laravel 11
- PHP 8.2.12
- guzzlehttp/oauth-subscriber

Install guzzlehttp/oauth-subscriber

dev@DEV01:~# composer require guzzlehttp/oauth-subscriber

Create Laravel Command

dev@DEV01:~# php artisan make:command getNSLocation

.env

NETSUITE_APIHOST="Setup - Company - Company Information - Company URLs - SUITETALK"
NETSUITE_ACCOUNT="Setup - Company - Company Information - ACCOUNT ID"
NETSUITE_CONSUMER_KEY="Setup - Integration - Manage Integrations"
NETSUITE_CONSUMER_SECRET="Setup - Integration - Manage Integrations"
NETSUITE_TOKEN_KEY="Home - Manage Access Token"
NETSUITE_TOKEN_SECRET="Home - Manage Access Token"

getNSLocation.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Oauth\Oauth1;

class getNSLocation extends Command
{
    protected $signature = 'app:get-ns-location';
    protected $description = 'Get location from Netsuite';

    public function handle()
    {
        $stack = HandlerStack::create();

        $auth = new Oauth1([
            "signature_method" => "HMAC-SHA256",
            'consumer_key' => env('NETSUITE_CONSUMER_KEY'),
            'consumer_secret' => env('NETSUITE_CONSUMER_SECRET'),
            'token' => env('NETSUITE_TOKEN_KEY'),
            'token_secret' => env('NETSUITE_TOKEN_SECRET'),
            'realm' => env('NETSUITE_ACCOUNT')
        ]);

        $stack->push($auth);

        $client = new Client([
            'base_uri' => env('NETSUITE_APIHOST'),
            'handler' => $stack,
            'auth' => 'oauth'
        ]);

        $suiteql = "SELECT * FROM location WHERE isinactive= 'F'";

        $response = $client->post('services/rest/query/v1/suiteql',
            [
                'headers' => [
                'Prefer' => 'transient' ],
                'json' => [
                'q' => $suiteql ]
            ])->getBody()->getContents();

        $response_json = json_decode($response);

        dd($response_json->items);
    }
}

Running Laravel Command :

dev@DEV01:~# php artisan app:get-ns-location

Leave a Comment

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.