JSON request error. Mollybet API

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 1168 Views - Last Post: 11 February 2019 - 10:59 AM Rate Topic: -----

#1 banjo121212   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 22-January 19

JSON request error. Mollybet API

Posted 22 January 2019 - 04:41 AM

Hi guys,

We have been going in circles with the below errors and cant seem to get past this step.
Any help would be greatly appreciated.

This is in regards to section 4.3.1 Create a new bet placement order with API https://api.mollybet...lacement-order.

The client used is c# Httpclient, and we are sending the parameters as JSON body.

JSON request parameters:

{
   "betslip_id":"aff87f1773774ef7b04e81992c038e8f",
   "price":"2.06",
   "stake":"[\"EUR\", 13]",
   "duration":"15",
   "accounts":"[\"ibc\", \"_99899bb2_\"]",
   "adaptive_bookies":"[ibc]",
   "ignore_system_maintenance":false,
   "no_put_offer_exchange":false,
   "bookie_min_stakes":"{}",
   "user_data":null
}


The c# code that generates the JSON :

 private void doPlace(string betSlipId,double price , double stake , string bookie, string accountName)
    {
        try
        {
            //string placebetLink = "https://pro.sportmarket.com/trade/place_order";
            //var postData = new FormUrlEncodedContent(new[]
            //{
            //    new KeyValuePair<string,string>("betslip_id",betSlipId),
            //    new KeyValuePair<string,string>("price" , price.ToString()),
            //    new KeyValuePair<string, string>("request_uuid",getRandom()),
            //    new KeyValuePair<string, string>("timeout","20"),
            //    new KeyValuePair<string,string>("stake",stake.ToString()),
            //    new KeyValuePair<string,string>("accounts",accountName),
            //    new KeyValuePair<string,string>("adaptive",bookie),
            //    new KeyValuePair<string, string>("ignore_autoplacing","false"),
            //    new KeyValuePair<string, string>("csrfmiddlewaretoken", csrToken)
            //});

            //HttpResponseMessage placeResponse = httpClient.PostAsync(placebetLink, postData).Result;
            //placeResponse.EnsureSuccessStatusCode();

            //string content = placeResponse.Content.ReadAsStringAsync().Result;
            //ApiClient.DefaultRequestHeaders.TryAddWithoutValidation("X-Requested-With", "XMLHttpRequest");
            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
            string stakeStr = string.Format("[\"EUR\", {0}]", stake);
            string placebetUrl = string.Format("{0}v1/orders/", endPonit);
            //var postData = new FormUrlEncodedContent(new[]
            //{
            //    new KeyValuePair<string,string>("betslip_id",betSlipId),
            //    new KeyValuePair<string,string>("price" , price.ToString()),
            //    new KeyValuePair<string,string>("stake",stakeStr),
            //    new KeyValuePair<string,string>("duration","15"),
            //    new KeyValuePair<string,string>("accounts",accountName),
            //    new KeyValuePair<string,string>("adaptive_bookies",string.Format("[{0}]",bookie)),
            //    new KeyValuePair<string, string>("ignore_system_maintenance","false"),
            //    new KeyValuePair<string, string>("no_put_offer_exchange","false"),
            //    new KeyValuePair<string, string>("bookie_min_stakes","{}"),
            //    new KeyValuePair<string, string>("user_data","")

            //});

            PlaceRequest requestJson = new PlaceRequest();
            requestJson.betslip_id = betSlipId;
            requestJson.price = price.ToString();
            requestJson.stake = stakeStr;
            requestJson.accounts = accountName;
            requestJson.duration = "15";
            requestJson.adaptive_bookies = string.Format("[{0}]", bookie);
            requestJson.ignore_system_maintenance = false;
            requestJson.no_put_offer_exchange = false;
            requestJson.bookie_min_stakes = "{}";

            string jsonStr = JsonConvert.SerializeObject(requestJson);

            HttpResponseMessage placeResponse = ApiClient.PostAsync(placebetUrl, new StringContent(jsonStr, Encoding.UTF8, "application/json")).Result;
            placeResponse.EnsureSuccessStatusCode();

            string content = placeResponse.Content.ReadAsStringAsync().Result;
        }
        catch (Exception e)
        {

        }


Attached Image
Attached Image

This post has been edited by Skydiver: 22 January 2019 - 05:49 AM
Reason for edit:: Put code and JSON in code tags to preserve formatting.


Is This A Good Question/Topic? 0
  • +

Replies To: JSON request error. Mollybet API

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6825
  • View blog
  • Posts: 23,203
  • Joined: 05-May 12

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 05:53 AM

The screenshot which shows the response indicating the errors seems to be pretty explicit about why it rejected your JSON data submission. There were places where it was expecting to see arrays or dictionaries, but you are passing in Unicode strings; and where it says that the user_data cannot be null.
Was This Post Helpful? 0
  • +
  • -

#3 banjo121212   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 22-January 19

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 06:44 AM

Thanks for your reply, appreciate it.

The parameters are passed according to the API document. Could you please give an example as to how you think they should look?

This post has been edited by Skydiver: 22 January 2019 - 07:44 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 banjo121212   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 22-January 19

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 07:05 AM

Attached Image

This is what happens when accounts is passed as array.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,943
  • Joined: 12-December 12

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 07:12 AM

You've then moved a step further ;)

It now tells you it recognises an array, but the element(s) aren't in the right format. It looks like you need one or more objects, with two properties/attributes of bookie and username. The API you linked to above also confirms they type of format expected.

Presumably PlaceRequest() enables you to construct the correct JSON objects.
Was This Post Helpful? 0
  • +
  • -

#6 banjo121212   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 22-January 19

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 08:01 AM

Thanks for taking the time guys.

As array it looks like this
betslip_id=70e46582ecc349c2a8fabaca221da8e2&price=2.92&stake=%5B%22EUR%22%2C+13%5D&duration=15&accounts=%5B%22sbo%22%2C+%22_e8e8a7c0_%22%5D&adaptive_bookies=%5Bsbo%5D&ignore_system_maintenance=false&no_put_offer_exchange=false&bookie_min_stakes=%7B%7D&user_data=



Attached Image

Is this not correct?

This post has been edited by Skydiver: 22 January 2019 - 08:26 AM
Reason for edit:: Put the URL query string into code tags to be able to see the full string.

Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6825
  • View blog
  • Posts: 23,203
  • Joined: 05-May 12

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 08:27 AM

No, that is a URL query string. You are supposed to be building a JSON body.
Was This Post Helpful? 0
  • +
  • -

#8 banjo121212   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 22-January 19

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 08:40 AM

View PostSkydiver, on 22 January 2019 - 08:27 AM, said:

No, that is a URL query string. You are supposed to be building a JSON body.


Sorry to be asking questions which may seem stupid to you.

I don't exactly understand.

To confirm; the parameters need to be as JSON body and instead of passing as string it needs to be done as array, is this correct?
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6825
  • View blog
  • Posts: 23,203
  • Joined: 05-May 12

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 09:28 AM

There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.

Yes, my understanding is that your objective is to pass along JSON. See the railroad track diagrams on JSON.org to see what valid JSON looks like.
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,943
  • Joined: 12-December 12

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 09:30 AM

What members does the PlaceRequest class provide? When you type requestJson. does anything useful appear?

Quote

instead of passing as string it needs to be done as array

Some of the parameters are provided as arrays, arrays of objects, or objects. You need to construct a JSON object with all the right properties, which one would hope PlaceRequest would provide (assuming this class is obtained from their API). If not, then you might resort to some other approach to creating a valid JSON object for your request.
Was This Post Helpful? 0
  • +
  • -

#11 h4nnib4l   User is offline

  • The Noid
  • member icon

Reputation: 1366
  • View blog
  • Posts: 1,942
  • Joined: 24-August 11

Re: JSON request error. Mollybet API

Posted 22 January 2019 - 01:02 PM

Have you tried not quote-wrapping the collections in your JSON string definition? For example, "stake":["EUR", 13] instead of "stake":"[\"EUR\", 13]". I haven't tested it, but that jumped out at me.

This post has been edited by h4nnib4l: 22 January 2019 - 04:27 PM

Was This Post Helpful? 0
  • +
  • -

#12 banjo121212   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 22-January 19

Re: JSON request error. Mollybet API

Posted 23 January 2019 - 09:01 AM

Thanks to all who have given suggestions so far. Unfortunately we are still unable to fix it.

String array format results in this:
Attached Image
Attached Image


JSON format parameter results in this:
Attached Image

Also not quote-wrapping doesn't work either.

Am I missing something?
Was This Post Helpful? 0
  • +
  • -

#13 h4nnib4l   User is offline

  • The Noid
  • member icon

Reputation: 1366
  • View blog
  • Posts: 1,942
  • Joined: 24-August 11

Re: JSON request error. Mollybet API

Posted 23 January 2019 - 09:09 AM

Accounts is an array of arrays. Try [["ibc", "_99899bb2_"]].
Was This Post Helpful? 0
  • +
  • -

#14 banjo121212   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 22-January 19

Re: JSON request error. Mollybet API

Posted 25 January 2019 - 07:49 AM

View Posth4nnib4l, on 23 January 2019 - 09:09 AM, said:

Accounts is an array of arrays. Try [["ibc", "_99899bb2_"]].


Hi thanks for that, unfortunately it doesn't work, getting the same error.


{"betslip_id":"5318704cc889482d9dbf0cc4df70d7c8","price":"1.02","stake":"[\"EUR\", 13]","duration":"15","accounts":"[[\"bf\", \"_ec34b96a_\"]]","adaptive_bookies":"[bf]","ignore_system_maintenance":false,"no_put_offer_exchange":false,"bookie_min_stakes":"{}","user_data":null}

Attached Image
Was This Post Helpful? 0
  • +
  • -

#15 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2791
  • View blog
  • Posts: 11,005
  • Joined: 03-December 12

Re: JSON request error. Mollybet API

Posted 25 January 2019 - 08:50 AM

{
    "betslip_id":"5318704cc889482d9dbf0cc4df70d7c8",
    "price":"1.02",
    "stake":"[\"EUR\", 13]",
    "duration":"15",
    "accounts":"[
        [\"bf\", \"_ec34b96a_\"]
    ]",
    "adaptive_bookies":"[bf]",
    "ignore_system_maintenance":false,
    "no_put_offer_exchange":false,
    "bookie_min_stakes":"{}",
    "user_data":null
}


And the errors tell you what to fix.
After running it thru a lint checker, https://jsonlint.com, your JSON is not correct anyway.

Why are you escaping quotes?
Why do you have arrays inside of quotes?
Why is user_data null?
"stake":"[\"EUR\", 13]", That is a string, not an array.
"adaptive_bookies":"[bf]", Same as above.
"bookie_min_stakes":"{}", Are you starting to notice a pattern, that elements are not correctly formatting?
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2