After adding an API to the Setup page, you will see that the API now gets its own tab – clicking on the tab will take us to the Endpoint page as shown below.
We can see that this page shows the Base URL that we set up in the Setup page.
It also shows the Template Tag and Shortcode that will be used for each endpoint as well as a Test Endpoint button.
You can add unlimited endpoints within the endpoint page, simply by clicking the Add Endpoint button.
Let’s look what each field does within the endpoint page.
Unique ID field
The Unique ID field is used to identify an endpoint within the shortcode or the template tag. If you are using multiple different endpoints, then you must ensure this is unique.
It is usually a good idea for the Unique ID to be the same name as the endpoint.
In the example below, the endpoint is ‘/random’ so we have set the Unique ID as random.
We can also see how this Unique ID is used within the shortcode and template tag. It is used to identify the endpoint.
Endpoint field
The Endpoint field is used to add the endpoint. This endpoint will be appended to the Base URL to form a complete URL that will be called when using this endpoint. You can find the endpoint details within your API’s documentation.
This field should begin with a /
Method field
The Method field is a drop down with the following options: GET, POST, PUT
This is used to set the desired request method for your API call. You can find this within your API docs.
Results Format field
The Results Format field determines the output of the API data. By default there are 2 options: PHP array data or JSON string and the format you choose will largely depend on how you are going to use the returned data.
JSON string
When set to JSON string, the output will look something like the below.
PHP array data
When set to PHP array data, the output will look something like the below.
As a rule of thumb, set this to JSON string when you are using the shortcode and set to PHP array data when using the template tag.
Query String fields
You can add unlimited query string parameters using the Query String name/value fields.
We have a detailed article on these fields here: https://wpgetapi.com/docs/adding-query-string-parameters/
Headers fields
You can add unlimited header parameters using the Headers name/value fields.
We have a detailed article on these fields here: https://wpgetapi.com/docs/sending-headers-in-request/
Body POST fields
You can add unlimited body POST parameters using the Body POST name/value fields.
We have a detailed article on these fields here: https://wpgetapi.com/docs/sending-post-fields-in-request/
Encode Body field
This field is only used when you are sending data in the Body POST fields and the Request Method is set to POST or PUT. You will need to choose the option that your API says to use in the API documentation. If your API docs do not mention the type, you can experiment to see which one will work.
The options for this field are:
- No encoding
- JSON encode
- URL encode