【问题标题】:Updating stock on magento 2.1 using REST API - Error {"message": "Request does not match any route."}使用 REST API 在 magento 2.1 上更新库存 - 错误 {“message”:“请求与任何路由都不匹配。”}
【发布时间】:2019-06-19 13:34:39
【问题描述】:

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

我在 VB.net 中编码,但收到错误 JSON 响应 {"message": "Request does not match any route."}

            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 进行更新,我真的希望情况并非如此,因为主机/网络开发人员不太容易访问!

【问题讨论】:

    标签: vb.net rest api magento soapui


    【解决方案1】:

    UploadString 将创建一个 POST 请求,正如您从 API 文档中看到的那样,此 API 端点仅是 PUT 方法。

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

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

    【讨论】:

    • 感谢 Andrew 更新了代码以包含“Put”作为过载,例如code Response=WebClient.UploadString("derrys.com/rest/V1/products/M_T_P/stockItems/1", "Put", "{""stockItem"":{""qty"":100}}") code 我现在得到一个 401 错误与身份验证问题有关,因此解决了我的直接问题:) 谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    • 2019-11-25
    • 2010-12-17
    • 2016-04-22
    相关资源
    最近更新 更多