Amazon's Selling Partner API (SP-API) ...a long shot, but has anyone managed to sign such API calls? (1 Viewer)

peskywinnets

Registered User.
Local time
Today, 02:24
Joined
Feb 4, 2014
Messages
576
I realise this is pretty niche, and I realise there aren't likely to be anyone on here that has...but hey, worth a shot.

Amazon have an API that is a head trip to understand the signing stages (if you wish to suffer from Brain fog, you can read about how they say it should be signed here... https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html)

...none of the steps are particular onerous (and I already have one of their other APIs running...albeit I used a lot of pre-made code!), but it's just not clear which part of the overall request gets signed...I was hoping someone might have gone through this pain....I must have read it 50 times, I'm none the wiser!

They've provided a detailed example of the process using Python (but I'm not Python literate) ...in essence if you're using VBA - you're on your own...

....Section headed "Using GET with an authorization header (Python)")

Can anyone suggest a basic simple lightweight Python IDE, which will then allow me to step through the supplied Python code ...I reckon if I can step through with the Python equivalent of debug.print I should be able to work out what's going on :D!
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:24
Joined
Oct 29, 2018
Messages
21,358
Hi. Just letting you know, I did successfully manage to work with the Amazon API. But as you said, it took a lot of reading and analyzing examples before I figured it out.
 

peskywinnets

Registered User.
Local time
Today, 02:24
Joined
Feb 4, 2014
Messages
576
Hi. Just letting you know, I did successfully manage to work with the Amazon API. But as you said, it took a lot of reading and analyzing examples before I figured it out.
They certainly don't make things easy.

I hadn't actually realised how similar Python is to VBA (their Python code extract)....

Code:
method = 'GET'
service = 'ec2'
host = 'ec2.amazonaws.com'
region = 'us-east-1'
endpoint = 'https://ec2.amazonaws.com'
request_parameters = 'Action=DescribeRegions&Version=2013-10-15'

# Key derivation functions. See:
# http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-python
def sign(key, msg):
    return hmac.new(key, msg.encode('utf-8'), hashlib.sha256).digest()

def getSignatureKey(key, dateStamp, regionName, serviceName):
    kDate = sign(('AWS4' + key).encode('utf-8'), dateStamp)
    kRegion = sign(kDate, regionName)
    kService = sign(kRegion, serviceName)
    kSigning = sign(kService, 'aws4_request')
    return kSigning

....there's a fair degree of similarity in the syntax there ...I'm kinda hoping that's a sort of 'Rosetta Stone' moment as it shows how the signing is done stage by stage ...just got to spend a little bit of time now familiarising myself with basic python
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:24
Joined
Oct 29, 2018
Messages
21,358
They certainly don't make things easy.

I hadn't actually realised how similar Python is to VBA (their Python code extract)....

Code:
method = 'GET'
service = 'ec2'
host = 'ec2.amazonaws.com'
region = 'us-east-1'
endpoint = 'https://ec2.amazonaws.com'
request_parameters = 'Action=DescribeRegions&Version=2013-10-15'

# Key derivation functions. See:
# http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-python
def sign(key, msg):
    return hmac.new(key, msg.encode('utf-8'), hashlib.sha256).digest()

def getSignatureKey(key, dateStamp, regionName, serviceName):
    kDate = sign(('AWS4' + key).encode('utf-8'), dateStamp)
    kRegion = sign(kDate, regionName)
    kService = sign(kRegion, serviceName)
    kSigning = sign(kService, 'aws4_request')
    return kSigning

....there's a fair degree of similarity in the syntax there ...I'm kinda hoping that's a sort of 'Rosetta Stone' moment as it shows how the signing is done stage by stage ...just got to spend a little bit of time now familiarising myself with basic python
Hi. Good luck!
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:24
Joined
Jul 9, 2003
Messages
16,245
In my early days as an MS Access programmer, I recall being reprimanded by a more, shall we say, senior member for suggesting that I could use VB6 and vb.net code in MS Access.

My comment was taken out of context because I probably didn't write it very clearly, but I suspect it's along the same lines as you demonstrate here, you are looking at Python code to get some indication as to how to handle the problem you have with this API in VBA.

I would also suggest looking to see if there are any vb.net or vb6 examples.
 

peskywinnets

Registered User.
Local time
Today, 02:24
Joined
Feb 4, 2014
Messages
576
I would also suggest looking to see if there are any vb.net or vb6 examples.
that was a great tip!

It transpires some kind soul has posted a working solution in vb.net - The author (stackflow user2728841) said "Here's a complete VB.NET console application that successfully connects to AWS." - connecting to AWS (Amazon's API Server) is exactly what I need :), his full code is at the foot of this page...


Now I know zilch about vb.net, so I downloaded Visual Studio & created a 'console application project' ...I'm stepping through his code but I have a question, about this part...

Code:
Dim dateKey() As Byte = HmacSha256(Encoding.UTF8.GetBytes("AWS4" & secretkey), amzShortDate)

The bit Encoding.UTF8.GetBytes() ...does anyone know if these would there be a similar function in VBA? I have no clue what is going on there!
 
Last edited:

Users who are viewing this thread

Top Bottom