REST API

Using the WordPress REST API, you can easily add or update mapped domains in Domain Mapping System.

Domain Mapping System takes advantage of the WordPress REST API to allow adding and deleting of domain mappings.

When Domain Mapping System is installed, by default, the REST API URL is available on your site at this kind of URL:

https://your-domain.com/api/dms/v1

Be sure to replace your-domain with your primary domain name configured on your WordPress site. This can be founder under the Settings > General tab in the WP-Admin Menu.

The API requires a Token Request for valid authentication. Then, you can add/update mappings as desired.

1. Token Request

Authentication to the REST API is facilitated via JSON Web Token (JWT).

First, you must request a token by logging in using the below endpoint and valid WordPress admin credentials.

When requesting the token by logging in, the new JWT will be generated for you and passed in response to the request.

The token will later be required to authorize all calls to the API using the Bearer Token authentication method.

The token is tied to the admin user account. If the admin user account is ever deleted, the token will no longer work.

POST /wp-json/dms/v1/token

--body { "user_name": "some-user@example.com", "password": "******" }

Request Body

NameTypeDescription

user_name*

string

WordPress Admin account username or email

password*

string

WordPress Admin account password

{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMSJ9.CLFgmmXt0xVKBMhkpy67ULD_d79-XFI0JtuiOMqAYMw"
} 

2. Add/Update Mapping

This request does not support bulk changes. You can add/update only one object per request. If the website is using the free version of the plugin, then you will not be able to add multiple values per mapping or set up a primary value. This means you cannot set up Microsites (or a Microsite homepage), which are paid features.

Free Version Request

POST /wp-json/dms/v1/mappings

--header Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMSJ9.CLFgmmXt0xVKBMhkpy67ULD_d79-XFI0JtuiOMqAYMw

--body { "host": "example.com", "value": 6 }

Headers

NameTypeDescription

Authorization: Bearer*

string

Token

Request Body

NameTypeDescription

host*

string

Desired mapped domain

value*

integer or string

Either post ID or category slug

{
    "message": "Successfully saved"
}

POST /wp-json/dms/v1/mappings

--header Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMSJ9.CLFgmmXt0xVKBMhkpy67ULD_d79-XFI0JtuiOMqAYMw

--body { "host": "example.com", "path": "some_path", "primary": 0, "value": 6 }

Headers

NameTypeDescription

Authorization: Bearer*

string

Token

Request Body

NameTypeDescription

host*

string

Desired mapped domain

path*

string

Valid URL path for subdirectory mapping

primary*

boolean

0 => Set as primary value and make this published resource the microsite homepage

1 => Not as not primary value

value*

integer or string

Either post ID or category slug

{
    "message": "Successfully saved"
}

Last updated