Skip to content

Instantly share code, notes, and snippets.

@dlively1
Last active December 26, 2021 17:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlively1/5858513 to your computer and use it in GitHub Desktop.
Save dlively1/5858513 to your computer and use it in GitHub Desktop.
Sugar 7 Web Services using Guzzle PHP
<?php
require_once 'vendor/autoload.php';
use Guzzle\Http\Client;
$user = '<<user>>';
$password = '<<password>>';
$url = '<<baseurl>>/rest/v10/';
$client = new Client($url);
$request = $client->post('oauth2/token', null, array(
'grant_type' => 'password',
'client_id' => 'sugar',
'username' => $user,
'password' => $password,
));
$results = $request->send()->json();
$token = $results['access_token'];
$request = $client->get('me');
$request->setHeader('OAuth-Token', $token);
$currentUser = $request->send()->json();
var_dump($currentUser);
{
"require": {
"guzzle/guzzle": "~3.7"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment