No announcement yet.

Node API Sample with HMAC and Timestamp

  • Filter
  • Time
  • Show
Clear All
new posts

  • Node API Sample with HMAC and Timestamp

    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:


    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:


    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( / 1000)
    const client = new api.Client( 'https://{your_url}/mm5/json.mvc', MyApiToken, MySigningKey, options );
    Product export route, requires no input parameters
    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){
    else if ( !response.isSuccess() ){
    console.log('Load Products Error', response.getErrorCode(), response.getErrorMessage());
    var productResults = response.getProducts();
    //loop for testing not neccdessarily needed

    Basic but it works and it is the result of about 4 different sources.

  • We also have examples up on github

    Have you looked though these yet?
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]


    • I have tried the Nodejs SDK and PHP SDK they don't work.
      The issue is returning simple HTML Admin login page instead of JSON response.
      SDK shows an error: Error Decoding JSON: Syntax error

      Can you check this issue?

      The PHP code:

      require_once __DIR__ . '/vendor/autoload.php';

      use MerchantAPI\Client;
      use MerchantAPI\ClientException;
      use MerchantAPI\Request\ProductListLoadQuery;
      use MerchantAPI\Request\ProductImageAdd;

      $config = json_decode(file_get_contents(__DIR__ . '/config.json'));

      $client = new Client(
      'require_timestamp' => true,
      'signing_key_digest' => Client::SIGN_DIGEST_SHA256,
      'default_store_code' => 'MYSTORE',
      'curl_options' => []

      $reqProductList = new ProductListLoadQuery;
      $reqProductList->filterExpression()->equal('code', 'SOMEPROD')

      try {
      $resProductList = $client->send($reqProductList);
      } catch (ClientException $e) {
      printf("Error: %s\n", $e->getMessage());


      • The code looks correct. What value are you providing for the endpoint url?



        This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

        This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.