PHP Proxy & Rest API

The Plugin includes a PHP Proxy for accessing the Spreadshirt API through Javascript. The Proxy is available as route of the WordPress Rest API.

Example

var options = {
  url : 'https://api.spreadshirt.net/api/v1/shops/40000'
};

sfw.spreadshirt( option ).done(function( shopdata ){
  // do something with the data 
  console.log( shopdata.id );
}); 

Methods

You can access these functions by using the global sfw variable. All request to your server will be protected with nonces. These methods are part of sfw-core.js.

All functions are asynchronous and will return an jQuery.Deferred Object that will resolve with the response.

Options will be passed to jQuery.ajax().

sfw.api( object options )

Retrieve SFW Rest API Response

options.route
Relative rest route to the SFW WordPress Rest API.

options.url
Url to the Rest API. Will be overridden if the route option is set.

sfw.proxy( object options )

Retrieve an API Resource through the PHP Proxy. Will not perform any checks on the response.

options.url
The url of a Spreadshirt Resource. Can be relative rest route.

sfw.spreadshirt( object options )

Retrieve an API Resource. Will check if the response is valid.

options.proxy
To pipe the request through the proxy method or use jQuery.ajax directly. Default is true.

options.check_result
To check the response or not. Default is true.

sfw.api.getShopItem( endpoint, spreadshirt_id )

Retrieve an item from the shop. Applies various filters to the result. Uses Session Storage to cache the result.

Resolves with object of type Spreadshirt on success.

endpoint
A shop endpoint. Must be available as property of the shops api resource.

spreadshirt_id
Any Spreadshirt item id.

sfw.api.getProductType( spreadshirt_id )

sfw.api.getProduct( spreadshirt_id )

sfw.api.getArticle( spreadshirt_id )

sfw.api.getCurrency( spreadshirt_id )

Retrieve currency. Defaults to shop currency.

sfw.api.getCountry( spreadshirt_id )

Retrieve country. Defaults to shop country.

sfw.api.getList( endpoint, args )

Retrieve an item listing from the Spreadshirt API. Applies various filters to the result. Uses Session Storage to cache the result.

Resolves with object of type SpreadshirtList on success.