dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] Using variable in POST params?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    28

    Resolved [RESOLVED] Using variable in POST params?

    I get all markets of event type "cricket" from betfair api using eventTypeIDs filter number which is 4.
    Populated all markets into Treeview.
    What i want to achieve is, getting market name when user click on Treeview name and send another POST request to Api with eventName filter which i'll get from that treeview node. I just want to use variable in that filter. How to do that?

    This is my code to load Cricket Markets.

    Code:
            'This filter will get all Cricket related Market odds
    
            Dim filter As String = "{ ""filter"": { ""eventTypeIds"": [""4""] } }"
    
            Dim endPoint As String = "listEvents"
    
            loadMarket(filter, endPoint)
    
            populateTreeview()

    This will be my code to load specific Cricket Match markets. Don't know how to include variable in filter because that double quotes are confusing for me.

    Code:
    Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
    
            'Here i will get selected Cricket Match name like "Australia vs England" 
    
            Dim sMarket As String = e.Node.Text
    
            Dim endPoint As String = cbxType.Text
            
            'Here i want use that Cricket Match name "Australia vs England" as filter. How can i include it in double 
             quoted filter?
    
            Dim filter As String = sMarket
    
            loadMarket(Filter, EndPoint)
    
        End Sub
    Code for loadMarket() and PopulateTreeview() subs.


    Code:
    Public Sub loadMarket(ByVal filter As String, ByVal endpoint As String)
    
            Try
    
                Dim url As String = "https://api.betfair.com/exchange/betting/rest/v1.0/" + endpoint + "/"
    
                ServicePointManager.Expect100Continue = False
                Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
    
                myHttpWebRequest.Method = "POST"
                myHttpWebRequest.KeepAlive = True
                myHttpWebRequest.Accept = "application/json"
                myHttpWebRequest.Headers("X-Application") = "WcnmFApc9e8M5OA0"
                myHttpWebRequest.Headers("X-Authentication") = "1KLIkDlaD8voIIMsvvMYdJ8+JFk/ZLwORx0pSHma3k0="
                myHttpWebRequest.Headers("Accept-Encoding") = "gzip,deflate"
    
                Dim postData As String = filter
                Dim dataBytes() As Byte = Encoding.UTF8.GetBytes(postData)
    
                myHttpWebRequest.ContentLength = dataBytes.Length
                myHttpWebRequest.ContentType = "application/json"
    
                Using reqStream As Stream = myHttpWebRequest.GetRequestStream()
                    reqStream.Write(dataBytes, 0, dataBytes.Length)
                End Using
    
                Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse, HttpWebResponse)
                Using responseStream = New GZipStream(myHttpWebResponse.GetResponseStream(), CompressionMode.Decompress)
                    Using reader As New StreamReader(responseStream, Encoding.Default)
                        RichTextBox1.Text = reader.ReadToEnd()
                    End Using
                End Using
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
    Public Sub populateTreeview()
    
            Dim json = RichTextBox1.Text
    
            Dim obj() As rootObject = JsonConvert.DeserializeObject(Of rootObject())(json)
    
            For Each o In obj
    
                Dim rNode As New TreeNode(o.event.name)
    
                TreeView1.Nodes.Add(rNode)
    
                rNode.Nodes.Add(o.event.id)
    
                If Not String.IsNullOrEmpty(o.event.countryCode) Then
    
                    rNode.Nodes.Add(o.event.countryCode)
    
                End If
    
    
                rNode.Nodes.Add(o.event.openDate)
    
                rNode.Nodes.Add(o.event.timezone)
    
    
            Next
    
        End Sub

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,746

    Re: Using variable in POST params?

    I'm not quite clear on what will get replaced. You started with this example"

    Dim filter As String = "{ ""filter"": { ""eventTypeIds"": [""4""] } }"

    If you wanted to replace the ""4"", it would probably be conceptually easiest to replace the [""4""], which would look like this:

    dim st1 As String = "[""4""]"

    and the filter would become:

    Dim filter As String = "{ ""filter"": { ""eventTypeIds"": " & st1 & " } }"

    The same kind of thing could be done to replace more than just the 4. You could also leave the square brackets out and just replace the 4, but that would be pretty ugly to read, cause you could end up with a triple double quote on either side of it, so including the square brackets makes it easier to read.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    28

    Re: Using variable in POST params?

    I tried sending POST request using eventID and eventName in filter but no success. It gives me other data related to some football event. This is link where they explain how to navigate markets using filters.

    http://docs.developer.betfair.com/do...r+Applications

    This is my code.

    Code:
            Dim endPoint As String = "listMarketTypes"
    
            Dim filter As String = "{ ""filter"": { ""eventId"": ""28622327"",""eventName"": ""New Zealand v England (5th ODI)"" } }"
    
            loadMarket(filter, endPoint)
    And this is data which Betfair Api supposed to return in json format.

    https://www.betfair.com/sport/cricke...entId=28622327

    I think something wrong with my filter and i couldn't figure out because i am noob at reading documentation thats why i desperately seeking for help. Thanx

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,183

    Re: Using variable in POST params?

    Quote Originally Posted by Terrybogard911 View Post
    .

    Code:
            Dim endPoint As String = "listMarketTypes"
    
            Dim filter As String = "{ ""filter"": { ""eventId"": ""28622327"",""eventName"": ""New Zealand v England (5th ODI)"" } }"
    Are those filter keys valid? Wouldn't the filter be:
    Code:
    Dim filter As String = "{ ""filter"": { ""eventIds"": [""28622327""] } }"
    or
    Code:
    Dim filter As String = "{ ""filter"": { ""textQuery"": ""New Zealand v England (5th ODI)"" } }"

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    28

    Re: Using variable in POST params?

    Quote Originally Posted by Inferrd View Post
    Are those filter keys valid? Wouldn't the filter be:
    Code:
    Dim filter As String = "{ ""filter"": { ""eventIds"": [""28622327""] } }"
    or
    Code:
    Dim filter As String = "{ ""filter"": { ""textQuery"": ""New Zealand v England (5th ODI)"" } }"
    Inferrd, Really appreciate it. Its working. How you got that textQuery method? There is nothing of this type in their documentation i think.

  6. #6
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,183

    Re: Using variable in POST params?

    Yeah, I've not seen an example of the textQuery filter in their docs, but they list all the filter keys here (under 'MarketFilter' on their Betting Type Definitions page)

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    28

    Re: Using variable in POST params?

    Amazing. It seems i am pretty noob at reading documentation or this Api is complex enough for a newbie like me. One more thing, I am using a Betting Excahnge and it shows Betfair odds and i use it without using any proxy or vpn. Is it possible to examine this application and observe how it is accessing betfair without vpn or proxy here in pakistan? Because i have this big issue right now. Will be thankful to you for this.

  8. #8
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,183

    Re: Using variable in POST params?

    It's not the worst API I've seen, but there's still a lot to it. They give a lot of documentation, but then also leave a lot to the imagination; and most of the examples are for the RPC API, not the REST API, which doesn't make things easier for you.

    VPNs and Proxies aren't something I normally get involved with. If you find you need to use them, it's likely the remote server is refusing service based on your IP address. Trying to work out how the other application gets around that is probably going to be very difficult. Maybe it uses a proxy by default? You might get some insight by examining its network traffic by using the likes of Fiddler or Wireshark (again, very complicated if you've not used them before), but I wouldn't really know, sorry.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Sep 2013
    Posts
    28

    Re: Using variable in POST params?

    Thanx anyway. You helped alot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width