Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions php/deleteRequest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
$company = "YOUR TEAMWORK SITENAME";
<?php
$company = "YOUR_TEAMWORK_SITENAME";
$key = "YOUR_API_KEY";
$taskId = TASK_ID;
$action = "todo_items/".$taskId.".json";

$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "https://{$company}.teamwork.com/{$action}" );
curl_setopt( $channel, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($channel, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt( $channel, CURLOPT_HTTPHEADER,
array( "Authorization: BASIC ". base64_encode( $key .":xxx" )));

echo curl_exec ( $channel );
curl_close ( $channel );
$taskID = 1;
$action = "todo_items/{$taskID}.json";

$ch = curl_init();

$options = array(
CURLOPT_URL => "https://{$company}.teamwork.com/{$action}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_SSLVERSION => 6,
CURLOPT_HTTPHEADER => array("Authorization: BASIC ". base64_encode($key .":xxx"))
);

curl_setopt_array($ch, $options);

$result = curl_exec($ch);
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}

if (isset($error_msg)) {
// TODO - Handle cURL error
}

if ($result !== false) {
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($response == 200) {
// TODO - Handle cURL response
$obj = json_decode($result);
var_dump($obj);
}
}

curl_close($ch);
42 changes: 32 additions & 10 deletions php/getRequest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
$company = "YOUR TEAMWORK SITENAME";
<?php
$company = "YOUR_TEAMWORK_SITENAME";
$key = "YOUR_API_KEY";
$action = "projects.json";

$channel = curl_init();

curl_setopt( $channel, CURLOPT_URL, "https://". $company .".teamwork.com/". $action );
curl_setopt( $channel, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $channel, CURLOPT_HTTPHEADER,
array( "Authorization: BASIC ". base64_encode( $key .":xxx" ))
$ch = curl_init();

$options = array(
CURLOPT_URL => "https://{$company}.teamwork.com/{$action}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSLVERSION => 6,
CURLOPT_HTTPHEADER => array("Authorization: BASIC ". base64_encode($key .":xxx"))
);

curl_setopt_array($ch, $options);

echo curl_exec ( $channel );

curl_close ( $channel );
$result = curl_exec($ch);
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}

if (isset($error_msg)) {
// TODO - Handle cURL error
}

if ($result !== false) {
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($response == 200) {
// TODO - Handle cURL response
$obj = json_decode($result);
var_dump($obj);
}
}

curl_close($ch);


66 changes: 44 additions & 22 deletions php/postRequest.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
$company = "YOUR_TEAMWORK_SITE_NAME";
<?php
$company = "YOUR_TEAMWORK_SITENAME";
$key = "YOUR_API_KEY";
$taskListId = TASK_LIST_ID;
$taskListId = 1;
$taskName = "This is an example task.";
$taskDate = time();


$arr = array('todo-item' =>
array( 'content' => $taskName,
'due-date' => date( 'Ymd', $taskDate ) ));
$arr = array(
'todo-item' => array(
'content' => $taskName,
'due-date' => date('Ymd', $taskDate)
)
);

$json = json_encode($arr);


$channel = curl_init();

curl_setopt( $channel, CURLOPT_URL,
"https://{$company}.teamwork.com/todo_lists/{$taskListId}/todo_items.json"
$ch = curl_init();

$options = array(
CURLOPT_URL => "https://{$company}.teamwork.com/todo_lists/{$taskListId}/todo_items.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $json,
CURLOPT_SSLVERSION => 6,
CURLOPT_HTTPHEADER => array(
"Authorization: BASIC ". base64_encode($key .":xxx"),
"Content-type: application/json"
)
);
curl_setopt( $channel, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $channel, CURLOPT_POST, 1 );
curl_setopt( $channel, CURLOPT_POSTFIELDS, $json );
curl_setopt( $channel, CURLOPT_HTTPHEADER, array(
"Authorization: BASIC ". base64_encode( $key .":xxx" ),
"Content-type: application/json"
));

curl_exec ( $channel );

curl_close ( $channel );


curl_setopt_array($ch, $options);

$result = curl_exec($ch);
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}

if (isset($error_msg)) {
// TODO - Handle cURL error
}

if ($result !== false) {
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($response == 201) {
// TODO - Handle cURL response
$obj = json_decode($result);
var_dump($obj);
}
}

curl_close($ch);
47 changes: 36 additions & 11 deletions php/putRequest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
$company = "YOUR TEAMWORK SITENAME";
<?php
$company = "YOUR_TEAMWORK_SITENAME";
$key = "YOUR_API_KEY";
$taskId = 12345;
$action = "todo_items/".$taskId."/complete.json";
$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "https://". $company .".teamwork.com/". $action );
curl_setopt( $channel, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($channel, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt( $channel, CURLOPT_HTTPHEADER,
array( "Authorization: BASIC ". base64_encode( $key .":xxx" ))
$taskID = 1;
$action = "todo_items/{$taskID}/complete.json";

$ch = curl_init();

$options = array(
CURLOPT_URL => "https://{$company}.teamwork.com/{$action}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_SSLVERSION => 6,
CURLOPT_HTTPHEADER => array( "Authorization: BASIC ". base64_encode($key .":xxx"))
);
echo curl_exec ( $channel );
curl_close ( $channel );

curl_setopt_array($ch, $options);

$result = curl_exec($ch);
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}

if (isset($error_msg)) {
// TODO - Handle cURL error
}

if ($result !== false) {
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($response == 200) {
// TODO - Handle cURL response
$obj = json_decode($result);
var_dump($obj);
}
}

curl_close($ch);
126 changes: 94 additions & 32 deletions php/uploadFile.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,95 @@
$url = "https://YOUR_COMPANY_NAME.teamwork.com";
<?php
$company = "YOUR_TEAMWORK_SITENAME";
$key = "YOUR_API_KEY";

$filename = 'samplefile.txt';

$file_name_with_full_path = realpath($filename);

$args['file'] = new CurlFile($file_name_with_full_path, 'text/plain', $filename);

$channel = curl_init();

curl_setopt($channel, CURLOPT_URL, "$url/pendingfiles.json");

curl_setopt($channel, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($channel, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($channel, CURLOPT_POST, true);

curl_setopt($channel, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($channel, CURLOPT_POSTFIELDS, $args);

curl_setopt($channel, CURLOPT_HTTPHEADER,

array("Authorization: BASIC " . base64_encode($key . ":xxx")));

$result = curl_exec($channel);

curl_close($channel);

print_r($result);
$file = 'samplefile.txt';
$fileNameWithFullPath = realpath($file);
$mimeType = mime_content_type($file);
$pathParts = pathinfo($file);
$args['file'] = new CurlFile($fileNameWithFullPath, $mimeType, $file);

$ch = curl_init();

$options = array(
CURLOPT_URL => "https://{$company}.teamwork.com/pendingfiles.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $args,
CURLOPT_SSLVERSION => 6,
CURLOPT_HTTPHEADER => array("Authorization: BASIC " . base64_encode($key . ":xxx"))
);

curl_setopt_array($ch, $options);

$result = curl_exec($ch);
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}

if (isset($error_msg)) {
// TODO - Handle cURL error
}

if ($result !== false) {
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($response == 201) {
// TODO - Handle cURL response
$obj = json_decode($result);
$pendingFileRef = $obj->pendingFile->ref;
$projectID = 1;
$action = "projects";

// Example - Add a File to a Task
// https://developer.teamwork.com/projects/files/add-a-file-to-a-project
$arr = array(
"file" => array(
"name" => $pathParts['basename'],
"description" => "Some description",
"private" => "0",
"category-id" => "0",
"category-name" => "My new category",
"pendingFileRef" => $pendingFileRef,
"tags" => "tag1,tag2,tag3"
)
);

$json = json_encode($arr);

$options = array(
CURLOPT_URL => "https://{$company}.teamwork.com/{$action}/{$projectID}/files.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $json,
CURLOPT_SSLVERSION => 6,
CURLOPT_HTTPHEADER => array(
"Authorization: BASIC " . base64_encode($key . ":xxx"),
"Content-Type: application/json"
)
);

curl_setopt_array($ch, $options);
$result = curl_exec($ch);

if (curl_error($ch)) {
$error_msg = curl_error($ch);
}

if (isset($error_msg)) {
// TODO - Handle cURL error
}

if ($result !== false) {
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($response == 201) {
// TODO - Handle cURL response
$obj = json_decode($result);
var_dump($obj);
}
}
}
}

curl_close($ch);