Skip to content

Example Calls

Adam Anderly edited this page Feb 15, 2017 · 21 revisions

Usage Examples

Initialize the OData Client

// Using the example OData service from odata.org
$odataServiceUrl = 'http://services.odata.org/V4/TripPinService';
$odataClient = new ODataClient($odataServiceUrl);

// Need to authenticate the requests to the service? Pass in a Closure as the second argument
// which will get passed the request object 
// Access token retrieved from an oauth
$accessToken = 'abc';
$odataClient = new ODataClient($odataServiceUrl, function($request) {
    $request->headers['Authorization'] = 'Bearer '.$accessToken;

});

Get a collection of items

// Retrieve all entities from the "People" Entity Set
$people = $odataClient->from('People')->get();

Get a specific item from a collection by ID

// Or retrieve a specific entity by the Entity ID/Key
$person = $odataClient->from('People')->find('russellwhyte');
echo "Hello, I am $person->FirstName ";
Clone this wiki locally