• I just encountered a strange problem and I spent couple of hours on debugging the issue.

    I’m developing an Android app for my website https://www.geekdashbaord.com/ using Rest API v2 and I noticed extra text is added at the beginning of response only for few endpoints.

    More details
    I’m fetching 5 recent posts at once and loading next 5 after scrolling. But my app is crashing at offest 70 yesterday.

    and today my app is crashing for 1st and 2nd posts and working fine from the third post and again crashing at 72th post.

    I debugged the response from the postman and noticed a strange issue.

    If you test this end post in postman or browser https://www.geekdashboard.com/wp-json/wp/v2/posts?per_page=25&offset=1

    you can see these extra lines before the actual response

    <script type="text/javascript">hide_compare_list = true;var ajaxurl = "https://www.geekdashboard.com/wp-admin/admin-ajax.php",comp_link = "https://www.geekdashboard.com/compare/",comp_cn = "aps_comp_www_geekdashboard_com",msg_suc = "<strong>Success:</strong> You have added <strong>%title%</strong> to your <a href=\"%link%\">comparison list</a>",msg_ful = "<strong>Sorry:</strong> Your <a href=\"%link%\">Comparison list</a> is full, you can compare upto 3 products at a time.",msg_dup = "<strong>%title%:</strong> is already found in your <a href=\"%link%\">comparison list</a>",msg_rem = "<strong>%title%:</strong> is successfully removed from your <a href=\"%link%\">comparison list</a>";</script>

    and If you test these API calls
    https://www.geekdashboard.com/wp-json/wp/v2/posts?per_page=25&offset=25
    https://www.geekdashboard.com/wp-json/wp/v2/posts?per_page=25&offset=28
    https://www.geekdashboard.com/wp-json/wp/v2/posts?per_page=25&offset=28

    no errors are found in response. It is very clear for me, that extra code belongs to Arena Products Store – WordPress Plugin. I disabled the plugin and everything works fine.

    and also it is clear that I’m getting this error if few specific post id is present in the response.

    So, do you think it is problem with the plugin? If it is problem with the plugin, then why only few end point are failing?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Without a doubt it’s a plugin problem. I’ve only a hunch why only certain offsets are a problem. Apparently the conditionals used to decide whether to inject script into content is flawed. I’m not convinced injecting script into REST responses is even appropriate, even if it were introduced correctly. I guess they would still like their script to work in REST based apps. That would be up to the app developer to decide and implement IMO. Arbitrarily injecting script into REST responses is not how to do it.

    In any case, this is something to take up with the plugin authors. We are unable to assist you with commercial plugins.

    Thread Starter Amar Ilindra

    (@amarilindra)

    Thanks for the update bcworkz, I’ll get in touch with plugin developer to fix the issue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with Rest API v2 – Extra text added before response’ is closed to new replies.