2

We manage a catalogue website that displays objects the client manages in a 3th party application. The objects in the catalog are a CPT, created and updated via the API from the 3th party application. Currently, the API is called every 30 mins, collecting information of the objects with a 'last change' timestamp of the last 30 minutes. (+ a manual update button) Far from great, and we had issues with certain actions not triggering the last change timestamp or taking them out of the API, so no update (remove the object) could be made.

The 3th party application had an update to their API and introduced Webhooks. Now we can create webhooks in their portal and send a signal if an object is updated or has a specific status change.

We need to make a couple of changes to the existing plugin to start to make use of the new webhooks.

The webhook posts a JSON object, containing a signature, an object URL, and an eventtype. We can store the signature in the plugin settings, like the API key. And use the object URL to call the API and use the existing code to process the updated information to take the object offline.

We need to create a URL where the webhook can post to, and from there, use the plugin functions and check against the signature.

How can we create this URL with the plugin?

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Commented Aug 23 at 11:46

1 Answer 1

2

you can create a new API route like that :

add_action("rest_api_init", function () {
    
    register_rest_route(
          "test_api"
        , "reading_http_json"
        , [
            "methods" => WP_REST_Server::EDITABLE, // POST PUT PATCH
            "callback" => function (WP_REST_Request $request) {
                
                $body = file_get_contents("php://input");
                
                $json = json_decode($body, TRUE);
                
                
                // here you have data in the array $json
                
                
                
                return NULL;
                
            },
            "permission_callback" => fn (WP_REST_Request $request) => TRUE,
        ]
    );
    
    
});

You give the url https://server/wp_directory/wp-json/test_api/reading_http_json in their portal and then you receive the data in the array $json.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.