Sample Code and WordPress Developer Hook to integrate the API connection.

For GET request without dynamic header:

Example: API : http://<domain>/wp-json/wp/v2/posts

SAMPLE CODE:

$value1 = 'myapi'; //API Connection Name
$value2 = ''; //Passed as empty string
$value3 ='';//Passed as empty string

$value = apply_filters('ExternalApiHook', $value1, $value2, $value3); //$value is the response of the External API request.

 

For GET request with dynamic header:

 

Example: API : http://<domain>/wp-json/wp/v2/posts Header: Authorization: Bearer djdwdmqwod

-So the Sample PHP code will be:

SAMPLE CODE:

$value1 = 'myapi'; // API Connection Name
$value2 = ''; //Passed as empty string
$value3 =array();//Array of Dynamic headers
value3['Authorization'] = "Bearer djdwdmqwod";

$value = apply_filters('ExternalApiHook', $value1, $value2, $value3); //$value is the response of the External API request.

For POST,PUT,DELETE request without dynamic header:

  • This hook is used to redirect the user to the particular url after they are logged in.

Example: API : http://<domain>/wp-json/wp/v2/posts Body Parameters : <key1:value1>;<key2:value2> ….

SAMPLE CODE:

$value1 = 'myapi'; //API Connection Name
$value2 = array(); //Array of Body Parameters
$value2['key1'] = $value2['value1']’;
$value2['key2'] = $value2['value2']’;
$value3 = ''; //Passed as empty string

$value = apply_filters('ExternalApiHook', $value1, $value2, $value3); //$value is the response of the External API request.

For POST,PUT,DELETE request with dynamic header:

Example: API : http://<domain>/wp-json/wp/v2/posts Body Parameters : <key1:value1>;<key2:value2> …. Header: Authorization: Bearer djdwdmqwod

SAMPLE CODE:

$value1 = 'myapi';  //API Connection Name
$value2 = array();  //Array of Body Parameters
$value2['key1'] = $value2['value1']’;
$value2['key2'] = $value2['value2']’;
$value3 = array();
value3['Authorization'] = "Bearer djdwdmqwod";

$value = apply_filters('ExternalApiHook', $value1, $value2, $value3); //$value is the response of the External API request.