Skip to content

Instantly share code, notes, and snippets.

@gmjelle
Last active September 15, 2024 16:23
Show Gist options
  • Save gmjelle/2a5b2dd08fb1af722490e79fcc81995b to your computer and use it in GitHub Desktop.
Save gmjelle/2a5b2dd08fb1af722490e79fcc81995b to your computer and use it in GitHub Desktop.

How to make an API request to the Walmart I/O Affiliate API

This gist shows your how to prepare a request to the Walmart I/O Affiliate API, including how to sign your request with the private key you generated.

For more info, check out the accompanying blogpost: vandevliet.me/guide-how-to-use-the-walmart-affiliate-api-with-nodejs/

Waltrack API Proxy

Still having trouble calling the WalmartIO API? Or you are looking for a simpler way to call the API, without having to use a Private Key for signing?

Check out the Waltrack API Proxy: https://waltrack.net/byok

Waltrack allows you to

  • Create a unique key pair for you to use. So you don't have to mess with SSH keys
  • Call our API as a proxy with only an API key, no key signing required
  • Call any endpoint - simply pass the endpoint of the API you want call as a query param, and you're done.
  • The Proxy is 100% transparent, you will get the status code and response back that the WalmartIO api returned.

This means you can call the WalmartIO api from anywhere with a simple API key in the url.

import NodeRSA from "node-rsa";
const keyData = {
consumerId: "CONSUMER_ID",
privateKey: `-----BEGIN RSA PRIVATE KEY-----
MY PRIVATE KEY
-----END RSA PRIVATE KEY-----`,
keyVer: 1,
impactId: "YOUR IMPACT AFFILIATE ID" // not required
},
const generateWalmartHeaders = () => {
const { privateKey, consumerId, keyVer } = keyData;
const hashList = {
"WM_CONSUMER.ID": consumerId,
"WM_CONSUMER.INTIMESTAMP": Date.now().toString(),
"WM_SEC.KEY_VERSION": keyVer,
};
const sortedHashString = `${hashList["WM_CONSUMER.ID"]}\n${hashList["WM_CONSUMER.INTIMESTAMP"]}\n${hashList["WM_SEC.KEY_VERSION"]}\n`;
const signer = new NodeRSA(privateKey, "pkcs1");
const signature = signer.sign(sortedHashString);
const signature_enc = signature.toString("base64");
return {
"WM_SEC.AUTH_SIGNATURE": signature_enc,
"WM_CONSUMER.INTIMESTAMP": hashList["WM_CONSUMER.INTIMESTAMP"],
"WM_CONSUMER.ID": hashList["WM_CONSUMER.ID"],
"WM_SEC.KEY_VERSION": hashList["WM_SEC.KEY_VERSION"],
};
};
export const getProductById = async (productId) => {
const options = {
method: "GET",
headers: generateWalmartHeaders(),
};
const res = await fetch(
`https://developer.api.walmart.com/api-proxy/service/affil/product/v2/items/${productId}?publisherId=${keyData.impactId}`,
options
);
return await res.json()
};
@dosstx
Copy link

dosstx commented May 3, 2022

I tried to use this but Im getting a weird error :
Error: error:25078067:DSO support routines:win32_load:could not load the shared library

Ever seen this error? More details about my issue: https://stackoverflow.com/questions/72100029/node-rsa-and-firebase-function-why-the-error-dso-support-routineswin32-load

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment