Updates a single record via POST request.
Data is passed as key-value pairs in the body of the request. Fields to be updated are sent as fieldname=value&fieldname1=value1 list.
Arguments
table
the table name.
action
update
editid1, editid2, ...
key column values, the way they are defined in PHPRunner on Choose pages screen.
field1, field2, ...
field values to update the record
Example 1
Update customer with CustomerID (key column) KOENE setting ContactName to be Bill Gates.
curl -X POST "http://localhost:8086/api/v1.php?table=customers&action=update" -d "editid1=KOENE&ContactName=Bill Gates" -H "Content-Type: application/x-www-form-urlencoded"
Sample success response:
{
"success": true
}
Example 2
Update a table that has two key columns. The easiest way to approach this is to open the Edit page of the table in question in a web browser first. For instance, we have Order Details table with two primary key columns, OrderID and ProductID. The URL of an Edit page looks like this:
order_details_edit.php?editid1=10252&editid2=60
As we can see, we need to specify editid1 parameter (OrderID) and editid2 parameter (ProductID). So the sample REST API update call looks like this:
curl -X POST "http://localhost:8086/api/v1.php?table=order%20details&action=update" -d "editid1=10252&editid2=60Quantity=30" -H "Content-Type: application/x-www-form-urlencoded"
Sample success response:
{
"success": true
}
Sample code
Updates the record in the customers table where CustomerID (key column) is KOENE setting ContactName to be Bill Gates
PHP code:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost:8086/api/v1.php?table=customers&action=update",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('editid1' => 'KOENE','ContactName' => 'Bill Gates'),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
C# code (using RestCharp):
var client = new RestClient("http://localhost:8086/api/v1.php?table=customers&action=update");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AlwaysMultipartFormData = true;
request.AddParameter("editid1", "KOENE");
request.AddParameter("ContactName", "Bill Gates");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
JavasScript code (jQuery):
var form = new FormData();
form.append("editid1", "KOENE");
form.append("ContactName", "Bill Gates");
var settings = {
"url": "http://localhost:8086/api/v1.php?table=customers&action=update",
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});