Creating timeslips via API (in PHP)

Hi guys,

I’ve been working with the new FreeAgent API, now that v1 is EOL. I’ve got
the oAuth connection sorted, there’s no problem there. I’ve implemented a
wrapper for the key GET related requests that I need. The trouble has come
when I’ve tried to implement creating a timeslip (POST).

The API documentation doesn’t show sample request data and their types +
format. So, referencing
: https://dev.freeagent.com/docs/timeslips#create-a-timeslip

We see it says to provide the following input:

  • user (Required)
  • project (Required)
  • task (Required)
  • dated_on (Required)
  • hours (Required)
  • comment

I’ve provided a task by it’s ID and tried passing the full name of the task
as is (via copy/paste from the UI)…I am always receiving the response
“task is required” or something to that effect. It let me to think there
was a problem with the oAuth PHP lib that I was using, so I dug into that
and found the data is all being posted as I would expect.

Would anyone have any ideas? Is the task in a format that I’m unaware of?
Has anyone had any success with creating a timeslip?

Thanks in advance,

Dave.

I managed to work out where I was going wrong, for the benefit of other
reading this or having the same issues,

You must send json encoded data, and the key for the data should be the
singular of the endpoint. What that means is, if sending a new “contact” to
“/v2/contacts” then you need a data structure like so:

json_encode( array( ‘contact’ => array( /*key value pairs as per the
documentation */ ) );

Same goes for say timeslips, but the key would be “timeslip”.
You also need to be absolutely sure to send the Content-Type header as
‘application/json’ when using this method described above.

Also, when asked for “task”, you can provide the fully qualified URL or you
can just provide the ID …I appear to have had successes with both.

Thanks,
Dave.On Saturday, 22 March 2014 12:32:51 UTC+1, David Goodchild wrote:

Hi guys,

I’ve been working with the new FreeAgent API, now that v1 is EOL. I’ve got
the oAuth connection sorted, there’s no problem there. I’ve implemented a
wrapper for the key GET related requests that I need. The trouble has come
when I’ve tried to implement creating a timeslip (POST).

The API documentation doesn’t show sample request data and their types +
format. So, referencing :
FreeAgent Developer Dashboard

We see it says to provide the following input:

  • user (Required)
  • project (Required)
  • task (Required)
  • dated_on (Required)
  • hours (Required)
  • comment

I’ve provided a task by it’s ID and tried passing the full name of the
task as is (via copy/paste from the UI)…I am always receiving the
response “task is required” or something to that effect. It let me to think
there was a problem with the oAuth PHP lib that I was using, so I dug into
that and found the data is all being posted as I would expect.

Would anyone have any ideas? Is the task in a format that I’m unaware of?
Has anyone had any success with creating a timeslip?

Thanks in advance,

Dave.

P.S. I’ve also tried using the full URL:
https://api.sandbox.freeagent.com/v2/tasks/185” and to correct my previous
post, the response was "task must be specified"On Saturday, 22 March 2014 12:32:51 UTC+1, David Goodchild wrote:

Hi guys,

I’ve been working with the new FreeAgent API, now that v1 is EOL. I’ve got
the oAuth connection sorted, there’s no problem there. I’ve implemented a
wrapper for the key GET related requests that I need. The trouble has come
when I’ve tried to implement creating a timeslip (POST).

The API documentation doesn’t show sample request data and their types +
format. So, referencing :
FreeAgent Developer Dashboard

We see it says to provide the following input:

  • user (Required)
  • project (Required)
  • task (Required)
  • dated_on (Required)
  • hours (Required)
  • comment

I’ve provided a task by it’s ID and tried passing the full name of the
task as is (via copy/paste from the UI)…I am always receiving the
response “task is required” or something to that effect. It let me to think
there was a problem with the oAuth PHP lib that I was using, so I dug into
that and found the data is all being posted as I would expect.

Would anyone have any ideas? Is the task in a format that I’m unaware of?
Has anyone had any success with creating a timeslip?

Thanks in advance,

Dave.