Skip to content
Advertisement

How to use PHP function into API Blocks with ConfigureIT

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.

Advertisement

Answer

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'] = "abc@xyz.com"; //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.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement