Example to do a POST command in REST API with PHP

Posted by Rollbase User on 28-Feb-2011 18:19

Can anybody provide an example of how to use the POST methods of REST API in PHP? I am able to do the GET methods (getDataField, etc.), but whenever I try a POST method (create, update) I am unsuccessful. The latest error I am getting is "Cannot parse XML input: ". Here's the PHP code:  The results from the above code is:  I've tried different methods of defining the XML [ $xml = simplexml_load_string($string); ] but I am getting the same error. Thanks

All Replies

Posted by Admin on 28-Feb-2011 19:04

I confirm that PHP curl request does not go through REST server. I will investigate and fix the problem ASAP.

Posted by Admin on 02-Mar-2011 19:14

I've added another implementations for these APIs - create2 and update2. They take HTTP parameters only, no XML. Please let me know how this works for you (you still need to use POST).

Posted by Admin on 03-Mar-2011 18:14

I tried again using update2 and a parameter string instead of XML. Now I am getting an "OK" status - but the update was never actually performed. I even tried changing the query string to try an invalid field name and it still returns "OK". I may be doing something wrong as I'm not too familiar with curl.

Code:



/*
* LOG IN
*/
$uname = "MY_USERNAME";
$pword = "MY_PASSWORD";

echo "\n\nLogging in...\n";
$url = 'http://www.rollbase.com/rest/api/login?loginName='.$uname.'&password=' .$pword;

$session = curl_init($url);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
$respXML = new SimpleXMLElement($response);
$sessionID = $respXML->sessionId;
echo "-->Logged in // SESSION ID: " . $sessionID;


/*
* UPDATE RECORD
*/
echo "\n\nUpdating record....";
$url = 'http://www.rollbase.com/rest/api/update2?sessionId=' . $sessionID;
$params = '&id=14270115&&useIds=false&fieldName=name

Posted by Admin on 03-Mar-2011 18:23

I've also tried updating regular text fields and picklist fields - with the same result. It says "OK" but when I look at the record in Rollbase or with getDataField it has the original value.

Posted by Admin on 03-Mar-2011 18:36

May be I did not make documentation clear enough: you should use pairs like

&admin_test_field=RESTUpdated

Actual parameter name is your field's name. If parameter's name is invalid the system will ignore it.

Are you trying update just a single field? I will provide setField API for that.

Posted by Admin on 03-Mar-2011 18:41

Ah, OK. That works.

Thanks!

This thread is closed