Event Registration Mechanism


Wordapp has an event (hook) mechanism for third-party services or sites. Currently in Wordapp there is only one event name such as "task_approved" that it is triggered after the completion of a task. As a third-party service you might want to be informed after a is task completed. The only thing you should do is to be registered to the "task_approved" event.  

First of all you need to create an application in order create "access token"(see here).

In addition, see here how to make an API call by scrolling down to "Make authenticated requests".


Events

1.Subscribing to an event

Parameter
Description
Required
target_urlA url in order to send data to target endpointYes
eventThe event name to be subscribedYes
project_idIf event name is "task_approved" "project_id" should be given. This should be an array.No
Sample Call
POST /api/event_hooks HTTP/1.1
Host: app.wordapp.io
Authorization: Bearer access token
X-Api-Version: api version
Content-Type: application/json
{ "target_url":"http://example.com",
 "event"task_approved",
 "project_id":['project_id_1', 'project_id_2'],
}
Sample Output
Status: 201
[
 { "id": "58089723a83ab103c0c8abfd" }
]


If the process is invalid, then errors are returned with a 422 status code. An output is returned with the status code of 201, and it contains an "id" that is an event id. You should store this "id" somewhere in your database in order to unsubscribe later, by "unsubscribing from an event" which is covered below.


2. Unsubscribing from an event

Parameter
Description
Required
idEvent Id that should be included at end of url. See upward.Yes
Sample Call
DELETE /api/event_hooks/58089723a83ab103c0c8abfd HTTP/1.1
Host: app.wordapp.io
Authorization: Bearer access token
X-Api-Version: api version

There is a returned output with status code of 200 without no content. If the process is invalid then errors returned with 422 status code. 


3. How it works

Say that you have a blog related to "cars" built with Wordpress. You want to upload contents related to "cars" which are produced on Wordapp, but you don't have time to upload tons of content manually. Don't worry, Wordapp does it for you thanks to its hooking mechanism. What you should do here is subscribe to the "task_approved" event, due to fact that you want your contents to be uploaded after the content (we call it task) is approved by publisher. After subscribing to the "task_approved" event which is explained above, Wordapp will trigger your given "target_url" with a bunch of data. That endpoint should accept POST request and accept "application/json" header owing to fact that Wordapp sends data in JSON format. In the following Wordapp's events and related sample requests are listed. The target endpoint should send a 200 status code each time. 

task_approved: 

POSThttp://example.com/hook/wordapp
Sample Call
POST /hook/wordapp HTTP/1.1
Host: example.com
Content-Type: application/json
{ "id":"5624cb4c0d5b04191100000b",
 "approval_time":Mon, 25 Jan 2016 16:43:19 UTC +00:00,
 "main_keyword":"polo tişört",
 "keyword_url":"http://www.dc.com.tr/golf-k-yafetleri",
 "sub_keywords":"polo tişörtler, yakalı tişört",
 "content":"Sample content goes here",
 "approval_status":"Approved",
 "text_1":"Polo shirt",
 "type_1":"h1",
 "text_2":"",
 "type_2":"h2",
 "text_3":"",
 "type_3":"text",
 "text_4":"",
 "type_4":"h2",
 "text_5":"",
 "type_5":"text",
 "text_6":"",
 "type_6":"title",
 "text_7":"",
 "type_7":"description",
 "project_name":"Decathlon",
 "language":"tr_TR"}