caxy / php-forecast-api-client

PHP client for the https://forecastapp.com undocumented API
MIT License
2 stars 0 forks source link

postAssignment() #1

Open sviriden opened 6 years ago

sviriden commented 6 years ago

Hi,

Do you have any code example how to get work postAssignment() method? What should I pass as $data parameter?

jschroed91 commented 6 years ago

Hi @sviriden - I will provide an example tomorrow morning

jschroed91 commented 6 years ago

Actually @sviriden I have a code sample I used in another project that I can post here...

    protected function createAssignment($userId, $projectId, $startDate, $endDate, $allocation)
    {
        $data = array(
            'assignment' => array(
                'allocation' => $allocation, // Harvest is in hours, forecast requires seconds.
                'end_date' => $endDate,
                'person_id' => (string) $userId,
                'project_id' => (string) $projectId,
                'repeated_assignment_set_id' => null,
                'start_date' => $startDate,
            ),
        );
        echo "\nCreate assignment";
        $response = $this->forecast->postAssignment($data);
        $assignment = $response['assignment'];
        return $assignment;
    }
jschroed91 commented 6 years ago

I'll leave this issue open until we have documentation written that covers this

jschroed91 commented 6 years ago

Oh, that project that uses this is public, too - if you want some additional examples https://github.com/caxy/harvest-forecast-sync/blob/master/src/Service/SyncService.php

sviriden commented 6 years ago

Thanks a lot! Now everything works.