• Resolved JimBurke

    (@jimburke)


    I have a problem which I can’t find any specific answer, so I hope someone can help.

    The problem is that I want to create a JSON interface so that an external application can enquire internal data and also update internal data. I’m not interested in searching/creating posts etc.

    This is a WP site which uses Gravity Forms and an external MySQL db for the tournament data. It is a Billiards tournament management site and is located at – https://wbeventsonline.com/

    The important point is by “internal data” I mean a MySQL db external to the normal WP db. The MySQL db actually sits alongside the WP one, probably same server. PHP code accesses both db’s.

    Ex1: The external app wants a list of tournaments from our site. I want to respond to this request and send back something like the data in – https://wbeventsonline.com/?page_id=130 in a JSON object.

    Ex2: The external app wants to update the score in a particular match. I want to take the JSON request, extract the data and update our external db with this.

    I realise that ex1 is a GET and ex2 an UPDATE operation.

    Is there an easy way to implement this ?

    I will be most grateful for a helpful reply.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Ideally your external app would directly query the external DB. There’s little point in involving WP if that’s feasible. Obviously the app would need proper DB credentials to access it, which could introduce security concerns, depending upon the exact implementation. Running requests through your WP site could add an extra layer of security, but the challenge remains in allowing access without disclosing secret credentials.

    You could create custom WP API routes and endpoints to handle client requests and the WP server could query the external DB to get or update any data. Application passwords are the simplest way to authenticate API requests, but keeping them secret remains a challenge. You should look at oAuth or JWT authentication methods for any WP API when dealing with client apps.

    Thread Starter JimBurke

    (@jimburke)

    I probably wasn’t clear about db access. I plan to run php code which does the actual db access, not the external app. My php code would therefore interface with the API. My problem is this interface I think.

    I’ll have another look at custom WP API routes and endpoints.

    Many thanks.

    Thread Starter JimBurke

    (@jimburke)

    Created a route and got some data coming through now. Usual formatting problems, but solvable.

    Thanks for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.