Really useful stock checker script for Amazon sellers

I'm a small seller on Amazon Handmade and got caught out a number of times with my items going out of stock and not realising.  If my items where fulfilled by Amazon then there is a handy alert to warn you when stock gets low.  But as I made my items to order I have to fulfil them myself, but there is no way to alert me via the seller account.

To fix this I have created a small VBScript that I run manually.  You will just need to save the code below into a text file with a vb extension to execute.  Sorry, Windows only.  You will also need to update the CheckAmazonStock calls to your own shop items using the 10 character Amazon stock codes.  This is for the UK site, so may need updating for the USA etc.

Function CheckAmazonStock( code )

	Dim htmlDoc, xml
	Dim url, stockCheck
	Set htmlDoc = CreateObject("HTMLFile")
	Set xml = CreateObject("MSXML2.XMLHTTP")
	url = "https://www.amazon.co.uk/gp/product/" & code
	With xml
	  .Open "GET", url, False
	  .Send
	  'MsgBox .responseText
	  htmlDoc.Write .responseText
	  htmlDoc.Close
	End With
	
	If NOT htmlDoc.getElementById("outOfStock") Is Nothing Then

		outofstock = outofstock & htmlDoc.getElementById("productTitle").innerText & vbcr 

	Elseif NOT htmlDoc.getElementById("availability") Is Nothing Then
		stockCheck = Split(Trim(htmlDoc.getElementById("availability").firstChild.innerText))(1)
	
		If stockCheck = "1"	Then
			oneInStock = oneInStock & htmlDoc.getElementById("productTitle").innerText & vbcr 	
		ElseIf stockCheck = "2" Then
			twoInStock = twoInStock & htmlDoc.getElementById("productTitle").innerText & vbcr 
		End If
	
	End If

End Function

Dim oneInStock, twoInStock, outofstock

'Add you own 10 char amazon stock code here (enter as many as you want)
'CheckAmazonStock("XXXXXXXXXX") 
'CheckAmazonStock("XXXXXXXXXX") 
'CheckAmazonStock("XXXXXXXXXX") 

' Alert Box
Dim warningStock
If oneInStock <> "" Then
	warningStock = warningStock & "Items with only 1 left in stock" & vbcr & oneInStock & vbcr 
End If

If twoInStock <> "" Then
	warningStock = warningStock & "Items with only 2 left in stock" & vbcr & twoInStock & vbcr 
End If

If outofstock <> "" Then
	MsgBox "ITEMS OUT OF STOCK" & vbcr & outofstock & vbcr & warningStock & vbcr & "All other items have good stock levels", 16, "WARNING Stock Levels on Amazon"
ElseIf warningStock <> "" Then
	MsgBox warningStock & "All other items have good stock levels", 48, "Stock Levels on Amazon"
Else
	MsgBox "All  items have good stock levels", 64, "Good Stock Levels on Amazon"
End If

Hope it helps someone.  Feel free to use it as you wish.  If you make any changes, that you think may be useful to others, let me know and I can share it here.

#coding

Comments

Back to blog