Hello! Since Friday from last week I have been getting an error due to "An invalid API response was returned".
With this error it is not possible to build the website.
I also saw that the slice-machine version for this project was old so I updated it. The "sm.json" file was deprecated so when I updated the slice-machine package to the latest version the "slicemachine.config.json" file was created successfully, but as a consequence of this update I lost a good amount of slices... The slice-machine localhost does not detect some slices after this update, even though, I can still see them and their corresponding "model.json" file in my code base.
Any further help with this problems would be greatly appreciated.
Thank you in advance,
Nuno
@nunopereirasousa00,
It has been my experience that when you upgrade your packages and then run dev, their script does create the appropriate slicemachine.config.json file as you mentioned, but it does not then adjust your prismicio.js
Check that your prismicio looks similar to the following:
import * as prismic from '@prismicio/client'
import * as prismicNext from '@prismicio/next'
import config from './slicemachine.config.json'
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName
//
// your route stuff goes here...
//
export const createClient = (config = {}) => {
const client = prismic.createClient(repositoryName, {
routes,
...config,
})
prismicNext.enableAutoPreviews({
client,
previewData: config.previewData,
req: config.req,
})
return client
}
Your slicemachine.config.json should be similar to this:
{
"apiEndpoint": "https://your-repo-here.cdn.prismic.io/api/v2",
"repositoryName": "your-repo-here",
"adapter": "@slicemachine/adapter-next",
"libraries": ["./slices"],
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
}
Does that help in any way?
1 Like
@nf_mastroianni thank you for the response! Seems like in the code I had "config.apiEndpoint" and not "config.repositoryName". I can't really check atm if the "An invalid API response was returned" error is fixed with this change because I still have a lot of slices missing. Meaning if I build the website again, if the error no longer exists, the website will be deployed without the missing slices.
Regarding this issue, when I am at the "Changes" tab in http://localhost:9999/slices, sometimes one of the missing slices appears and then suddenly disappears. Is there any way to get these back? As I said before, I can still see the missing slices in the "slices" folder in my code base, just not at http://localhost:9999/slices. I don't know if this might be connected, but right after I updated the slice machine in this project, the localhost loses connection with the Prismic authentication quite often.
Wow, that seems very strange about how they appear and disappear like that. It is my understanding that if the data are present in your models files, you should be safe. Could this be a browser/caching issue? If you cleared your cache or tried another browser? Also, when strange things like this happen, I've found that deleting the .next directory and then running dev again helps.
Already cleared cache and deleted the .next folder and still the same.
Yes it is super weird... basically when I click for the first time in the "Changes" tab sometimes it shows me either a slice with the "New" tag, which was created and published months ago, or the missing slices. If I click refresh they disappear from the "changes" tab right away.
Have you tried spinning up a new prismic repo and project using
prismic theme --theme-url https://github.com/yourGitHubUserName/YourGitHubRepoName
Might be worth it to see if the slices/types are all faithfully recreated
I was able to get the slices back. I installed again the slice-machine version I had initially - 0.5.2 - and the slices missing appeared, but I still see "An invalid API response was returned" when building the website. Could this be related to the 'Your request count (151) is over the allowed limit of 150.'? (as it shown on the first image I uploaded). I already have the prismicio.js file as you have it above.
@nunopereirasousa00,
I'm happy to see you were able to resolve the missing slices issue. I've not seen a error message like you describe.
Is the error related just to your sitemap? I feel like it's really hard to figure this out with the info that I have.
1 Like
Yes it was the sitemap file. For some reason there was "config.apiEndpoint" instead of "config.repositoryName" in this file. Not sure why this error appeared after successfully building the website so many times for so long with "config.apiEndpoint".
Anyway, thank you so much @nf_mastroianni!
1 Like