How to make a post to an api?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
trax-x3
User
Posts: 3

How to make a post to an api?

Post by trax-x3 »

Hello, everybody.

First I would like to thank anyone who can help me in solving my problem. I understand very little of the programming logic, I have to pass data to an api, if I have the following example:

192.168.10.1:4443/devapi.php?username=api&password=5f4dcc3b5aa765d61d8327deb882cf99&apicmd=subscriber:addUser:online:-clientId=API001%20-firstName=API%20-lastName=Example%20-emailAddress=user@example.com%20-contactNumber=(012)3456789%20-password=123456%20-passwordConfirm=123456%20-package=P-512K%20-ipAddress=10.10.0.1%20-addrMsk=255.255.255.0

Since my customer table I have the same fields it is necessary to pass the api, if:

clientId
firstName
lastName
emailAddress
contactNumber
password
passwordConfirm
package
ipAddress
addrMsk

How can I do to when registering a new client he takes the field above and send through the api? and also when I click on edit.

Again thanks for the help :-)


mobhar
User
Posts: 11790

Post by mobhar »

Do you want to generate such link or catch all the variable from that link in your devapi.php file?


trax-x3
User
Posts: 3

Post by trax-x3 »

Hello mobhar

In case I need to pass all these variables to the link so that it can register the client, and when I edit the client it also pass these variables.

So when I click Add a new customer (after filling in all fields) it sends to: devapi.php located in a particular hostname the variables, and when I click to edit a customer he can also pass again to update the via client API.

Thanks


mobhar
User
Posts: 11790

Post by mobhar »

Then you need to pass all the variables using "Row_Inserting" server event while inserting data, or "Row_Updating" server event while updating data.


Webmaster
User
Posts: 9432

Post by Webmaster »

From your URL, it seems that the data is passed as URL parameters (not HTTP POST). In the server events (see Server Events and Client Script in the help file), build your URL and pass by cURL, e.g.

ew_ClientUrl("<YourHost>/devapi.php?username=api&password=" . urlencode($rsnew["password"]) . "&xxx=" . urlencode($rsnew["xxx"]) . "& ...other fields...");


trax-x3
User
Posts: 3

Post by trax-x3 »

In the case when I create a User filling all the fields in my registration and clicking Add, it will have to send the following command to the api:

192.168.10.1:4443/devapi.php?username=api&password=5f4dcc3b5aa765d61d8327deb882cf99&apicmd=subscriber:addUser:online:-clientId=API001%20-firstName=API%20-lastName=Example%20-emailAddress=user@example.com%20-contactNumber=(012)3456789%20-password=123456%20-passwordConfirm=123456%20-package=P-512K%20-ipAddress=10.10.0.1%20-addrMsk=255.255.255.0

And to edit the User this command:

192.168.10.1:4443/devapi.php?username=api&password=5f4dcc3b5aa765d61d8327deb882cf99&apicmd=subscriber:editUser:online:-clientId=API001%20-firstName=API%20-lastName=Example%20-emailAddress=user@example.com%20-contactNumber=(012)3456789%20-password=123456%20-passwordConfirm=123456%20-package=P-512K%20-ipAddress=10.10.0.1%20-addrMsk=255.255.255.0

In the first code (which registers the User) by what mobhar said he would be modified and would be placed in: Server Events> Table-Specific> Common> Row_Inserting

And the second code (used to edit the User through the api) would be modified and placed in: Server Events> Table-Specific> Common> Row_Updating

Could you help me by passing me how would complete the modified code for the two situations?

Remembering that as I commented at the beginning of the topic all the parameters I need to pass the api has the same name in the database, eg: need to pass the parameter clientId, he'll get the clientId of a field called clientId inside my table

Sorry for the inconvenience


Post Reply