REST API 来自 VB ( ZOHO CREATOR ) 的调用

REST API Call from VB ( ZOHO CREATOR )

正在尝试拨打电话

https://www.zoho.com/creator/help/api/rest-api/rest-api-edit-records.html

我尝试了所有方法,但似乎我需要基本知识。谁能告诉我我的代码有什么问题

Public Sub updateRecord(ByVal ht As Hashtable, ByVal criteriaField As String)

        Dim apiUrl As String = "https://creator.zoho.com/api/xml/write/apikey=xxxx"
        Dim xmlStr As New System.Text.StringBuilder
        Dim newvalue As New System.Text.StringBuilder

        newvalue.AppendLine("<newvalues>")
        xmlStr.Append("<ZohoCreator><applicationlist>")
        xmlStr.Append("<application name=copy-of-ebay-inventory><formlist><form name=Ebay_Inventory>")
        xmlStr.AppendLine("<update>")
        xmlStr.AppendLine("<criteria>")
        xmlStr.AppendLine("<field name='Ticket Number' compOperator='Equals' value='20573'></field>")
        xmlStr.AppendLine("</criteria>")
        newvalue.AppendLine("<field name='Found on site' value='1'></field>")
        newvalue.AppendLine("</newvalues>")
        xmlStr.Append(newvalue.ToString)
        xmlStr.AppendLine("</update>")
        xmlStr.AppendLine("</form></formlist></application></applicationlist></ZohoCreator>")

        Dim params As String = "XMLString=" + xmlStr.ToString

        Dim res As String = getResponseFromUrl(apiUrl, params)

    End Sub
Public Function getResponseFromUrl(ByVal url As String, ByVal params As String)
        Dim str As String = ""
        Try
            Dim webreq As HttpWebRequest = WebRequest.Create(url)
            webreq.Method = "POST"
            webreq.ContentType = "application/x-www-form-urlencoded"
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(params)
            Dim dataStream As Stream = webreq.GetRequestStream()
            dataStream.Write(byteArray, 0, byteArray.Length)
            dataStream.Close()

            Dim res As WebResponse = webreq.GetResponse()
            Dim stream As Stream = res.GetResponseStream()
            Dim streamReader As New StreamReader(stream)
            str = streamReader.ReadToEnd
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Return str.ToString
    End Function

格式化结束时我的 xml 看起来像

但事实并非如此。 在 ..

上找到了一个很好的例子

LINK DEMO

回复

错误消息告诉您,name 属性的 value 必须用引号引起来 node/element:

xmlStr.Append("<application name='copy-of-ebay-inventory'><formlist><form name=Ebay_Inventory>")

注意 ' 单引号 "copy-of-ebay-inventory"...

用引号将所有 XML 属性值括起来(单引号或双引号,尽管双引号更常见):

    xmlStr.Append("<application name=" & ControlChars.Quote & "copy-of-ebay-inventory" & ControlChars.Quote &
                  "><formlist><form name=" & ControlChars.Quote & "Ebay_Inventory" & ControlChars.Quote & ">")