toannk
3/16/2017 - 2:54 PM

test.php

<?php
$userData = array('username' => 'admin', 'password' => '123123q');
$ch = curl_init('http://magento2.vagrant192/rest/V1/integration/admin/token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Lenght: ' . strlen(json_encode($userData))));

$token = curl_exec($ch);
$ch = curl_init('http://magento2.vagrant192/rest/V1/cs_oauth_token/consumer');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['consumer' => ['name' => 'villageghost1', 'email' => 'vg.test.info@gmail.com', 'endpoint' => 'http://vg.dev/oauth.php', 'identity_link_url' => 'http://vg.dev']]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . json_decode($token)));

$result = curl_exec($ch);

echo '<pre>';
var_dump($result);
print_r(json_decode($result));