Consume API created with apigility

Hello all

I’m a bit new when it comes to API’s, so please forgive me if this question is a little lame.

I need to create an API for various reasons.
On a friend’s recommendation, I am using apigility to create the API.
Now, I need to consume it.

On another friends recommendation, I am using Guzzle 6 to consume API’s.
I’ve tested it out and it seems to work.

I tried to consume a test API that I created with Guzzle, but after I have completed the post request to the auth page, no access code is returned.
All that is returned is the client id that I send.

Here is the code that I’m using.

session_start(); $s_session_id = session_id();
// this points to my local machine
$s_base_url = 'http://www.apigility.loc';
$s_client = 'testclient';
$s_redirect_uri = '/oauth/receivecode';

$o_client = new Client(['base_uri' => $s_base_url]);

$s_uri = '/oauth/authorize';
$s_response_type = 'code';

$s_get_string = $s_uri . '?response_type=' . $s_response_type . '&client_id=' . $s_client . '&redirect_uri=' . $s_redirect_uri . '&state=' . $s_session_id;

$a_header = array('accept' => 'application/json' , 'Content-Type' => 'application/json');

$a_params = array('headers' => $a_header);

$o_response = $o_client -> post($s_get_string , $a_params);

$s_body = $o_response -> getBody() -> getContents();
    
$a_body = json_decode($s_body , true);

/*
all that’s in $a_body is the client id
*/

How do I get the access code?

Thanks in advance
Daniel

Hello all

I figured out a little more, I think…
It seems, to get the access code, you need to send through a post variable ‘authorized’ with value ‘yes’

So my question now is, how do I send both a post variable and the required headers using Guzzle 6?
I’ve tried all sorts of combinations in my params array, but nothing is working so far.

Any suggestions?

I can’t figure out how to delete a post.
I recreated the thread in another post.
I worded the question better I hope.
Please look here Using Guzzle 6 to consume an API