The JSON response from the API could not be parsed. Please check your API connection + The panel can't connect to the API

After I install Kirby 3 (latest version) plainkit, I get "The JSON response from the API could not be parsed. Please check your API connection. " randomly in the backend and "This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible. " randomly on frontend. Once in a while, I get disconnected from the backend with the error message “The panel can’t connect to the API”.

Sometimes, everything loads OK.

It is a LiteSpeed server with php 7.4. http://dev.steveforest.com/ is the testing environnement URL.

mod_security is disabled for this subdomain since my hosting provider though it could be the source of the problem. No change since then.

In the network tab, I also get random stuff :

  • 500 Error with /media/plugins/index.js?0=
  • 500 Error with /media/plugins/index.css
  • other random stuff is going on.

I don’t get it, there’s no plugins folder in the /media… I also got some stuff not loading properly with /api once in a while. Everything is very, very random.

I’d really like to use Kirby for my personnal website if I can get it working… Can someone help me with this mess? Sorry for my lame english.

To get more information on the frontend, please enable debugging in your config. Maybe we will see clearer afterwards.

Since the plainkit doesn’t come with a config, you first have to create the config folder inside the site folder, then a config.php inside with the following content:

<?php
return [
    'debug'  => true
];

Done. This is what I get. I’m not a programmer/developper so it doesn’t help me very much…

I tried to install Kirby on a free web hosting solution to see if I can get it working there and, yes, it does work great. I guess something is wrong with my server config/setup that mess with Kirby’s code.

Everything seems to work fine after disabling the ‘sqlite3’ PHP module on the server. That would be great if someone can confirm that.

This has nothing to do with Kirby, but is a PHP startup error caused by - as the error says - trying to load the same module twice. If it works now, then everything should be ok.

I have just run into this same issue on my own hosting, and I havent enabled the SQLLite extension or messed about with the PHP extensions. Strange.

With a fresh Starterkit or with your own website and several plugins?

I have a website running live with "Kirby: 3.4.3 - PHP: 7.2.26" on a Linux server.

On my development system running "Kirby: 3.4.3" on “XAMPP 7.4.10Apache/2.4.46 (Win64) and PHP/7.4.10 on Win10 64-bit” I want to add a new blogarticle as admin.

When I click on “Entwurf anlegen” I get the error message “The JSON response from the API could not be parsed. Please check your API connection.

.

On the live system, I get the same error!

I don’t use a database, only “pure” Kirby!

# // site/blueprints/pages/blogarticle.yml

title: Blog-Artikel

num: "{{ page.date.toDate('Ymd') }}"

icon: document

status:
  draft:
    text: Dieser Beitrag ist im Entwurfsmodus und daher nur für angemeldete Editoren sichtbar.
  listed:
    text: Dieser Beitrag ist für alle Besucher sichtbar.

options:                   # default is "true" with the exception of changeTemplate
  read:                    # hide this page in the panel
    *: false
    editor: true
    admin: true

columns:
  # sidebar
  - width: 1/3
    sections:

      # a list of files
      files:
        type: files
        headline: Dateien
        sortable: true
        layout: cards
#        size: small
        text: "Dateiname: {{ file.filename }}"
        info: "{{ file.dimensions }} Pixel, Alt-Text: '{{ file.alt }}'"
      blueprint:
        type: info
        theme: none
        text: |
          Pfad: site/blueprints/{{ page.blueprint.name }}.yml

  # main
  - width: 2/3
    sections:
      # a simple form
      content:
        type: fields
        fields:
          date:
            label: Datum des Blog-Beitrags (Veröffentlichung)
            type:  date
            required: true
            default: today
            width: 1/2
            help:  Bitte das "Tagesdatum" des Blog-Beitrags auswählen.
          author:
            label: Autor
            type: users
            multiple: false
            width: 1/4
            help:  Bitte den "Autor" des Blog-Beitrags auswählen.
          pagetitleClass:
            label: Schriftfarbe
            type:  text
            help:  Bitte "red" eingeben, wenn der Titel in roter Schriftfarbe erscheinen soll.
            width: 1/4
          coverimage:
            label: Titelbild
            type: select
            options: images
            width: 1/2
            help:  Bitte das "Titelbild" des Blog-Beitrags auswählen.<br>Dieses wird dann automatisch angezeigt.
          notathomepage:
            label: Startseite
            type:  toggle
            width: 1/2
            text:  Auf der Startseite unsichtbar?
            help:  Bitte das Häkchen setzen, wenn dieser Eintrag auf der Startseite <b>NICHT</b> (mehr) angezeigt werden soll.
          text:
            label: Text
            type:  textarea
            required: true
            help:  Bitte den vollständigen "Text" des Blog-Beitrags eingeben.
          preview:
            label: Blog-Vorschau
            type:  textarea
            help:  Bitte, wenn gewünscht, den "Vorschautext" des Blog-Beitrags eingeben.<br>Dieser wird, wenn er vorhanden ist, anstelle des verkürzten Textes in der Vorschau angezeigt.<br>=>&nbsp;&nbsp;&nbsp;<span class="red">Es sollte im Normalfall <b>nicht mehr nötig</b> sein, dieses Feld zu füllen!</span>

Despite the error message, the new draft is saved, but the panel page is not updated, i.e. the new draft is not displayed on the blog page, nor is the newly created blog article (for editing) displayed in the panel.

[added:]
Running Kirby 3.4.2 makes no difference.

I use Firefox and Google Chrome (newest versions) on a Win10 computer.
[/added]

I think this is an Kirby issue.

@texnixe: Please reopen this issue! Or shall I move this contribution to a new thread?

It’s the demo site for my Hepburn theme (which you have a copy of if want to test!). I ran composer upgrade on it bring everything up to date, and uploaded to the domain which is set to use 7.4. Thats when i got the same Whoops further up the thread. 7.4 does infact have a sqlite extension, unlike preceding versions. i turned that off, which made the front end of the site work, but i still the JSON api error if i try to access the panel.

I’m running PHP 7.4.10 locally with Kirby 3.4.3 without having this issue.

@jimbobrjames What php modules are installed on your server? Looks like you are only having this issue on the remote server but not locally in your Valet environment?

@pixelijn Yes, its the live server…

Hm, that looks ok, I think.

Does this also happen with a fresh Starterkit on the same server?

And what does your browser console say?

CSP was blocking script source. Turned out to be this rule in the htaccess:

<IfModule mod_headers.c>

Header set Content-Security-Policy "script-src 'self'; object-src 'self'"

    <FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
        Header unset Content-Security-Policy
    </FilesMatch>

</IfModule>

I forgot that was in there :blush:

Didn’t we come across that before?

@anon77445132 Please also check your browser console and report the errors you find there.

@pixelijn:

The browser console of FF81.0(64 bit) shows, when I hit “Entwurf anlegen”:

Errors:
<none>

Warnings:
Das Cookie “phpMyAdmin” wird bald als Cross-Site-Cookie gegen “http://127.0.0.1:59215/mywebsite/api//pages/blog/lock” behandelt, da das Schema nicht übereinstimmt. lock
Das Cookie “phpMyAdmin” wird bald als Cross-Site-Cookie gegen “http://127.0.0.1:59215/mywebsite/api/pages/blog/children/blueprints?section=drafts” behandelt, da das Schema nicht übereinstimmt. blueprints
Das Cookie “phpMyAdmin” wird bald als Cross-Site-Cookie gegen “http://127.0.0.1:59215/mywebsite/api//pages/blog/lock” behandelt, da das Schema nicht übereinstimmt. lock
Das Cookie “phpMyAdmin” wird bald als Cross-Site-Cookie gegen “http://127.0.0.1:59215/mywebsite/api//pages/blog/lock” behandelt, da das Schema nicht übereinstimmt. lock
Das Cookie “phpMyAdmin” wird bald als Cross-Site-Cookie gegen “http://127.0.0.1:59215/mywebsite/api/pages/blog/children” behandelt, da das Schema nicht übereinstimmt. children
Das Cookie “phpMyAdmin” wird bald als Cross-Site-Cookie gegen “http://127.0.0.1:59215/mywebsite/api//pages/blog/lock” behandelt, da das Schema nicht übereinstimmt. lock
Das Cookie “phpMyAdmin” wird bald als Cross-Site-Cookie gegen “http://127.0.0.1:59215/mywebsite/api//pages/blog/lock” behandelt, da das Schema nicht übereinstimmt. lock

I’m using the .htaccess file like the Kirby Starterkt 3.4.3.

[Added:]
Deleting the Cookie “phpMyAdmin” unfortunately changed nothing (except the omission of warnings…)
[/Added]

Yes :slight_smile: that is why i was blushing :slight_smile:

@pixelijn:

Now I have tested this with OLD Firefox versions:

Using FirefoxPortable_63.0.3_German (12/2018) and FirefoxPortable_75.0_German (04/2020), which I had downloaded from PortableApps.com: Mozilla Firefox, Portable Edition some time ago and which I now (to avoid browser updates) used offline and only locally (no internet access).

The result is the same, according to my (here) very little knowledge, it must have somehow causally to do with Kirby, here tested with Kirby 3.4.3 and PHP 7.4.10.

After several days of intensive search I found the cause of the error in my websites!
It is therefore the Kirby bug #2343, which is not really fixed in my experience.

It is still not possible to define something in the following way:

// file: /site/config/config.php
return [
  // ... other options
  'authorname' => [
    'pluginname' => [
      'optionkey' => 'value',
    ],
  ],
  // ... other options
];

But such a setting does not lead to an error message visible (e.g. in whoops) but in ignoring this setting by the panel, when I use the Kirby log plugin from @bvdputte!

Notes
This error is not attributable to the above mentioned plugin ‘kirby-log’! This is a great plugin, which I realy like.
I only want to help those, who receive the error message of this thread, with this information.

It would of course be helpful for all developers to receive an error message in such situations, which gives an indication of the cause.
@bastianallgeier: What do you think about this?

Hi I’m just currently facing this issue but its only happening on 1 single page. Anytime I try and save, I get this error. Any ideas?

I’m running Kirby 3.5.3 and PHP 7.4