Network Gate Shop API

A PHP wrapper for the Network Gate REST API. Easily interact with the Network Gate REST API securely using this library. If using a HTTPS connection this library uses BasicAuth, else it uses Oauth to provide a secure connection to Network Gate.

Setup

Setup for the new NG REST API integration (Network Gate Shop 3.6 or later):

require __DIR__ . '/vendor/autoload.php';
use Automattic\Shop\Client;
$shop = new Client(
  'https://networkgate.lt',
  'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  [
    'version' => 'wc/v3',
  ]
);

Client class

$shop = new Client($url, $consumer_key, $consumer_secret, $options);

Options

OptionTypeRequiredDescription
urlstringyesYour Store URL, example: http://woo.dev/
consumer_keystringyesYour API consumer key
consumer_secretstringyesYour API consumer secret
optionsarraynoExtra arguments (see client options table)

Client options

OptionTypeRequiredDescription
versionstringnoAPI version, default is wc/v3
timeoutintnoRequest timeout, default is 15
verify_sslboolnoVerify SSL when connect, use this option as false when need to test with self-signed certificates, default is true
follow_redirectsboolnoAllow the API call to follow redirects
query_string_authboolnoForce Basic Authentication as query string when true and using under HTTPS, default is false
oauth_timestampstringnoCustom oAuth timestamp, default is time()
oauth_onlyboolnoOnly use oauth for requests, it will disable Basic Auth, default is false
user_agentstringnoCustom user-agent, default is Shop API Client-PHP
wp_api_prefixstringnoCustom WP REST API URL prefix, used to support custom prefixes created with the rest_url_prefix filter
wp_apiboolnoSet to false in order to use the legacy Shop REST API (deprecated and not recommended)
method_override_queryboolnoIf true will mask all non-GET/POST methods by using POST method with added query parameter ?_method=METHOD into URL
method_override_headerboolnoIf true will mask all non-GET/POST methods (PUT/DELETE/etc.) by using POST method with added X-HTTP-Method-Override: METHOD HTTP header into request

Client methods

GET

$shop->get($endpoint, $parameters = []);

POST

$shop->post($endpoint, $data);

PUT

$shop->put($endpoint, $data);

DELETE

$shop->delete($endpoint, $parameters = []);

OPTIONS

$shop->options($endpoint);

Arguments

ParamsTypeDescription
endpointstringNetwork Gate Shop API endpoint, example: customers or order/12
dataarrayOnly for POST and PUT, data that will be converted to JSON
parametersarrayOnly for GET and DELETE, request query string

Response

All methods will return arrays on success or throwing HttpClientException errors on failure.

use Automattic\Shop\HttpClient\HttpClientException;
try {
  // Array of response results.
  $results = $shop->get('customers');
  // Example: ['customers' => [[ 'id' => 8, 'created_at' => '2015-05-06T17:43:51Z', 'email' => ...
  echo '<pre><code>' . print_r($results, true) . '</code><pre>'; // JSON output.
  // Last request data.
  $lastRequest = $shop->http->getRequest();
  echo '<pre><code>' . print_r($lastRequest->getUrl(), true) . '</code><pre>'; // Requested URL (string).
  echo '<pre><code>' .
    print_r($lastRequest->getMethod(), true) .
    '</code><pre>'; // Request method (string).
  echo '<pre><code>' .
    print_r($lastRequest->getParameters(), true) .
    '</code><pre>'; // Request parameters (array).
  echo '<pre><code>' .
    print_r($lastRequest->getHeaders(), true) .
    '</code><pre>'; // Request headers (array).
  echo '<pre><code>' . print_r($lastRequest->getBody(), true) . '</code><pre>'; // Request body (JSON).
  // Last response data.
  $lastResponse = $shop->http->getResponse();
  echo '<pre><code>' . print_r($lastResponse->getCode(), true) . '</code><pre>'; // Response code (int).
  echo '<pre><code>' .
    print_r($lastResponse->getHeaders(), true) .
    '</code><pre>'; // Response headers (array).
  echo '<pre><code>' . print_r($lastResponse->getBody(), true) . '</code><pre>'; // Response body (JSON).
} catch (HttpClientException $e) {
  echo '<pre><code>' . print_r($e->getMessage(), true) . '</code><pre>'; // Error message.
  echo '<pre><code>' . print_r($e->getRequest(), true) . '</code><pre>'; // Last request data.
  echo '<pre><code>' . print_r($e->getResponse(), true) . '</code><pre>'; // Last response data.
}

Integration

Integrate Third-party
Custom App

Google Drive

Google Drive

Competently generate unique e-services and client-based models. Globally engage tactical niche

Google Drive

Google Drive

Competently generate unique e-services and client-based models. Globally engage tactical niche

New
Google Drive

Google Drive

Competently generate unique e-services and client-based models. Globally engage tactical niche

Premium

Let's Try! Get Free Support

Start Your 14-Day Free Trial

We can help you to create your dream website for better business revenue.

  • Free 14-day trial
  • No credit card required
  • Support 24/7
  • Cancel anytime