[Common Issue] Netlify CMS API_ERROR. Now what?

Failed to persist entry: API_ERROR: Reference update failed
  • You’re using the editorial workflow but already have a branch called cms. This error is fixed by removing the cms branch from the repo.

One of my writers has been experiencing intermittent 502 errors when saving articles, which doesn’t seem to be covered here yet…

The site is hosted on Netlify, the code is hosted on Github.

She copied the following from the console:

Uncaught (in promise) 
Object
error: API_ERROR at new t (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:142563) at new i (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:142870) at l.handleRequestError (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:512:27848) at l.request (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:159613) at async l.uploadBlob (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:55:8385) at async Promise.all (index 0) at async l.persistFiles (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:55:602) at async t.runWithLock (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:218:12733) at async K.persistEntry (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:28:83406) at async https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:48:59138
api: "Git Gateway"
message: undefined
meta: {}
name: "API_ERROR"
status: 502
stack: "API_ERROR↵    at new t (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:142563)↵    at new i (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:142870)↵    at l.handleRequestError (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:512:27848)↵    at l.request (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:159613)↵    at async l.uploadBlob (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:55:8385)↵    at async Promise.all (index 0)↵    at async l.persistFiles (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:55:602)↵    at async t.runWithLock (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:218:12733)↵    at async K.persistEntry (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:28:83406)↵    at async https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:48:59138"
__proto__: Error
payload:
collection: "articles"
error: API_ERROR at new t (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:142563) at new i (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:142870) at l.handleRequestError (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:512:27848) at l.request (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:51:159613) at async l.uploadBlob (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:55:8385) at async Promise.all (index 0) at async l.persistFiles (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:55:602) at async t.runWithLock (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:218:12733) at async K.persistEntry (https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:28:83406) at async https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js:48:59138
slug: "2020-11-23-xxx"
__proto__: Object
type: "UNPUBLISHED_ENTRY_PERSIST_FAILURE"
__proto__: Object

Any idea what’s going on here and what we can do about it?

Is it possible that her authentication token times out while she is authoring? She can tell by doing this experiment:

If when encountering the error, she goes to load the same URL that she shows while editing in another tab - does it work, or does it make her login again? If it makes her login again - does the NEXT save (after she logs in, and returns to original tab) work?

I see this on some of my sites and am very careful to save my work before the auth token expires (which on that site is once an hour, not sure if you have a similar setup or no - you could plug the contents of nf_jwt cookie into https://jwt.io to see what your expiry is)

Hi @fool, thanks for your response!

I ran into the same issue now myself so I had a chance to check the JWT token. It seems to also have a 1 hour expiry, however I’m getting the error while it’s still valid (currently 20 minutes since I logged in, and 40 minutes left on the clock according to jwt.io).

Opening the article editor in a new tab also doesn’t ask me to log in again (it just asks if I want to restore a local backup of the article).

Any other ideas?

(Note: when trying to click save again a minute or two later it worked just fine…)

Hi there! sorry to be slow to reply - there are quite a few API error issues on the Netlify CMS repo.

‘API ERROR’ is a common catch-all error message for a variety of different reasons.

Probably your best bet is to go and see if there is an issue that matches your circumstances - its possible there is a solution, or you are more than welcome to file a new one!

https://github.com/issues?q=is%3Aopen+is%3Aissue+API_ERROR++repo%3Anetlify%2Fnetlify-cms

Hi @perry,

can i ask what is the main reason here when im uploading a image in netlify cms it shows “Failed to persist media: API_ERROR” but its uploading in our github repo.

Thanks @perry!

Could this be because you have a clashing branch name, like in post 2 of this topic?

What do you mean @Scott?

That particular error you’re seeing, it sounds a bit like:

@Scott @aaronrye12 this issue is already being handled in a separate topic:

1 Like

Thanks for the signposting, Tom!

1 Like

This is super helpful, thank you, but has anyone encountered “Failed to persist entry: API_ERROR: Validation Failed”?

It doesn’t affect all of my posts, only one in the collection. There is another message about it on this board however the resolution of the issue was not posted: Netlify CMS: 'Failed to persist entry: API_ERROR: Validation Failed' - #2 by hrishikesh

Thanks for reaching out! Let’s continue the conversation on the thread you linked (also here) in order to streamline support!

Hello, what if the error is simply “Failed to persist entry: API_ERROR” with none of the text in your examples (“Not Found” / “Validation Failed”)?

This pops up when trying to add a first entry to a collection.

@cobbie Have you set the right branch in your config?