使用REST API在magento 2.1上更新库存-错误{“ message”:“请求与任何路线都不匹配。”}

时间:2019-06-19 13:34:39

标签: vb.net rest api magento soapui

我正在尝试使用REST API在magento 2.1站点上更新库存数量。

我正在VB.net中编码,但收到错误JSON响应{“ message”:“请求与任何路由都不匹配。”}

            Dim Access_Token = "XXXXXXXXXXXXX"

            Try

                Dim VATWebClient = New WebClient()
                VATWebClient.Headers(HttpRequestHeader.Accept) = "application/json"
                VATWebClient.Headers(HttpRequestHeader.ContentType) = "application/json"
                VATWebClient.Headers(HttpRequestHeader.Authorization) = "Authorization Bearer " & Access_Token
                Dim Response As String

                Response = VATWebClient.UploadString("http://www.xxxxxx.com/rest/V1/products/xxxx/stockItems/1", "{""stockItem"":{""qty"":100}}")


            Catch webEx As WebException
                Dim errorMessage As String = webEx.Message
                Dim errorStack As String = webEx.StackTrace

            End Try

我还尝试设置SoapUI,只是为了进行测试以确保我正确调用它,并且遇到相同的错误。

我在某处读到webapi.xml必须使用必需的API进行更新,我真的希望情况并非如此,因为主机/ Web开发人员不是很容易访问!

1 个答案:

答案 0 :(得分:0)

UploadString将创建一个 POST 请求,如您从API文档所见,此API端点仅是 PUT 方法。

https://devdocs.magento.com/swagger/index_21.html#!/catalogInventoryStockRegistryV1/catalogInventoryStockRegistryV1UpdateStockItemBySkuPut

我不太确定如何在Visual Basic中更改方法,但我确定它不太困难。