Search code examples
javascriptjsonreststrapi

Not able to fetch json data from a "SINGLE-TYPE" content-type in strapi


I used strapi as my backend for all my data flow, I created single-type content, this single type has different components attached to it. After configuring all the single-types, I tried to fetch the data through rest Api, But I didn't got the json data as a response.

This is my json response

This was the json response

This is my single-type structure

This is my single-type structure


Solution

  • So to get back all the data from the "single-type" the following procedure are:

    • After creating the single-Type content, Go to the settings of the strapi admin page and then click the Role option.

    • Click on the public tab.

    • locate permissions tab and search for the single-type you created and click on the single-type tab.

    • Then you will find the permissions for that single-type, tick on find option, there are other option too, tick it as per your needs.

    • After that you will see a api endpoint on the right side of the screen for that particular single-type.

    • Copy that endpoint.

    • Use your browsers or any api client like Postman etc to test the api endpoint.

    Now the Main Trick comes here

    To get the result of the end point you have to type something like this:

    http://localhost:1337/api/"your single-type name"?populate=*

    This above code will list all the components and all its data inside of it will be displayed in the json response.

    NOTE:

    If there is any image data or any other media files inside the component it won't be displayed, so to to get that also along with other data you need to type:

    http://localhost:1337/api/"your single-type name"?populate[your component name which contains that image data][populate]=*

    When you type the api endpoint url your single-type name should be without double quotes

    Follow this link : For More Information regarding how to handle the rest api in strapi