I'm trying to get SyncCentric to work with a legacy Classic ASP site that is currently using Amzpecty.
Any help would be greatly appreciated! Thanks
The cURL request should be:
curl "https://app.synccentric.com/api/v3/products" \
-H "Authorization: Bearer your-api-token" \
-d "identifiers[0][identifier]=B00YECW5VM" \
-d "identifiers[0][type]=asin" \
-d "identifiers[1][identifier]=B00USV83JQ" \
-d "identifiers[1][type]=asin" \
-XPOST
The ASP code I was going to use is below, but I have no idea how to convert the cURL request into the data string:
Dim http: Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Dim url: url = "https://app.synccentric.com/api/v3/products"
Dim data: data = ""
With http
Call .Open("POST", url, False)
Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call .SetRequestHeader("Authorization", "My API key")
Call .Send(data)
End With
If Left(http.Status, 1) = 2 Then
'Request succeeded with a HTTP 2xx response, do something...
Else
'Output error
Call Response.Write("Server returned: " & http.Status & " " & http.StatusText)
End If
The clue is in the CURL man page, under the -d, --data <data>
section:
If any of these options is used more than once on the same command line, the data pieces specified will be merged with a separating &-symbol. Thus, using '-d name=daniel -d skill=lousy' would generate a post chunk that looks like 'name=daniel&skill=lousy'.
So you need to specify the key=value separated by an ampersand as you would with a raw HTTP POST.
Dim http: Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Dim url: url = "https://app.synccentric.com/api/v3/products"
Dim data: data = "identifiers[0][identifier]=B00YECW5VM&identifiers[0][type]=asin&identifiers[1][identifier]=B00USV83JQ&identifiers[1][type]=asin"
With http
Call .Open("POST", url, False)
Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call .SetRequestHeader("Authorization", "Bearer your-api-token")
Call .Send(data)
End With
If Left(http.Status, 1) = 2 Then
'Request succeeded with a HTTP 2xx response, do something...
Else
'Output error
Call Response.Write("Server returned: " & http.Status & " " & http.StatusText)
End If