Not sure if this is needed or not but I was struggling with the API implementation and I have cobbled together some examples from various points in the documentation. I have a few examples but I will post one working example of one endpoint. I haven't seen the actual syntax for the parameters so I modified thru trial and error. For example the function docs list the following:
ProductList_Load_Query
But to access it in the call it was
var request = new api.requests.ProductListLoadQuery(client);
The options list also has to be in a specific order. For example:
request.setFilters([{"Customer_ID":"int"}])
.setCount(100)
.setOffset(0)
Will work for the get orders endpoint but if I try to set Offset before Count it will not work. The following example is a product export. I'll leave the assignments for account specific values but remove the private data.
const express = require('express');
const router = express.Router();
const api = require('merchantapi');
const MyApiToken = '{your_api_token}';
const MySigningKey = '{your_signing_key}';
const algorithm = 'sha256';
const options = {
require_timestamps: true,
signing_key_digest: api.Client.SIGN_DIGEST_SHA256,
default_store_code: 'test',
Miva_Request_Timestamp : Math.floor(Date.now() / 1000)
}
const client = new api.Client( 'https://{your_url}/mm5/json.mvc', MyApiToken, MySigningKey, options );
/*
Product export route, requires no input parameters
*/
router.get('/productexport',(req,res)=>{
var request = new api.requests.ProductListLoadQuery(client);
request.setCount( 100 ); // how many records to load
request.setOffset( 0 ); // offset of records to load
request.setStoreCode( 'test' ); // you can optionally set the store code here if you did not pass default_store_code in the client options.
// apply filtering with the filter expression features:
var filters = request.filterExpression();
filters.isTrue( 'active' );
request.setFilters( filters );
request.send( function( error, response ){
if (error){
console.log(error);
return;
}
else if ( !response.isSuccess() ){
console.log('Load Products Error', response.getErrorCode(), response.getErrorMessage());
}
var productResults = response.getProducts();
//loop for testing not neccdessarily needed
response.getProducts().forEach((product)=>{
console.log(product.getCode());
});
res.send(productResults);
});
});
Basic but it works and it is the result of about 4 different sources.
ProductList_Load_Query
But to access it in the call it was
var request = new api.requests.ProductListLoadQuery(client);
The options list also has to be in a specific order. For example:
request.setFilters([{"Customer_ID":"int"}])
.setCount(100)
.setOffset(0)
Will work for the get orders endpoint but if I try to set Offset before Count it will not work. The following example is a product export. I'll leave the assignments for account specific values but remove the private data.
const express = require('express');
const router = express.Router();
const api = require('merchantapi');
const MyApiToken = '{your_api_token}';
const MySigningKey = '{your_signing_key}';
const algorithm = 'sha256';
const options = {
require_timestamps: true,
signing_key_digest: api.Client.SIGN_DIGEST_SHA256,
default_store_code: 'test',
Miva_Request_Timestamp : Math.floor(Date.now() / 1000)
}
const client = new api.Client( 'https://{your_url}/mm5/json.mvc', MyApiToken, MySigningKey, options );
/*
Product export route, requires no input parameters
*/
router.get('/productexport',(req,res)=>{
var request = new api.requests.ProductListLoadQuery(client);
request.setCount( 100 ); // how many records to load
request.setOffset( 0 ); // offset of records to load
request.setStoreCode( 'test' ); // you can optionally set the store code here if you did not pass default_store_code in the client options.
// apply filtering with the filter expression features:
var filters = request.filterExpression();
filters.isTrue( 'active' );
request.setFilters( filters );
request.send( function( error, response ){
if (error){
console.log(error);
return;
}
else if ( !response.isSuccess() ){
console.log('Load Products Error', response.getErrorCode(), response.getErrorMessage());
}
var productResults = response.getProducts();
//loop for testing not neccdessarily needed
response.getProducts().forEach((product)=>{
console.log(product.getCode());
});
res.send(productResults);
});
});
Basic but it works and it is the result of about 4 different sources.
Comment