REST API Extended – Managing Creatives

Note: This article relates to the REST API Extended pro add-on.

REST API Extended adds three endpoints, one each for creating, editing, and deleting creatives on top of the two read-only endpoints already available in AffiliateWP core.

All five endpoints leverage the same two route patterns:

  1. creatives – When sent a GET request, a list of creatives are returned and can be filtered with additional arguments. When sent a POST or PUT request, a new creative can be created.
  2. creatives/[id] – When sent a GET, PATCH, or DELETE request, a single creative can be retrieved, edited, or deleted, respectively.

Both routes can also accept generic OPTIONS requests, which can be very helpful for discovering information about available endpoints, accepted request types and arguments, and item schema.

Whether you're planning to read, write, edit, or delete creatives, this add-on makes it possible.

All requests must be authenticated using API keys, which are generated and managed via the Affiliates → Tools → API Keys tab. Check out the REST API - Authentication article for more information.


Creating a Creative

Creatives can be created by sending a POST or PUT request to the creatives route:

https://example.com/wp-json/affwp/v1/creatives

The create endpoint accepts any of the following affwp_add_creative() arguments:

  • name – (integer) Name label for the creative.
  • description – (string) Description of the creative.
  • url – (string) URL to point the creative to.
  • text – (string) Text to display with the creative.
  • image – (string) Image URL to associate with the creative.
  • status – (string) Creative status. Accepts 'active' or 'inactive'. Default 'active'.

Creating a creative:

Method: PUT/POST
Endpoint: https://example.com/wp-json/affwp/v1/creatives/?name=New+Creative&text=REST

The new creative, named "New Creative" would contain text "REST".

Example response:

{
  "creative_id": 20,
  "name": "New Creative",
  "description": "",
  "url": "",
  "text": "REST",
  "image": "",
  "status": "",
  "date": "2017-01-26 09:25:05",
  "id": 20
}

Editing an Existing Creative

Single creatives can be updated by sending a POST or PATCH request to the creatives/[id] route:

https://example.com/wp-json/affwp/v1/creatives/[id]

The edit endpoint accepts any of the following affwp_update_creative() arguments:

  • name – (integer) Name label for the creative.
  • description – (string) Description of the creative.
  • url – (string) URL to point the creative to.
  • text – (string) Text to display with the creative.
  • image – (string) Image URL to associate with the creative.
  • status – (string) Creative status. Accepts 'active' or 'inactive'.

Updating a Creative

In this example, we'll update a creative's status from active to inactive.

Method: POST/PATCH
Endpoint: https://example.com/wp-json/affwp/v1/creatives/20?status=inactive

Response:

{
  "creative_id": 20,
  "name": "Creative",
  "description": "",
  "url": "http://affiliate.dev",
  "text": "AffiliateWP Plugin Testing",
  "image": "",
  "status": "inactive",
  "date": "2017-01-26 09:25:05",
  "id": 20
}

Deleting a Creative

A can be deleted by sending a DELETE request to the creatives/[id] route:

https://example.com/wp-json/affwp/v1/creatives/[id]

The delete endpoint accepts no additional arguments. When a creative as been successfully deleted, a key/value pair of deleted: true will be included in the response, along with a copy of the old creative response.

Example request:

Method: DELETE
Endpoint: https://example.com/wp-json/affwp/v1/creatives/20

Response:

{
  "deleted": true,
  "previous": {
    "creative_id": 20,
    "name": "Creative",
    "description": "",
    "url": "http://affiliate.dev",
    "text": "AffiliateWP Plugin Testing",
    "image": "",
    "status": "inactive",
    "date": "2017-01-26 09:25:05",
    "id": 20
  }
}