セラーフォーラム
サインイン
サインイン
imgサインイン
imgサインイン
user profile
Seller_42K70JWMmzwhz

Trying to make a VBA SP-API Connection to replace AMTU - Private Application

I’m going to be frank, I don’t know what I’m doing but I’m hoping with a little help I can get there. I’ve been looking for a solution to the soon to be exiled AMTU application and decided to try to do it from scratch. I’ve been coding in VB and VBA since 1999 but I’ve only recently written a program to connect to a web API so my knowledge in this area is severely lacking.

I watched the whole Integrate with Amazon SP-API series and everything was going great until step 4B. In steps 1 to 3 I kind of felt a little like I was watching Dora the Explorer with the over explaining of each step multiple times. Then in step 4b they seem to jump through a series of authentication steps without a whole lot of explanation on any of it.

At any rate, here is what I have so far. It works as far as connecting to AP-SPI and retrieving the refresh token. I’m not sure what to do next. I believe I have to connect to AWS-STS to get the signed request using their encryption service or something… again, first time doing anything like this, I used to Username / Password and go!


Private Sub cmdamazonspapi_Click()

Dim rs As dao.Recordset
Dim db As dao.Database
Dim WinHttp As New WinHttpRequest
Dim BodyStr As String
Dim refreshtoken As String
Dim clientid As String
Dim clientsecret As String
Dim expiredate As Date
Dim xamzdate As String

'Return Access token variables
Dim accesstoken As String
Dim tokentype As String
Dim expiresin As String

'API URI Variables
Dim apiuri As String

Set db = CurrentDb
Set rs = db.OpenRecordset(“select refreshtoken, clientid, clientsecret, accesstoken, expiredate from SPAPI”)
If rs.RecordCount = 0 Then Exit Sub

'Step 1 - Request Login with Amazon Access Token

'See if refresh token is still valid
refreshtoken = rs.Fields(“refreshtoken”)
clientid = rs.Fields(“clientid”)
clientsecret = rs.Fields(“clientsecret”)
If IsNull(rs.Fields(“accesstoken”)) Then Else accesstoken = rs.Fields(“accesstoken”)
If IsNull(rs.Fields(“expiredate”)) Then Else expiredate = rs.Fields(“expiredate”)

If DateDiff(“s”, Date & " " & Time, expiredate) > 0 Then
Debug.Print “Token still valid!”
Else 'If refresh token is not valid - get a new one!
'Our token has expired so get a new one!
BodyStr = “{” & Chr(34) & “grant_type” & Chr(34) & “:” & Chr(34) & “refresh_token” & Chr(34) & “,” & Chr(34) & “refresh_token” & Chr(34) & “:” & Chr(34) & refreshtoken & Chr(34) & “,” & Chr(34) & “client_id” & Chr(34) & “:” & Chr(34) & clientid & Chr(34) & “,”“client_secret”":" & Chr(34) & clientsecret & Chr(34) & “}”

'Debug.Print BodyStr

WinHttp.Open "POST", "https://api.amazon.com/auth/o2/token", False
WinHttp.SetRequestHeader "Content-Type", "application/json;charset=UTF-8"
WinHttp.Send BodyStr
'Debug.Print WinHttp.ResponseText
'Debug.Print WinHttp.Status

Dim dic As Object
Set dic = ParseJSON(WinHttp.ResponseText)
accesstoken = dic("obj.access_token")
If refreshtoken = dic("obj.refresh_token") Then
    'Token matches - there would be serious weirdness if it did not
Else
    MsgBox "Refresh Token mismatch!", vbOKOnly, "Token mismatch!"
End If
tokentype = dic("obj.token_type")
expiresin = dic("obj.expires_in")
expiredate = DateAdd("s", expiresin, Date & " " & Time)
CurrentDb.Execute "UPDATE SPAPI set accesstoken = '" & accesstoken & "', expiredate = #" & expiredate & "#"

End If

'Step 2 - Construct a Selling Partner API URI and connect to AWS-STS -

End Sub


Right now it’s all coded under a button on my form. Oh and I use the VBA-JSON-PARSER module added in to my project, the person that coded that is truly a wizard. What I hope to accomplish is to be able to connect and update my inventory price and quantity. That’s it, that’s all I used AMTU for anything above and beyond that is just icing on the cake.

Any help would be greatly appreciated!

13件の閲覧
9件の返信
タグ:在庫
00
返信
user profile
Seller_42K70JWMmzwhz

Trying to make a VBA SP-API Connection to replace AMTU - Private Application

I’m going to be frank, I don’t know what I’m doing but I’m hoping with a little help I can get there. I’ve been looking for a solution to the soon to be exiled AMTU application and decided to try to do it from scratch. I’ve been coding in VB and VBA since 1999 but I’ve only recently written a program to connect to a web API so my knowledge in this area is severely lacking.

I watched the whole Integrate with Amazon SP-API series and everything was going great until step 4B. In steps 1 to 3 I kind of felt a little like I was watching Dora the Explorer with the over explaining of each step multiple times. Then in step 4b they seem to jump through a series of authentication steps without a whole lot of explanation on any of it.

At any rate, here is what I have so far. It works as far as connecting to AP-SPI and retrieving the refresh token. I’m not sure what to do next. I believe I have to connect to AWS-STS to get the signed request using their encryption service or something… again, first time doing anything like this, I used to Username / Password and go!


Private Sub cmdamazonspapi_Click()

Dim rs As dao.Recordset
Dim db As dao.Database
Dim WinHttp As New WinHttpRequest
Dim BodyStr As String
Dim refreshtoken As String
Dim clientid As String
Dim clientsecret As String
Dim expiredate As Date
Dim xamzdate As String

'Return Access token variables
Dim accesstoken As String
Dim tokentype As String
Dim expiresin As String

'API URI Variables
Dim apiuri As String

Set db = CurrentDb
Set rs = db.OpenRecordset(“select refreshtoken, clientid, clientsecret, accesstoken, expiredate from SPAPI”)
If rs.RecordCount = 0 Then Exit Sub

'Step 1 - Request Login with Amazon Access Token

'See if refresh token is still valid
refreshtoken = rs.Fields(“refreshtoken”)
clientid = rs.Fields(“clientid”)
clientsecret = rs.Fields(“clientsecret”)
If IsNull(rs.Fields(“accesstoken”)) Then Else accesstoken = rs.Fields(“accesstoken”)
If IsNull(rs.Fields(“expiredate”)) Then Else expiredate = rs.Fields(“expiredate”)

If DateDiff(“s”, Date & " " & Time, expiredate) > 0 Then
Debug.Print “Token still valid!”
Else 'If refresh token is not valid - get a new one!
'Our token has expired so get a new one!
BodyStr = “{” & Chr(34) & “grant_type” & Chr(34) & “:” & Chr(34) & “refresh_token” & Chr(34) & “,” & Chr(34) & “refresh_token” & Chr(34) & “:” & Chr(34) & refreshtoken & Chr(34) & “,” & Chr(34) & “client_id” & Chr(34) & “:” & Chr(34) & clientid & Chr(34) & “,”“client_secret”":" & Chr(34) & clientsecret & Chr(34) & “}”

'Debug.Print BodyStr

WinHttp.Open "POST", "https://api.amazon.com/auth/o2/token", False
WinHttp.SetRequestHeader "Content-Type", "application/json;charset=UTF-8"
WinHttp.Send BodyStr
'Debug.Print WinHttp.ResponseText
'Debug.Print WinHttp.Status

Dim dic As Object
Set dic = ParseJSON(WinHttp.ResponseText)
accesstoken = dic("obj.access_token")
If refreshtoken = dic("obj.refresh_token") Then
    'Token matches - there would be serious weirdness if it did not
Else
    MsgBox "Refresh Token mismatch!", vbOKOnly, "Token mismatch!"
End If
tokentype = dic("obj.token_type")
expiresin = dic("obj.expires_in")
expiredate = DateAdd("s", expiresin, Date & " " & Time)
CurrentDb.Execute "UPDATE SPAPI set accesstoken = '" & accesstoken & "', expiredate = #" & expiredate & "#"

End If

'Step 2 - Construct a Selling Partner API URI and connect to AWS-STS -

End Sub


Right now it’s all coded under a button on my form. Oh and I use the VBA-JSON-PARSER module added in to my project, the person that coded that is truly a wizard. What I hope to accomplish is to be able to connect and update my inventory price and quantity. That’s it, that’s all I used AMTU for anything above and beyond that is just icing on the cake.

Any help would be greatly appreciated!

タグ:在庫
00
13件の閲覧
9件の返信
返信
0件の返信
user profile
Seller_fsNHBXJZNVJpE

you might want to seek help in a forum for CODERS not the Amazon seller forum!

00
user profile
Seller_Nx5bUHme6tcMS

I can tell you that there is very little out there to help a VB/VBA coder on this sort of project. I’ve been tinkering with it, but not sure if I will go forward or not. May just try to put something together with Veeqo.

For the OP, have you got SP-API credentials? You definitely want to code everything to use the sandbox until you have it working perfectly, meaning all code should point to the sandbox URL, not the live URL. I would also recommend looking at ADO instead of DAO. I switched many years ago and have always been glad.

This project is non-trivial, and I keep hoping Amazon or a third-party will make an AMTU replacement, not one of the thousands that are aimed at pricing, or buying shipping (like Veeqo is). So far, nothing on the horizon.

FWIW, I was a Microsoft MVP for VB back in the dark ages.

10
このディスカッションをフォローして、新しいアクティビティの通知を受け取りましょう
user profile
Seller_42K70JWMmzwhz

Trying to make a VBA SP-API Connection to replace AMTU - Private Application

I’m going to be frank, I don’t know what I’m doing but I’m hoping with a little help I can get there. I’ve been looking for a solution to the soon to be exiled AMTU application and decided to try to do it from scratch. I’ve been coding in VB and VBA since 1999 but I’ve only recently written a program to connect to a web API so my knowledge in this area is severely lacking.

I watched the whole Integrate with Amazon SP-API series and everything was going great until step 4B. In steps 1 to 3 I kind of felt a little like I was watching Dora the Explorer with the over explaining of each step multiple times. Then in step 4b they seem to jump through a series of authentication steps without a whole lot of explanation on any of it.

At any rate, here is what I have so far. It works as far as connecting to AP-SPI and retrieving the refresh token. I’m not sure what to do next. I believe I have to connect to AWS-STS to get the signed request using their encryption service or something… again, first time doing anything like this, I used to Username / Password and go!


Private Sub cmdamazonspapi_Click()

Dim rs As dao.Recordset
Dim db As dao.Database
Dim WinHttp As New WinHttpRequest
Dim BodyStr As String
Dim refreshtoken As String
Dim clientid As String
Dim clientsecret As String
Dim expiredate As Date
Dim xamzdate As String

'Return Access token variables
Dim accesstoken As String
Dim tokentype As String
Dim expiresin As String

'API URI Variables
Dim apiuri As String

Set db = CurrentDb
Set rs = db.OpenRecordset(“select refreshtoken, clientid, clientsecret, accesstoken, expiredate from SPAPI”)
If rs.RecordCount = 0 Then Exit Sub

'Step 1 - Request Login with Amazon Access Token

'See if refresh token is still valid
refreshtoken = rs.Fields(“refreshtoken”)
clientid = rs.Fields(“clientid”)
clientsecret = rs.Fields(“clientsecret”)
If IsNull(rs.Fields(“accesstoken”)) Then Else accesstoken = rs.Fields(“accesstoken”)
If IsNull(rs.Fields(“expiredate”)) Then Else expiredate = rs.Fields(“expiredate”)

If DateDiff(“s”, Date & " " & Time, expiredate) > 0 Then
Debug.Print “Token still valid!”
Else 'If refresh token is not valid - get a new one!
'Our token has expired so get a new one!
BodyStr = “{” & Chr(34) & “grant_type” & Chr(34) & “:” & Chr(34) & “refresh_token” & Chr(34) & “,” & Chr(34) & “refresh_token” & Chr(34) & “:” & Chr(34) & refreshtoken & Chr(34) & “,” & Chr(34) & “client_id” & Chr(34) & “:” & Chr(34) & clientid & Chr(34) & “,”“client_secret”":" & Chr(34) & clientsecret & Chr(34) & “}”

'Debug.Print BodyStr

WinHttp.Open "POST", "https://api.amazon.com/auth/o2/token", False
WinHttp.SetRequestHeader "Content-Type", "application/json;charset=UTF-8"
WinHttp.Send BodyStr
'Debug.Print WinHttp.ResponseText
'Debug.Print WinHttp.Status

Dim dic As Object
Set dic = ParseJSON(WinHttp.ResponseText)
accesstoken = dic("obj.access_token")
If refreshtoken = dic("obj.refresh_token") Then
    'Token matches - there would be serious weirdness if it did not
Else
    MsgBox "Refresh Token mismatch!", vbOKOnly, "Token mismatch!"
End If
tokentype = dic("obj.token_type")
expiresin = dic("obj.expires_in")
expiredate = DateAdd("s", expiresin, Date & " " & Time)
CurrentDb.Execute "UPDATE SPAPI set accesstoken = '" & accesstoken & "', expiredate = #" & expiredate & "#"

End If

'Step 2 - Construct a Selling Partner API URI and connect to AWS-STS -

End Sub


Right now it’s all coded under a button on my form. Oh and I use the VBA-JSON-PARSER module added in to my project, the person that coded that is truly a wizard. What I hope to accomplish is to be able to connect and update my inventory price and quantity. That’s it, that’s all I used AMTU for anything above and beyond that is just icing on the cake.

Any help would be greatly appreciated!

13件の閲覧
9件の返信
タグ:在庫
00
返信
user profile
Seller_42K70JWMmzwhz

Trying to make a VBA SP-API Connection to replace AMTU - Private Application

I’m going to be frank, I don’t know what I’m doing but I’m hoping with a little help I can get there. I’ve been looking for a solution to the soon to be exiled AMTU application and decided to try to do it from scratch. I’ve been coding in VB and VBA since 1999 but I’ve only recently written a program to connect to a web API so my knowledge in this area is severely lacking.

I watched the whole Integrate with Amazon SP-API series and everything was going great until step 4B. In steps 1 to 3 I kind of felt a little like I was watching Dora the Explorer with the over explaining of each step multiple times. Then in step 4b they seem to jump through a series of authentication steps without a whole lot of explanation on any of it.

At any rate, here is what I have so far. It works as far as connecting to AP-SPI and retrieving the refresh token. I’m not sure what to do next. I believe I have to connect to AWS-STS to get the signed request using their encryption service or something… again, first time doing anything like this, I used to Username / Password and go!


Private Sub cmdamazonspapi_Click()

Dim rs As dao.Recordset
Dim db As dao.Database
Dim WinHttp As New WinHttpRequest
Dim BodyStr As String
Dim refreshtoken As String
Dim clientid As String
Dim clientsecret As String
Dim expiredate As Date
Dim xamzdate As String

'Return Access token variables
Dim accesstoken As String
Dim tokentype As String
Dim expiresin As String

'API URI Variables
Dim apiuri As String

Set db = CurrentDb
Set rs = db.OpenRecordset(“select refreshtoken, clientid, clientsecret, accesstoken, expiredate from SPAPI”)
If rs.RecordCount = 0 Then Exit Sub

'Step 1 - Request Login with Amazon Access Token

'See if refresh token is still valid
refreshtoken = rs.Fields(“refreshtoken”)
clientid = rs.Fields(“clientid”)
clientsecret = rs.Fields(“clientsecret”)
If IsNull(rs.Fields(“accesstoken”)) Then Else accesstoken = rs.Fields(“accesstoken”)
If IsNull(rs.Fields(“expiredate”)) Then Else expiredate = rs.Fields(“expiredate”)

If DateDiff(“s”, Date & " " & Time, expiredate) > 0 Then
Debug.Print “Token still valid!”
Else 'If refresh token is not valid - get a new one!
'Our token has expired so get a new one!
BodyStr = “{” & Chr(34) & “grant_type” & Chr(34) & “:” & Chr(34) & “refresh_token” & Chr(34) & “,” & Chr(34) & “refresh_token” & Chr(34) & “:” & Chr(34) & refreshtoken & Chr(34) & “,” & Chr(34) & “client_id” & Chr(34) & “:” & Chr(34) & clientid & Chr(34) & “,”“client_secret”":" & Chr(34) & clientsecret & Chr(34) & “}”

'Debug.Print BodyStr

WinHttp.Open "POST", "https://api.amazon.com/auth/o2/token", False
WinHttp.SetRequestHeader "Content-Type", "application/json;charset=UTF-8"
WinHttp.Send BodyStr
'Debug.Print WinHttp.ResponseText
'Debug.Print WinHttp.Status

Dim dic As Object
Set dic = ParseJSON(WinHttp.ResponseText)
accesstoken = dic("obj.access_token")
If refreshtoken = dic("obj.refresh_token") Then
    'Token matches - there would be serious weirdness if it did not
Else
    MsgBox "Refresh Token mismatch!", vbOKOnly, "Token mismatch!"
End If
tokentype = dic("obj.token_type")
expiresin = dic("obj.expires_in")
expiredate = DateAdd("s", expiresin, Date & " " & Time)
CurrentDb.Execute "UPDATE SPAPI set accesstoken = '" & accesstoken & "', expiredate = #" & expiredate & "#"

End If

'Step 2 - Construct a Selling Partner API URI and connect to AWS-STS -

End Sub


Right now it’s all coded under a button on my form. Oh and I use the VBA-JSON-PARSER module added in to my project, the person that coded that is truly a wizard. What I hope to accomplish is to be able to connect and update my inventory price and quantity. That’s it, that’s all I used AMTU for anything above and beyond that is just icing on the cake.

Any help would be greatly appreciated!

タグ:在庫
00
13件の閲覧
9件の返信
返信
user profile

Trying to make a VBA SP-API Connection to replace AMTU - Private Application

投稿者:Seller_42K70JWMmzwhz

I’m going to be frank, I don’t know what I’m doing but I’m hoping with a little help I can get there. I’ve been looking for a solution to the soon to be exiled AMTU application and decided to try to do it from scratch. I’ve been coding in VB and VBA since 1999 but I’ve only recently written a program to connect to a web API so my knowledge in this area is severely lacking.

I watched the whole Integrate with Amazon SP-API series and everything was going great until step 4B. In steps 1 to 3 I kind of felt a little like I was watching Dora the Explorer with the over explaining of each step multiple times. Then in step 4b they seem to jump through a series of authentication steps without a whole lot of explanation on any of it.

At any rate, here is what I have so far. It works as far as connecting to AP-SPI and retrieving the refresh token. I’m not sure what to do next. I believe I have to connect to AWS-STS to get the signed request using their encryption service or something… again, first time doing anything like this, I used to Username / Password and go!


Private Sub cmdamazonspapi_Click()

Dim rs As dao.Recordset
Dim db As dao.Database
Dim WinHttp As New WinHttpRequest
Dim BodyStr As String
Dim refreshtoken As String
Dim clientid As String
Dim clientsecret As String
Dim expiredate As Date
Dim xamzdate As String

'Return Access token variables
Dim accesstoken As String
Dim tokentype As String
Dim expiresin As String

'API URI Variables
Dim apiuri As String

Set db = CurrentDb
Set rs = db.OpenRecordset(“select refreshtoken, clientid, clientsecret, accesstoken, expiredate from SPAPI”)
If rs.RecordCount = 0 Then Exit Sub

'Step 1 - Request Login with Amazon Access Token

'See if refresh token is still valid
refreshtoken = rs.Fields(“refreshtoken”)
clientid = rs.Fields(“clientid”)
clientsecret = rs.Fields(“clientsecret”)
If IsNull(rs.Fields(“accesstoken”)) Then Else accesstoken = rs.Fields(“accesstoken”)
If IsNull(rs.Fields(“expiredate”)) Then Else expiredate = rs.Fields(“expiredate”)

If DateDiff(“s”, Date & " " & Time, expiredate) > 0 Then
Debug.Print “Token still valid!”
Else 'If refresh token is not valid - get a new one!
'Our token has expired so get a new one!
BodyStr = “{” & Chr(34) & “grant_type” & Chr(34) & “:” & Chr(34) & “refresh_token” & Chr(34) & “,” & Chr(34) & “refresh_token” & Chr(34) & “:” & Chr(34) & refreshtoken & Chr(34) & “,” & Chr(34) & “client_id” & Chr(34) & “:” & Chr(34) & clientid & Chr(34) & “,”“client_secret”":" & Chr(34) & clientsecret & Chr(34) & “}”

'Debug.Print BodyStr

WinHttp.Open "POST", "https://api.amazon.com/auth/o2/token", False
WinHttp.SetRequestHeader "Content-Type", "application/json;charset=UTF-8"
WinHttp.Send BodyStr
'Debug.Print WinHttp.ResponseText
'Debug.Print WinHttp.Status

Dim dic As Object
Set dic = ParseJSON(WinHttp.ResponseText)
accesstoken = dic("obj.access_token")
If refreshtoken = dic("obj.refresh_token") Then
    'Token matches - there would be serious weirdness if it did not
Else
    MsgBox "Refresh Token mismatch!", vbOKOnly, "Token mismatch!"
End If
tokentype = dic("obj.token_type")
expiresin = dic("obj.expires_in")
expiredate = DateAdd("s", expiresin, Date & " " & Time)
CurrentDb.Execute "UPDATE SPAPI set accesstoken = '" & accesstoken & "', expiredate = #" & expiredate & "#"

End If

'Step 2 - Construct a Selling Partner API URI and connect to AWS-STS -

End Sub


Right now it’s all coded under a button on my form. Oh and I use the VBA-JSON-PARSER module added in to my project, the person that coded that is truly a wizard. What I hope to accomplish is to be able to connect and update my inventory price and quantity. That’s it, that’s all I used AMTU for anything above and beyond that is just icing on the cake.

Any help would be greatly appreciated!

タグ:在庫
00
13件の閲覧
9件の返信
返信
0件の返信
0件の返信
クイックフィルター
並べ替え
user profile
Seller_fsNHBXJZNVJpE

you might want to seek help in a forum for CODERS not the Amazon seller forum!

00
user profile
Seller_Nx5bUHme6tcMS

I can tell you that there is very little out there to help a VB/VBA coder on this sort of project. I’ve been tinkering with it, but not sure if I will go forward or not. May just try to put something together with Veeqo.

For the OP, have you got SP-API credentials? You definitely want to code everything to use the sandbox until you have it working perfectly, meaning all code should point to the sandbox URL, not the live URL. I would also recommend looking at ADO instead of DAO. I switched many years ago and have always been glad.

This project is non-trivial, and I keep hoping Amazon or a third-party will make an AMTU replacement, not one of the thousands that are aimed at pricing, or buying shipping (like Veeqo is). So far, nothing on the horizon.

FWIW, I was a Microsoft MVP for VB back in the dark ages.

10
このディスカッションをフォローして、新しいアクティビティの通知を受け取りましょう
user profile
Seller_fsNHBXJZNVJpE

you might want to seek help in a forum for CODERS not the Amazon seller forum!

00
user profile
Seller_fsNHBXJZNVJpE

you might want to seek help in a forum for CODERS not the Amazon seller forum!

00
返信
user profile
Seller_Nx5bUHme6tcMS

I can tell you that there is very little out there to help a VB/VBA coder on this sort of project. I’ve been tinkering with it, but not sure if I will go forward or not. May just try to put something together with Veeqo.

For the OP, have you got SP-API credentials? You definitely want to code everything to use the sandbox until you have it working perfectly, meaning all code should point to the sandbox URL, not the live URL. I would also recommend looking at ADO instead of DAO. I switched many years ago and have always been glad.

This project is non-trivial, and I keep hoping Amazon or a third-party will make an AMTU replacement, not one of the thousands that are aimed at pricing, or buying shipping (like Veeqo is). So far, nothing on the horizon.

FWIW, I was a Microsoft MVP for VB back in the dark ages.

10
user profile
Seller_Nx5bUHme6tcMS

I can tell you that there is very little out there to help a VB/VBA coder on this sort of project. I’ve been tinkering with it, but not sure if I will go forward or not. May just try to put something together with Veeqo.

For the OP, have you got SP-API credentials? You definitely want to code everything to use the sandbox until you have it working perfectly, meaning all code should point to the sandbox URL, not the live URL. I would also recommend looking at ADO instead of DAO. I switched many years ago and have always been glad.

This project is non-trivial, and I keep hoping Amazon or a third-party will make an AMTU replacement, not one of the thousands that are aimed at pricing, or buying shipping (like Veeqo is). So far, nothing on the horizon.

FWIW, I was a Microsoft MVP for VB back in the dark ages.

10
返信
このディスカッションをフォローして、新しいアクティビティの通知を受け取りましょう