Use SmartCrawl API in React

I'm wondering if it will be simple to use the API to grab the SmartCrawl data to put into the React site, so we can still use SmartCrawl as a GUI for SEO, thanks in advance.

  • Adam Czajczyk
    • Support Gorilla

    Hi netn8

    I hope you're well today and thank you for your question!

    I've asked our developers for consultation on this as I'm not really familiar with React myself (so I don't quite know what would be necessary to make them work together). I'm awaiting their response and I'll update you here as soon as I get to know more.

    Please note: developers' response time might be a bit longer than ours here on forum so I'd appreciate some patience. I will, however, let you know immediately once I got information from them.

    Best regards,
    Adam

  • netn8
    • WPMU DEV Initiate

    Thanks so much Adam. Basically just looking for API calls or endpoints where we can grab the same data that SmartCrawl inserts into posts and pages on the WordPress site, so we can insert it into a static version of the React site.

    Have a terrific Tuesday,

    -Nathan

  • Adam Czajczyk
    • Support Gorilla

    Hi netn8

    Thanks for your response!

    I already had an "initial" talk to our developers and I got additional questions, if you don't mind :slight_smile:

    They say that "the answer depends on how the React system is implemented" and are asking - I'm passing the question literally - which API is used, is it the one that comes with WP or something additional/custom?

    Best regards,
    Adam

  • netn8
    • WPMU DEV Initiate

    Hi Adam,

    They are using the standard Wordpress REST API to grab post content and pull it into the React site. They're also using Prerender to serve static HTML to the bots.

    I would have thought that the SmartCrawl data would be part of the meta objects that get returned with the post type endpoint, but the developers on my end are asking how they can grab the SEO data with React. I'm just the SEO person, so hoping you could provide some insight.

    Thank you.

  • Adam Czajczyk
    • Support Gorilla

    Hello netn8

    Thank you for this additional explanation!

    I got confirmation from our developers that you're actually correct: we store our data as standard post meta so you should be able to retrieve it using standard WP Rest API. Post endpoint response does contain meta fields.

    That basically means that you shouldn't need to pull any additional data or do it in any non-standard way - a standard retrieval of the post you're working with should contain necessary data.

    However, if you're experiencing some troubles with it, could you please ask your developers about the details of these specific issues during retrieval? An example of the code that they are using could also be helpful.

    I'd then pass it on again to our developers and I'm sure we can find the "way out" :slight_smile:

    Best regards,
    Adam

  • netn8
    • WPMU DEV Initiate

    Hello again Adam,

    Still waiting on a response for this. Could you give me an example API call that your developers would use to grab the Smartcrawl meta data? Speciifically we're looking for title, description, keywords, open graph cards, and twitter cards.

    Thank you,

    -Nathan

  • Adam Czajczyk
    • Support Gorilla

    Hello netn8

    I'm sorry for delayed response on my end!

    I got a feedback from one of our developers who checked that and apparently the response does not indeed contain meta data by default. There's, however, a simple solution to this that should do the trick.

    If you add this code to your site (e.g. via current theme's "functions.php" file):

    register_rest_field( 'post', 'metadata', array(
        'get_callback' => function ( $data ) {
            return get_post_meta( $data['id'], '', '' );
        }, ));

    a standard call for a post should now return all the data, including all meta data - so also including all SmartCrawl data related to the post.

    Give it a try, please, and let me know if it worked for you.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.