Fix: WP REST api import / schedule

New home Forums Pro Add-on Troubleshooting Fix: WP REST api import / schedule

Tagged: , , ,

This topic contains 0 replies, has 1 voice, and was last updated by  samfitzpatrick 7 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #48926

    Hey,

    I couldn’t find this information in the documentation or in a search of the forums

    I experienced a problem when creating a custom WP REST endpoint that serves up custom field data for map markers. I would get through the first part of the import, where it would verify the data structure and ask the map and which other information to import (markers etc), so I believe it knew the data was there and readable. However, I only got an error when actually performing the last stage of the import.

    I saved the raw json data from the endpoint as a JSON file then uploaded this, it worked. So I knew the data integrity wasn’t an issue. After some trial and error, I discovered appending ‘.json’ to my custom endpoint URL resolved the issue e.g

    register_rest_route( 'your-route/v1', '/maps.json', array(
                    'methods' => 'GET',
                    'callback' => 'your_function'
    ) );

    Hopefully, this helps someone and saves some time.

    #48931

    Perry
    Moderator

    Hi there

    Thank you very much for bringing this to our attention.

    This is due to WordPress’ mime type security policies – It will refuse to open a directory or files with a .php extension. Your solution is ideal, I’d perhaps improve on that by changing the suffix to ?.json so that appears as a query variable rather than part of the route.

    Thank you for your input!

    Kind regards
    – Perry

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.