arendjantetteroo / guzzle-toggl

A Toggl API client based on guzzle
MIT License
88 stars 42 forks source link

Need help w/creating clients, etc. #11

Closed TILVince closed 9 years ago

TILVince commented 9 years ago

Could you provide some guidance on how to use the v8 API to create clients (and projects and time entries) using guzzle-toggl? I can't figure out how to format and send the request (calling $toggl_client->CreateClient for clients) nor what to expect as a response. For creating a client, I tried the following, where the variables $client_name, $wid, and $client_notes are set, but the $response returns NULL:

$response = $toggl_client->CreateClient('{"client":{"name":"$client_name","wid":$wid,"notes":"$client_notes"}}');

I can get the example get-workspaces.php to function properly, and I even modified it to pull a list of clients successfully (I first manually added a test client directly in Toggl).

Thanks in advance.

arendjantetteroo commented 9 years ago

Does the response give an error http status code?

Did you try adding the debug config flag? Can you post the complete code in a gist so i can try it out? (Without your token offcourse) Op 19 apr. 2015 19:32 schreef "TILVince" notifications@github.com:

Could you provide some guidance on how to use the v8 API to create clients (and projects and time entries) using guzzle-toggl? I can't figure out how to format and send the request (calling $toggl_client->CreateClient for clients) nor what to expect as a response. For creating a client, I tried the following, where the variables $client_name, $wid, and $client_notes are set, but the $response returns NULL:

$response = $toggl_client->CreateClient('{"client":{"name":"$client_name","wid":$wid,"notes":"$client_notes"}}');

I can get the example get-workspaces.php to function properly, and I even modified it to pull a list of clients successfully (I first manually added a test client directly in Toggl).

Thanks in advance.

— Reply to this email directly or view it on GitHub https://github.com/arendjantetteroo/guzzle-toggl/issues/11.

TILVince commented 9 years ago

I enabled the debug flag, but got nothing different.

GIST is at https://gist.github.com/TILVince/e3594b9fa4cdc9e7d875

arendjantetteroo commented 9 years ago

I think you need to use $client->createClient, so lowercase "create". I'll try your code in a few minutes.

arendjantetteroo commented 9 years ago

Ok, so createClient or CreateClient both work.

You don't need to bother with JSON, this is handled by guzzle. So just use this:

$clientdata = array('client' => array('name' => $client_name, 'wid' => $wid, 'notes' => $client_notes)); $response = $toggl_client->CreateClient($clientdata);

The same is true for the other commands you asked about.

Can you add your example with a pull request? this is helpfull for others as well.

TILVince commented 9 years ago

Thanks! That was the issue. Sorry, I'm a noob at this, and there's no example of posting data. Now I just have to figure out why Workspace clients (where the API saves them) aren't available when creating projects within the Toggl web site (that's not your problem).

Have a good night!

arendjantetteroo commented 9 years ago

No problem. Let me know if you need more help. I will add some more examples that make this stuff clear :)