Accounts API JSON Request

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NickyG
    Junior Member
    • Aug 2014
    • 6

    #1

    Accounts API JSON Request

    I'm trying to call getAccountFunds from the accounts API using a JSON request, I keep getting the error "NO_SESSION" though. My app key and session token are ok as the rest of my program is working fine, so there must be something wrong with the request, cant figure out what though:

    Code:
        Private Function SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String) As String
            Dim req As WebRequest = WebRequest.Create(uri)
            req.ContentType = contentType
            req.Method = method
            req.ContentLength = jsonDataBytes.Length
    
    
            Dim stream = req.GetRequestStream()
            stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
            stream.Close()
    
            Dim response = req.GetResponse().GetResponseStream()
    
            Dim reader As New StreamReader(response)
            Dim res = reader.ReadToEnd()
            reader.Close()
            response.Close()
    
            Return res
        End Function
    
        Private Sub Get_Funds()
    
    
            Dim endpoint As New Uri("https://api.betfair.com/exchange/account/json-rpc/v1/getAccountFunds/")
    
            Dim header As String = "{ 'X-Application' : '" & appkey & "', 'X-Authentication' : '" & sessionToken & "' ,'content-type' : 'application/json' }"
    
            Dim json_req As String = "{""jsonrpc"":""2.0"",""method"":""AccountAPING/v1.0/getAccountFunds"",""id"":""1"",""params"":{""locale"":""en""} }"
    
            Dim data = Encoding.UTF8.GetBytes(json_req)
            Dim result_post = SendRequest(endpoint, data, header, "POST")
    
            PrintOut(result_post.ToString)
    
        End Sub
  • betdynamics
    Junior Member
    • Sep 2010
    • 534

    #2
    If you are using JSON-RPC, then the endpoint should be:

    https://api.betfair.com/exchange/account/json-rpc/v1/

    i.e. you do not need to append the getAccountFunds name as the function is passed as the "method" in the json request.

    Comment

    • NickyG
      Junior Member
      • Aug 2014
      • 6

      #3
      Thanks, working now.

      Comment

      • rphi6876
        Junior Member
        • Nov 2009
        • 7

        #4
        Hi I have tried to use the same code as posted to get my account funds (with the appropriate change to the endpoint). What I have currently is below

        Code:
        Imports System.Net
        Imports System.IO
        Imports System.Text
        Imports System.Linq
        Imports Api_ng_sample_code.TO
        Imports Api_ng_sample_code.Json
        
        Public Class accountRequest
            Public Shared Function SendRequest(ByVal uri As Uri, ByVal jsonDataBytes As Byte(), ByVal contentType As String, ByVal method As String) As String
                Dim req As WebRequest = WebRequest.Create(uri)
                req.ContentType = contentType
                req.Method = method
                req.ContentLength = jsonDataBytes.Length
        
        
                Dim stream = req.GetRequestStream()
                stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
                stream.Close()
        
                Dim response = req.GetResponse().GetResponseStream()
        
                Dim reader As New StreamReader(response)
                Dim res = reader.ReadToEnd()
                reader.Close()
                response.Close()
        
                Return res
            End Function
        
            Public Shared Sub Get_Funds()
        
        
                Dim endpoint As New Uri("https://api.betfair.com/exchange/account/json-rpc/v1/")
        
                Dim header As String = "{ 'X-Application' : '" & AppKey & "', 'X-Authentication' : '" & sessionToken & "' ,'content-type' : 'application/json' }"
        
                Dim json_req As String = "{""jsonrpc"":""2.0"",""method"":""AccountAPING/v1.0/getAccountFunds"",""id"":""1"",""params"":{""locale"":""en""} }"
        
                Dim data = Encoding.UTF8.GetBytes(json_req)
                Dim result_post = SendRequest(endpoint, data, header, "POST")
        
            End Sub
        End Class
        What is returned by res is


        {"jsonrpc":"2.0","error":{"code":-32099,"message":"AANGX-0010","data":{"AccountAPINGException":{"errorDetai ls":"","errorCode":"NO_SESSION","requestUUID":"prd aan-288274-02121119-000241b304"},"exceptionname":"AccountAPINGExceptio n"}},"id":"1"}
        My AppKey and SessionTOken are correct as other request to https://api.betfair.com/exchange/betting are working. Any help on this error would be greatly appreciated.

        I am Australian so my account is an Australian one if that makes a difference.

        Cheers,
        R
        Last edited by rphi6876; 15-02-2015, 11:40 PM.

        Comment

        • clothcap
          Junior Member
          • Sep 2009
          • 7

          #5
          This is the code I am using works fine five mins ago

          Code:
            Dim json_req As String = "{""jsonrpc"": ""2.0"",""method"":""AccountAPING/v1.0/getAccountFunds"",""params"": {""wallet"":""UK""},""id"": 1}"
          Endpoint

          Code:
          "https://api.betfair.com/exchange/account/json-rpc/v1/"
          I think your problem is the Json string should specify wallet and id at the end
          So your would be AUSTRALIAN and id 2
          Last edited by clothcap; 16-02-2015, 01:05 AM. Reason: just saw aus wallet

          Comment

          • rphi6876
            Junior Member
            • Nov 2009
            • 7

            #6
            Thanks clothcap.

            Unfortunately I tried both
            Code:
            Dim json_req As String = "{""jsonrpc"": ""2.0"",""method"":""AccountAPING/v1.0/getAccountFunds"",""params"": {""wallet"":""UK""},""id"":1}"
            and

            Code:
            Dim json_req As String = "{""jsonrpc"": ""2.0"",""method"":""AccountAPING/v1.0/getAccountFunds"",""params"": {""wallet"":""AUSTRALIAN""},""id"":2}"
            and still get the error message. I appreciate your help though.

            Cheers,
            R

            Comment

            • clothcap
              Junior Member
              • Sep 2009
              • 7

              #7
              What endpoint are you using
              the aus one is

              Code:
              REST
               https://api-au.betfair.com/exchange/account/rest/v1.0
              
              JSON-rpc
              https://api-au.betfair.com/exchange/account/json-rpc/v1

              Comment

              • clothcap
                Junior Member
                • Sep 2009
                • 7

                #8
                Thought i'd do the whole sub for Aus market


                Code:
                 
                Imports System.Net
                Imports System.IO
                Imports System.Text
                Imports System.Linq
                Imports Api_ng_sample_code.TO
                Imports Api_ng_sample_code.Json
                
                Public Class accountRequest
                    Public Shared Function SendRequest(ByVal uri As Uri, ByVal jsonDataBytes As Byte(), ByVal contentType As String, ByVal method As String) As String
                        Dim req As WebRequest = WebRequest.Create(uri)
                        req.ContentType = contentType
                        req.Method = method
                        req.ContentLength = jsonDataBytes.Length
                
                
                        Dim stream = req.GetRequestStream()
                        stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
                        stream.Close()
                
                        Dim response = req.GetResponse().GetResponseStream()
                
                        Dim reader As New StreamReader(response)
                        Dim res = reader.ReadToEnd()
                        reader.Close()
                        response.Close()
                
                        Return res
                    End Function
                
                    Public Shared Sub Get_Funds()
                
                
                        Dim endpoint As New Uri("https://api-au.betfair.com/exchange/account/json-rpc/v1/")
                
                        Dim header As String = "{ 'X-Application' : '" & AppKey & "', 'X-Authentication' : '" & sessionToken & "' ,'content-type' : 'application/json' }"
                
                       Dim json_req As String = "{""jsonrpc"": ""2.0"",""method"":""AccountAPING/v1.0/getAccountFunds"",""params"": {""wallet"":""AUSTRALIAN""},""id"":2}"
                        Dim data = Encoding.UTF8.GetBytes(json_req)
                        Dim result_post = SendRequest(endpoint, data, header, "POST")
                
                    End Sub
                End Class
                I dont use the sample code so it needs testing
                Last edited by clothcap; 17-02-2015, 01:30 PM. Reason: adding footnote

                Comment

                Working...
                X