Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
string ls_ConsumerId
string ls_BaseUrl
string ls_PrivateEncodedStr
string ls_HttpMethod
oleobject loo_Dt
integer li_BLocal
integer li_TimeStampVal
oleobject loo_SbStringToSign
oleobject loo_PrivKey
oleobject loo_Rsa
string ls_SignatureString

li_Success = 0

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

ls_ConsumerId = "b68d2a72...."
ls_BaseUrl = "https://marketplace.walmartapis.com/v2/feeds"
// This is your Base64 encoded private key
ls_PrivateEncodedStr = "MIICeAIBADANBgkqhkiG9w0BAQEFAA......"
ls_HttpMethod = "GET"

// We need a timestamp in decimal string form representing the number of milliseconds since Jan 01 1970 UTC.
loo_Dt = create oleobject
li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime")
if li_rc < 0 then
    destroy loo_Dt
    MessageBox("Error","Connecting to COM object failed")
    return
end if
// Set bLocal = 1 for a timestamp in the local timezone.  Set bLocal = 0 for a UTC timestamp.
li_BLocal = 0
// This gets the timestamp in seconds, not milliseconds.
li_TimeStampVal = loo_Dt.GetAsUnixTime(li_BLocal)

// Build the string to sign.
loo_SbStringToSign = create oleobject
li_rc = loo_SbStringToSign.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbStringToSign.Append(ls_ConsumerId)
loo_SbStringToSign.Append("~n")
loo_SbStringToSign.Append(ls_BaseUrl)
loo_SbStringToSign.Append("~n")
loo_SbStringToSign.Append(ls_HttpMethod)
loo_SbStringToSign.Append("~n")
loo_SbStringToSign.AppendInt(li_TimeStampVal)
// 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).
loo_SbStringToSign.Append("000~n")

loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")

// 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.
li_Success = loo_PrivKey.LoadPem(ls_PrivateEncodedStr)
if li_Success = 0 then
    Write-Debug loo_PrivKey.LastErrorText
    destroy loo_Dt
    destroy loo_SbStringToSign
    destroy loo_PrivKey
    return
end if

loo_Rsa = create oleobject
li_rc = loo_Rsa.ConnectToNewObject("Chilkat.Rsa")

li_Success = loo_Rsa.UsePrivateKey(loo_PrivKey)
if li_Success = 0 then
    Write-Debug loo_Rsa.LastErrorText
    destroy loo_Dt
    destroy loo_SbStringToSign
    destroy loo_PrivKey
    destroy loo_Rsa
    return
end if

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

ls_SignatureString = loo_Rsa.SignStringENC(loo_SbStringToSign.GetAsString(),"SHA256")
if loo_Rsa.LastMethodSuccess = 0 then
    Write-Debug loo_Rsa.LastErrorText
    destroy loo_Dt
    destroy loo_SbStringToSign
    destroy loo_PrivKey
    destroy loo_Rsa
    return
end if

Write-Debug "Signature String: " + ls_SignatureString


destroy loo_Dt
destroy loo_SbStringToSign
destroy loo_PrivKey
destroy loo_Rsa