Getting error code 32700 about invalid JSON, but I can't see what's invalid about it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eric
    Junior Member
    • Jul 2019
    • 3

    #1

    Getting error code 32700 about invalid JSON, but I can't see what's invalid about it

    Hi!

    I am new to the Betfair Exchange APIs but not due to software development generally. I am really struggling to make a good start on this and would really appreciate some help please.

    My C# application can successfully log in with the "non-interactive" method and generate a session token, which I put in the "X-Authentication" and "ssoid" HTTP Headers.

    I have successfully got data from one of the historic data APIs and now I'm trying to get some from the sports betting APIs, but my request keeps failing. The HTTP response I get back is Status Code 400: Bad Request, with the JSON {"jsonrpc":"2.0","error":{"code":-32700,"message":"DSC-0008"}}


    I looked up this error code 32700 and it's because of Invalid JSON.

    I ran the JSON of my request through a validator and it seems to be valid. Here it is:

    {"methodname":"SportsAPING/v1.0/listEvents","filter":{},"locale":""}

    It's the simplest JSON I could think of for testing: an empty filter, a blank locale, and the method name. Can't get simpler than that!
    Can anybody see what I did wrong please? I have been fiddling around with it for days and failed to make a successful POST to the sports betting API.

    Many thanks!
  • LiamP
    Junior Member
    • Oct 2015
    • 284

    #2
    Methodname? Fairly sure it should be method, use the visualiser with console open and you can see the requests/responses.

    https://docs.developer.betfair.com/v...ts-operations/

    Is there not a C# wrapper available?

    Comment

    • Eric
      Junior Member
      • Jul 2019
      • 3

      #3
      Wow! Thanks for the fast response!

      I used "methodname" instead of "method" because that's what it says on page 109 of the APIReferenceGuide.pdf

      But you're right.... if I change my string to:

      {"method":"SportsAPING/v1.0/listEvents","params":{"filter":{}}}

      It started to work!

      Just to ensure that I'm getting the most out of the Visualizer, what do you mean "use it with the console open" please?

      Comment

      • LiamP
        Junior Member
        • Oct 2015
        • 284

        #4
        Great, one for Neil to update then.

        console == network console

        https://developers.google.com/web/to...tools/network/

        Comment

        • Eric
          Junior Member
          • Jul 2019
          • 3

          #5
          Thanks for the video link. Taking a look now.

          Comment

          • Raingerred
            Junior Member
            • Jul 2019
            • 2

            #6
            If you write the data in JSON format manually, then making a typo somewhere is easy. Also, if in some script there is a code that needs to be checked for correct spelling, then problems will also arise.

            Need a service with which you can check in automatic mode, all errors. You can also contact professional developers, for example, here https://light-it.net/blog/how-much-d...st-create-app/ I occasionally look for sites with good developers and found one for myself.
            Last edited by Raingerred; 17-07-2019, 03:40 PM.

            Comment

            • Guest

              #7
              Try using null, ie


              {"methodname":"SportsAPING/v1.0/listEvents","filter":{},"locale":null}
              This is what I get back...

              Got Response: {"jsonrpc":"2.0","result":[{"eventType":{"id":"1","name":"Soccer"},"market Cou nt":10336},{"eventType":{"id":"2","name":"Tennis "} ,"marketCount":2332},{"eventType":{"id":"3","na me" :"Golf"},"marketCount":72},{"eventType":{"id":" 4", "name":"Cricket"},"marketCount":130},{"eventTy pe": {"id":"1477","name":"Rugby League"},"marketCount":74},{"eventType":{"id":"5", "name":"Rugby Union"},"marketCount":50},{"eventType":{"id":"6"," name":"Boxing"},"marketCount":31},{"eventType":{"i d":"7","name":"Horse Racing"},"marketCount":1090},{"eventType":{"id":"8 ","name":"Motor Sport"},"marketCount":5},{"eventType":{"id":"27454 571","name":"Esports"},"marketCount":153},{"event T ype":{"id":"28361978","name":"Lottery Specials"},"marketCount":1},{"eventType":{"id":"10 ","name":"Special Bets"},"marketCount":3},{"eventType":{"id":"998917 ","name":"Volleyball"},"marketCount":5},{"even tTyp e":{"id":"11","name":"Cycling"},"marketCount":2 4}, {"eventType":{"id":"2152880","name":"Gaelic Games"},"marketCount":22},{"eventType":{"id":"3988 ","name":"Athletics"},"marketCount ":1},{"eventType":{"id":"6422","name":"Snooker "}," marketCount":28},{"eventType":{"id":"7511","name": "Baseball"},"marketCount":45},{"eventType":{"i d":" 6423","name":"American Football"},"marketCount":9},{"eventType":{"id":"62 31","name":"Financial Bets"},"marketCount":5},{"eventType":{"id":"606611 ","name":"Netball"},"marketCount":5},{"eventTy pe": {"id":"7522","name":"Basketball"},"marketCount" :9} ,{"eventType":{"id":"61420","name":"Australian Rules"},"marketCount":99},{"eventType":{"id":"4683 28","name":"Handball"},"marketCount":17},{"event Ty pe":{"id":"3503","name":"Darts"},"marketCount":9 9} ,{"eventType":{"id":"26420387","name":"Mixed Martial Arts"},"marketCount":49},{"eventType":{"id":"4339" ,"name":"Greyhound Racing"},"marketCount":556},{"eventType":{"id":"23 78961","name":"Politics"},"marketCount":64}],"id":1}

              Troy

              Comment

              • HafizSami
                Junior Member
                • Nov 2020
                • 4

                #8
                Hello i am having the same issue and i am using PHP Curl to get Data.

                I am using below code.

                $vars = array();
                $vars['id'] = 1;
                $vars['params']['filter'] = '{}';
                $vars['method'] = 'SportsAPING/v1.0/listEventTypes';
                $vars['jsonrpc'] = '2.0';
                $vars['locale'] = '';

                $vars = http_build_query($vars);

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,"https://api.betfair.com/exchange/betting/json-rpc/v1");
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                $headers = [
                'X-Application: '.$my_app_key,
                'X-Authentication: '.$session_token,
                'Content-Type: application/json'
                ];

                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);



                $server_output = curl_exec ($ch);

                if (curl_errno($ch)) {
                echo $error_msg = curl_error($ch);
                }


                curl_close ($ch);

                $server_output = json_decode($server_output,true);

                print_r($server_output);exit;

                Comment

                • jabe
                  Senior Member
                  • Dec 2014
                  • 705

                  #9
                  Could you post the contents of $ch, do you think? If it's a JSON error, it'd help to see the JSON.

                  Comment

                  • HafizSami
                    Junior Member
                    • Nov 2020
                    • 4

                    #10
                    I am converting multi dimension array to query to post

                    the array i am posting

                    $vars = array();
                    $vars['id'] = 1;
                    $vars['params']['filter'] = '{}';
                    $vars['method'] = 'SportsAPING/v1.0/listEventTypes';
                    $vars['jsonrpc'] = '2.0';
                    $vars['locale'] = '';

                    and getting this error

                    Array ( [jsonrpc] => 2.0 [error] => Array ( [code] => -32700 [message] => DSC-0008 ) )

                    Comment

                    • HafizSami
                      Junior Member
                      • Nov 2020
                      • 4

                      #11
                      Is there any up to date PHP Wrapper for Betfair API? to get upcoming events and odds?

                      Comment

                      • HafizSami
                        Junior Member
                        • Nov 2020
                        • 4

                        #12
                        Fixed by sending JSON in CURLOPT_POSTFIELDS. The issue was data type.I was sending query data and the requirement was to send JSON.

                        Comment

                        • jabe
                          Senior Member
                          • Dec 2014
                          • 705

                          #13
                          Good. Glad you sorted it.

                          Comment

                          • MarcusMel
                            Junior Member
                            • Aug 2009
                            • 19

                            #14
                            Firefox (Top right corner menu) has a WebDeveloper menu option.
                            If you then use the Network option you can 'see' the network traffic, Headers, Cookies that get exchanged.
                            I find it very useful for de-bugging requests or creating them in combination with the developer web pages.

                            Here are the links to those pages
                            Betting API Demo tool - https://docs.developer.betfair.com/v...ts-operations/

                            Accounts API Demo tool - https://docs.developer.betfair.com/v...nt-operations/

                            Comment

                            Working...
                            X