Using RESTClient to post data

The RESTClient explained in the earlier post https://varunver.wordpress.com/2013/02/13/php-restclient-and-exception-handling/ can be used to post data to the server

1. POST request to send JSON file

<?php
require_once '/Path_To/RESTClient.php';
$client = new RESTClient;

//Calling the Salesforce API directly and passing json file as post payload
$response = $client->postJsonFile("http://server-name/api/results.php", '/var/www/api/data.json');
echo $response;
?>

2. POST request to send JSON data

<?php
require_once '/Path_To/RESTClient.php';
$jsonData = '{"api" : "SFOBJOWNER",
"obj" : "account",
"flds" : "name,customer_number__c,phone,company_size__c",
"limit" : 10
}';
$client = new RESTClient;
//Calling api home which determins which API to pass on to
$response = $client->post("http://server-name/api/index.php", $jsonData);
echo $response;
?>

3. GET request to send array

<?php
require_once '/Path_To/RESTClient.php';
$params = array("api" => "SFOBJOWNER",
"obj" => "account",
"flds" => "name,customer_number__c,phone,company_size__c",
"limit" => "5");
$client = new RESTClient;
//Calling api home. index.php determines api based on param ['api']
$response = $client->get("http://server-name/api/index.php", $params);
echo $response;
?>
Advertisements
Posted in PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s