I am creating API's using the api builder on Configure.It. can anyone explain me how to use the php custom function in the api block.
How to add API function to a simple PHP Page ? Application Programming Interface is a system that contains a set of rules or protocols or tools which help in providing interaction between two applications or software by standard data access. It is very much similar to a web service used in developing web pages or mobile apps.
PHP User Defined Functions Besides the built-in PHP functions, it is possible to create your own functions. A function is a block of statements that can be used repeatedly in a program. A function will not execute automatically when a page loads.
Get an API key: When you start with APIs, you should register and get a key which is a string of letters and numbers. This API key is only used while making a request so that the server API recognizes the user as a registered user. Test API with PHP applications: This process checks if everything works as expected.
Using API with PHP cURL: 1 Get an API key: When you start with APIs, you should register and get a key which is a string of letters and numbers. 2 Test API with PHP applications: This process checks if everything works as expected. 3 Develop the required PHP app by using API. Create or develop the application by using necessary APIs. More ...
Hello Nitish,
Please check below comments. Hope it will helpful for you.
In API Configuration we can add php function in following blocks.
A. Query Block (For selection, insertion and updation)
B. Custom Function Block
C. Variable Block
D. API Connector
Php function in these blocks uses for different purpose.
Query Block
In query block, php function is uses for modifying the current value of the record. It can be use for insert, update and select.
If query type is select then first record will fetch from the table and after that php function will execute, so modified value will use for further process.
If query type insert or update, first php function will execute and then modified value will store into table.
Input Parameter :: Here two input parameters will send to the function.
$value :: Current Value of that specific Field
$dataArr :: Data array of current record
Output Parameter :: Only value will return from the php function which will use for further process.
Custom Function
For any type of customization, you can use Custom Function. Using custom function you can return two types of values ::
Single Dimensional Array
Multi Dimensional Array
In Custom Function, you can get all the input parameters of working API into one parameter i.e. $input_params .
Example :: Suppose you have input param user_id then it will get using $input_params['user_id'].
You need to specify the output parameters in the custom function block, these output parameter will use to store customized data.
Example :: Suppose you have specified email and name into output parameters then you can return those values like below:
$ret_arr['name'] = "XYZ"; // modified values
$ret_arr['email'] = "[email protected]"; //modified values
return $ret_arr;
Variable Block
In variable block, php function is used to assign value to the variable
Input Parameter :: Here two input parameters will send to the function.
$input_params :: all API parameter will be available in this parameter
$index_val :: If variable is using inside loop then you can get current index value of loop.
Output Parameter :: Any value or array can be return as value of variable.
External API
In external API response we can use both PHP defined default functions or custom created functions.
As of now PHP defined functions works with single argument only, if you want to do more functionality with that value you can create custom PHP Function and use that function in API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With