• Resolved northernfrontier

    (@northernfrontier)


    I’m trying to migrate my current baseball league website to the Sportspress and Sportspress for Baseball plugins using the REST API. Most data was easily migrated but adding/updating event results doesn’t seem to be working.

    I’ve tried updating event results using data below. The format is based on the data retrieved by performing a GET on a different event which had its results manually entered. I can also confirm that the IDs used are valid.

    {“results”: {
    “0”: {
    “e”: “E”,
    “eight”: “8”,
    “five”: “5”,
    “four”: “4”,
    “h”: “H”,
    “nine”: “9”,
    “one”: “1”,
    “outcome”: “Outcome”,
    “r”: “R”,
    “seven”: “7”,
    “six”: “6”,
    “ten”: “10”,
    “three”: “3”,
    “two”: “2”
    },
    “2254”: {
    “outcome”: [
    “win”
    ],
    “e”: “3”,
    “eight”: “”,
    “five”: “3”,
    “four”: “0”,
    “h”: “13”,
    “nine”: “”,
    “one”: “1”,
    “r”: “11”,
    “seven”: “2”,
    “six”: “0”,
    “ten”: “”,
    “three”: “0”,
    “two”: “5”
    },
    “2286”: {
    “e”: “2”,
    “eight”: “”,
    “five”: “0”,
    “four”: “1”,
    “h”: “12”,
    “nine”: “”,
    “one”: “1”,
    “outcome”: [
    “loss”
    ],
    “r”: “6”,
    “seven”: “2”,
    “six”: “1”,
    “ten”: “”,
    “three”: “1”,
    “two”: “0”
    }}}

    I’ve tried including this data when creating a new event as well as updating an existing event using PUT and PATCH. In all 3 cases I get a response status of 200 indicating that the action was successful but the results data is not updated. In the case of creating a new event, the event is created while the results data is ignored.

    Is add/updating event results via the REST API available in the free version of the plugin or does this require the pro version? I’d planned on upgrading to the PRO version once the migration is successful so doing so earlier is not a problem if it’s a requirement.

    If this feature is available in the free version, is there a known issue related to updating event results via the REST API in the current release?

    Thanks

Viewing 15 replies - 1 through 15 (of 19 total)
  • Roch

    (@rochesterj)

    Hi there!

    Thanks for reaching out.

    Yes, you can post to update using the free version just fine.

    As far as I can see, it’s likely that this is an issue with the results syntax. Usually, we can’t help with API issues (as they depend on custom coding) but let’s see if @savvasha has any ideas on this one.

    Thanks!

    Thread Starter northernfrontier

    (@northernfrontier)

    Thanks @rochesterj

    The results syntax for baseball should be enough for me to be able to get this working.

    Also, can the results be included when creating an event or does this have to be done in a separate update call?

    Thanks

    Thread Starter northernfrontier

    (@northernfrontier)

    @rochesterj and @savvasha,

    While trying to figure out what might have been incorrect with the results data syntax I was using to update the event I performed the following test:

    1- Import the demo events from the Configuration view
    2- Create new new event using the same 2 teams as one of the demo events
    3- Performed a GET on the demo event and copied the “results” portion of the json result:

    
    {"results":{
          "2293":{
             "one":1,
             "two":2,
             "three":3,
             "four":4,
             "five":5,
             "six":6,
             "seven":7,
             "eight":8,
             "nine":9,
             "ten":10,
             "r":11,
             "h":12,
             "e":13,
             "outcome":[
                "win"
             ]
          },
          "2294":{
             "one":"0",
             "two":"0",
             "three":"0",
             "four":"0",
             "five":"0",
             "six":"0",
             "seven":"0",
             "eight":"0",
             "nine":"0",
             "ten":"0",
             "r":"0",
             "h":"0",
             "e":"0",
             "outcome":[
                "loss"
             ]
          },
          "0":{
             "one":"1",
             "two":"2",
             "three":"3",
             "four":"4",
             "five":"5",
             "six":"6",
             "seven":"7",
             "eight":"8",
             "nine":"9",
             "ten":"10",
             "r":"R",
             "h":"H",
             "e":"E",
             "outcome":"Outcome"
          }
       }}
    

    4 – Attempted a PATCH on the new event from step 2 using Postman. I am getting the same 200 status response and empty results as before. Removing the “0” entry and sending only the results data for the teams themselves gave the same results.

    
      "results": {
            "2293": [],
            "2294": [],
            "0": {
                "outcome": "Outcome"
            }
        }
    

    I would assume that posting the data from a GET should result in the event being updated correctly.

    Hi,

    I have the same problem, I don′t know how to update results. In documentation here – https://support.themeboy.com/article/276-events – is field “results” specified only as an array.

    When I′m trying to get results from existing event, I get dict, for example this:

    "results": {
            "5039": {
                "one": "7",
                "two": "10",
                "three": "17",
                "four": "0",
                "ot": "",
                "td": "",
                "points": "34",
                "outcome": [
                    "win"
                ]
            },
            "5036": {
                "one": "7",
                "two": "10",
                "three": "3",
                "four": "0",
                "ot": "",
                "td": "",
                "points": "20",
                "outcome": [
                    "loss"
                ]
            },
            "0": {
                "one": "1",
                "two": "2",
                "three": "3",
                "four": "4",
                "points": "T",
                "outcome": "Vysledek"
            }
        }

    When I post data in this syntax, nothing happens. In class-sp-rest-api.php I see that field results is updated by function update_post_meta_arrays, where the first row is:

    if ( ! is_array( $value ) ) return false;

    I don′t do much in PHP so I don′t understand the function, I can′t deduce the schema for results field. Please what is the correct schema for updating event results?
    Thanks!

    David

    Thread Starter northernfrontier

    (@northernfrontier)

    For anyone else that is unable to add/update event results via the Rest API, the problem is due to two different issues that were previously reported in the forums and don’t appear to have been fixed yet.

    I’ve provided links to the forum posts below with details on the temporary workarounds I used to get the results to update correctly.

    1- REST API ‘results’ bug due WP update 5.5

    In wp-includes/rest-api.php, each occurrence of the following line needs to be commented out to allow the event results to be updated

    
    $value = rest_sanitize_array( $value );
    

    2- REST API new events not updated in league table

    Follow the instructions provided by @chriskchris in this post to ensure that league tables include the submitted event results

    @rochesterj and @savvasha , I wasn’t able to find any issues in the Github repo related to the above posts. Do you know when they might be fixed?

    Thanks

    Plugin Contributor Savvas

    (@savvasha)

    Hi @northernfrontier ,

    Our developers working on it for a solution.

    Thanks,
    Savvas

    Hi @northernfrontier,

    which version of WordpPress do you have? It is not updating on my site, WP 5.7. I commented out two lines in rest-api.php (2339 and 2676), but when I′m trying to update results, nothing happens.

    Here are my “results”:

    {"5049":{"one":"7","two":"10","three":"17","four":"0","ot":"","td":"","points":"34","outcome":["win"]},"5055":{"one":"7","two":"10","three":"3","four":"0","ot":"","td":"","points":"20","outcome":["loss"]},"0":{"one":"1","two":"2","three":"3","four":"4","ot":"OT",
    "td":"TD","points":"T","outcome":"Vysledek"}}

    The JSON is valid, I′m trying to update it via Postman (PATCH request to URL https://{my-site}/wp-json/sportspress/v2/events/{event-id})

    Here is my output:

    "results": {
            "5049": [],
            "5055": [],
            "0": {
                "one": "1",
                "two": "2",
                "three": "3",
                "four": "4",
                "ot": "OT",
                "td": "TD",
                "points": "T",
                "outcome": "Vysledek"
            }
        }

    If you could help me, I′ll be very grateful. I′m frustrated ??
    Thanks!

    David

    Thread Starter northernfrontier

    (@northernfrontier)

    Hi @dhorava,

    I’m using 5.7 as well. There are a few things I can think of the might be causing you to still see the problem. I’m not sure if these are a problem for you, but I’ll list them for your to check.

    1- Performing PATCH or POST calls requires authentication. I used the Application Passwords plugin for this but there are a few different ways this can be accomplished.

    2- Make sure that the Content-Type header is added with a value of application/json when using Postman

    3- Your JSON payload needs to identify that it contains results since there are a number of different fields that can be updated. In your case, the payload should look like this

    
    {"results: 
    {"5049":{"one":"7","two":"10","three":"17","four":"0","ot":"","td":"","points":"34","outcome":["win"]},"5055":{"one":"7","two":"10","three":"3","four":"0","ot":"","td":"","points":"20","outcome":["loss"]},"0":{"one":"1","two":"2","three":"3","four":"4","ot":"OT",
    "td":"TD","points":"T","outcome":"Vysledek"}}
    }
    

    Hi @northernfrontier,

    I don′t know why, but via Postman it′s not updating – I′m using token for authentication, content-type in header as well, and my payload seems to be right.

    But now I tried it via python script and it updated! So it now works for me ?? (and problem in Postman is obviously on my side)

    Thanks a lot!

    David

    Plugin Contributor Savvas

    (@savvasha)

    Hi @northernfrontier , @chriskchris , @dhorava

    Version 2.7.8 is out and the developers noted that the REST API issue is Fixed!! https://www.ads-software.com/plugins/sportspress/#developers

    Can you check it out please?

    Thanks,
    Savvas

    Plugin Contributor Savvas

    (@savvasha)

    No news, I think are good news ??
    I will set it as resolved for now!

    Thanks,
    Savvas

    Thread Starter northernfrontier

    (@northernfrontier)

    @savvasha ,

    Sorry for the late reply. After running a test it looks as though version 2.7.8 only partially resolves the issue. Event results can be updated via the REST API now but league tables are still not updated correctly as per the second point in the workarounds I previously posted.

    Plugin Contributor Savvas

    (@savvasha)

    Hi @northernfrontier ,

    The league tables are related to the outcomes. Do you also include the outcome to your updates?

    Thanks,
    Savvas

    Thread Starter northernfrontier

    (@northernfrontier)

    @savvasha

    Yes they’re included when creating the event as well,

    The workaround from @chriskchris I previously mentioned fixed this issue. From his description of the issue in his post, the format is not being correctly set on the events when they are created.

    Plugin Contributor Savvas

    (@savvasha)

    Hi @northernfrontier ,

    The issue was fixed I think with the following commit.
    https://github.com/ThemeBoy/SportsPress/commit/c4cbc5e97cf65e2a8017882eb21afb888e87ac22

    Can you confirm it?

    Thanks,
    Savvas

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Updating event results via REST API’ is closed to new replies.