asked on
EncodedShipStationID = EncodeBase64(ShipStationAppID)
' ShipStation api call...
'##############################################################
sContactURL = "https://ssapi.shipstation.com/orders?ordernumber=1168501&orderStatus=awaiting_shipment"
'"orderNumber":"1168501","
Call xmlHttp2.open("GET", sContactURL, False)
xmlHttp2.setRequestHeader("Authorization:", " Basic " + EncodedShipStationID) 'MsgBox("Here 1 in FindItemsByProduct")
Call xmlHttp2.send()
'Get the server's response
sResponse = xmlHttp2.responseText
sResponse = Trim(sResponse)
'Save the response from shipstation for later evaluation if needed
RtnVal = VarStringToTextFile(TempDataStorageFolder + "\ShipStationOrderResponse1.xml", sResponse)
' Now parse out Item Data using JSON parser
Dim intI As Integer
Dim json As String = sResponse.ToString
Dim jsonObject As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.Linq.JObject.Parse(json)
Dim jsonArray As Newtonsoft.Json.Linq.JArray = jsonObject("orders")
Dim CurrentSKU As String
Dim CurrentOption As String
Dim OrderProcessed As String
Dim NewJasonRecord As String
CurrentSKU = ""
CurrentOption = ""
OrderProcessed = ""
For intI = 0 To jsonArray.Count - 1
' first test to see if this Order has already been processes if it has then
' just go to the next order
For Each newoption In jsonObject.SelectTokens("$.orders[" + CStr(intI) + "].advancedOptions.customField1")
OrderProcessed = newoption.ToString
If OrderProcessed = "" Then
' if not processed the look for the parent sku
For Each item In jsonObject.SelectTokens("$.orders[" + CStr(intI) + "].items[*].sku")
'Console.WriteLine(item.ToString & "; ")
CurrentSKU = CurrentSKU + item.ToString + ","
Next
'add 'Processed' to the advancedOptions.customField1 field
'NewJasonRecord = jsonArray(intI).Replace(Chr(34) + "customField1" + Chr(34) + ":null", Chr(34) + "customField1" + Chr(34) + ":null")
NewJasonRecord = jsonArray(intI).ToString
NewJasonRecord = NewJasonRecord.Replace(Chr(34) + "customField1" + Chr(34) + ": null", Chr(34) + "customField1" + Chr(34) + ": " + Chr(34) + "Processed" + Chr(34))
NewJasonRecord = NewJasonRecord + vbCrLf
End If
Next
Next
'now send the file back up
Dim client = New RestSharp.RestClient("https://ssapi.shipstation.com/orders/createorders")
client.Timeout = -1
Dim request = New RestRequest(Method.POST)
request.AddHeader("Host", "ssapi.shipstation.com")
request.AddHeader("Authorization", " Basic " + EncodedShipStationID)
request.AddHeader("Content-Type", "application/json")
request.AddParameter("application/json", jsonArray, ParameterType.RequestBody)
Dim response As IRestResponse = client.Execute(request)
MsgBox(response.Content)