Sample code for 30+ languages & platforms
Lianja Requires Chilkat v11.0.0+

Walmart Partner API Authentication (Generate a Signature for a Request)

See more RSA Examples

Demonstrates how to generate a signature for a Walmart Partner REST API call.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

lcConsumerId = "b68d2a72...."
lcBaseUrl = "https://marketplace.walmartapis.com/v2/feeds"
//  This is your Base64 encoded private key
lcPrivateEncodedStr = "MIICeAIBADANBgkqhkiG9w0BAQEFAA......"
lcHttpMethod = "GET"

//  We need a timestamp in decimal string form representing the number of milliseconds since Jan 01 1970 UTC.
loDt = createobject("CkDateTime")
//  Set bLocal = .T. for a timestamp in the local timezone.  Set bLocal = .F. for a UTC timestamp.
llBLocal = .F.
//  This gets the timestamp in seconds, not milliseconds.
lnTimeStampVal = loDt.GetAsUnixTime(llBLocal)

//  Build the string to sign.
loSbStringToSign = createobject("CkStringBuilder")
loSbStringToSign.Append(lcConsumerId)
loSbStringToSign.Append(Chr(10))
loSbStringToSign.Append(lcBaseUrl)
loSbStringToSign.Append(Chr(10))
loSbStringToSign.Append(lcHttpMethod)
loSbStringToSign.Append(Chr(10))
loSbStringToSign.AppendInt(lnTimeStampVal)
//  We add three zero's so that the timestamp value is in milliseconds.
//  We don't care about accuracy down to less than a second.
//  All the server cares about is that the request was signed at the current date/time
//  within some reasonable margin of error (to account for systems having clocks
//  that may be slightly different).
loSbStringToSign.Append("000" + Chr(10))

loPrivKey = createobject("CkPrivateKey")
//  Load the private key into a private key object.
//  Note: Technically the private key is not PEM because it lacks the header/footer strings
//  used for PEM.  However, the LoadPem method will still accept it and load it correctly.
llSuccess = loPrivKey.LoadPem(lcPrivateEncodedStr)
if (llSuccess = .F.) then
    ? loPrivKey.LastErrorText
    release loDt
    release loSbStringToSign
    release loPrivKey
    return
endif

loRsa = createobject("CkRsa")
llSuccess = loRsa.UsePrivateKey(loPrivKey)
if (llSuccess = .F.) then
    ? loRsa.LastErrorText
    release loDt
    release loSbStringToSign
    release loPrivKey
    release loRsa
    return
endif

//  We want a base64 signature string.
loRsa.EncodingMode = "base64"

lcSignatureString = loRsa.SignStringENC(loSbStringToSign.GetAsString(),"SHA256")
if (loRsa.LastMethodSuccess = .F.) then
    ? loRsa.LastErrorText
    release loDt
    release loSbStringToSign
    release loPrivKey
    release loRsa
    return
endif

? "Signature String: " + lcSignatureString


release loDt
release loSbStringToSign
release loPrivKey
release loRsa