Browser and node module for making API requests against Hanzo.
Please note: This module uses Popsicle to make API requests. Promises must be supported or polyfilled on all target environments.
npm install hanzo --save
bower install hanzo --save
var Hanzo = require('hanzo');
var client = new Hanzo();
<script src="hanzo/index.js"></script>
<script>
var client = new Hanzo();
</script>
You can set options when you initialize a client or at any time with the options
property. You may also override options for a single request by passing an object as the second argument of any request method. For example:
var client = new Hanzo({ ... });
client.options = { ... };
client.resource('/').get(null, {
baseUri: 'http://example.com',
headers: {
'Content-Type': 'application/json'
}
});
You can override the base URI by setting the baseUri
property, or initializing a client with a base URI. For example:
new Hanzo({
baseUri: 'https://example.com'
});
If the base URI has parameters inline, you can set them by updating the baseUriParameters
property. For example:
client.options.baseUriParameters.version = 'v3';
All methods return a HTTP request instance of Popsicle, which allows the use of promises (and streaming in node).
- id string
var resource = client.resources.store.id(id);
Basic Store calls are keyed upon the unique ID of the Store. As with all calls, it also requires an access key included with the request.
resource.get().then(function (res) { ... });
- key string
var resource = client.resources.store.id(id).variant.key(key);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Variant is as simple as passing its ID to the Variant endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 200.
resource.delete().then(function (res) { ... });
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Variant JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
It is possible to access the product variants organized under a store by providing the store's unique identifier and the variant's unique key. As with all calls, this requires an API key included along with the request.
resource.get().then(function (res) { ... });
- key string
var resource = client.resources.store.id(id).product.key(key);
It is possible to access the products belonging to a store by passing in the store's unique identifier, followed by the product's unique key. As with all calls, this also requires an access key to be included with the request.
resource.get().then(function (res) { ... });
var resource = client.resources.site;
This will deploy a new site.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreateaSiterequest"
}
Returns all sites that you are authorized to see.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.site.id(id);
The only input this requires is the contextual site ID, and it will respond with 200 OK.
resource.delete().then(function (res) { ... });
This functionally is a POST/Create command with a contextual site ID.
resource.put().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/Updateasiterequest"
}
These site calls are keyed on the SiteId in the Site object. As with all calls, it also requires an access key to be sent along with the request.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.user.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a User is as simple as passing its ID to the User endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 200.
resource.delete().then(function (res) { ... });
Basic User calls are keyed upon the unique ID of the User. As with all calls, it also requires an access key included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreateaUserrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid User JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic User calls are keyed upon the unique ID of the User. As with all calls, it also requires an access key included with the request.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.variant.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Variant is as simple as passing its ID to the Variant endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 200.
resource.delete().then(function (res) { ... });
Basic Variant calls are keyed upon the unique ID of the Variant. As with all calls, it also requires an access key included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreateaVariantrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Variant JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic Variant calls are keyed upon the unique ID of the Variant. As with all calls, it also requires an access key included with the request.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.product.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Product is as simple as passing its ID to the Product endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 200.
resource.delete().then(function (res) { ... });
Basic Product calls are keyed upon the unique ID of the Product. As with all calls, it also requires an access key included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreatingaProductrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Product JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic Product calls are keyed upon the unique ID of the Product. As with all calls, it also requires an access key included with the request.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.transaction.id(id);
This is the only call that is available for Transactions, as they are too directly sensitive to allow to be modified.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.referrer.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Referrer is as simple as passing its ID to the Referrer endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 200.
resource.delete().then(function (res) { ... });
Basic Referrer calls are keyed upon the unique ID of the Referrer. As with all calls, it also requires an access key included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreatingaReferrerrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Referrer JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic Referrer calls are keyed upon the unique ID of the Referrer. As with all calls, it also requires an access key included with the request.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.referral.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Referral is as simple as passing its ID to the Referral endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 200.
resource.delete().then(function (res) { ... });
Basic Referral calls are keyed upon the unique ID of the Referral. As with all calls, it also requires an access key included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreatingaReferralrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Referral JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic Referral calls are keyed upon the unique ID of the Referral. As with all calls, it also requires an access key included with the request.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.order.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Order is as simple as passing its ID to the Order endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 200.
resource.delete().then(function (res) { ... });
Basic Order calls are keyed upon the unique ID of the Order. As with all calls, it also requires an access key included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreateanOrderrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Order JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic Order calls are keyed upon the unique ID of the Order. As with all calls, it also requires an access key included with the request.
resource.get().then(function (res) { ... });
var resource = client.resources.order.id(id).payments;
It is possible to get a listing of all the payments on a specific order with this endpoint.
resource.get().then(function (res) { ... });
var resource = client.resources.order.id(id).capture;
The second step of the two-step payment process involves capturing a pre-authorized payment. The order ID is required for this step, but it is returned in the Authorize step (see above).
resource.post().then(function (res) { ... });
application/json
{
"properties": {}
}
- id string
var resource = client.resources.form.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Form is as simple as passing its ID to the Form endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 204.
resource.delete().then(function (res) { ... });
Basic Form calls are keyed to the unique ID of the form. As with all calls, it also requires an API key to be included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreateaFormrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Form JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic Form calls are keyed to the unique ID of the form. As with all calls, it also requires an API key to be included with the request.
resource.get().then(function (res) { ... });
var resource = client.resources.form.id(id).submit;
resource.post().then(function (res) { ... });
application/json
{
"type": "object"
}
- id string
var resource = client.resources.collection.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Collection is as simple as passing its ID to the Collection endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 204.
resource.delete().then(function (res) { ... });
Basic Collection calls are keyed to the unique ID of the collection. As with all calls, it also requires an API key to be included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreateaCollectionrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Collection JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic Collection calls are keyed to the unique ID of the collection. As with all calls, it also requires an API key to be included with the request.
resource.get().then(function (res) { ... });
- id string
var resource = client.resources.coupon.id(id);
The PATCH method will allow you to replace a given ID's data in a piecemeal fashion. Any fields passed in to a PATCH method will be updated with what you request, while any fields not specified in the JSON will be left alone.
resource.patch().then(function (res) { ... });
application/json
{
"properties": {}
}
Deleting a Coupon is as simple as passing its ID to the Coupon endpoint using the HTTP Delete method. You will not receive a response past the normal HTTP 204.
resource.delete().then(function (res) { ... });
Basic Coupon calls are keyed upon the unique ID of the Coupon. As with all calls, it also requires an access key included with the request.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/CreateaCouponrequest"
}
The PUT method will allow you to replace a given ID's data in its entirety. Passing in valid Coupon JSON (see the POST method), will overwrite any and all data existing on that ID.
resource.put().then(function (res) { ... });
application/json
{
"properties": {}
}
Basic Coupon calls are keyed upon the unique ID of the Coupon. As with all calls, it also requires an access key included with the request.
resource.get().then(function (res) { ... });
var resource = client.resources.checkout.authorize;
The two-step payment process separates the two steps mentioned in the one-step payment process, and allows you to authorize a payment, and then capture it at a later period. This is useful for pre-orders or other such payments that you do not wish to collect until shipment. The basic data needs remain the same, as Hanzo implicitly creates the Order and User for you, for later use in the capture portion.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/Authorizerequest"
}
var resource = client.resources.checkout.charge;
The one-step payment process is mostly used for general commerce for immediate fulfillment/sale. In general, you must send three things to successfully complete a charge call: order information, payment information, and user information. In essence, the one-step payment method takes this information, authorizes the payment, and, if successful, immediately attempts to capture it. Any failure in this process will result in a failure of the call.
resource.post().then(function (res) { ... });
application/json
{
"$ref": "#/definitions/ChargeanOrderrequest"
}
You can make requests to a custom path in the API using the #resource(path)
method.
client.resource('/example/path').get();
Apache 2.0