Not signed in (Sign In)

The Intervals Forum

Categories

Vanilla is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.

API

API PHP Code Sample: Create a Task

Bottom of Page

1 to 1 of 1

  1.  
    •  
      CommentAuthorjreeve
    • CommentTimeMay 21st 2010
     
    In this PHP code sample we'll see how to create a task from XML data using the API and the Curl library. When using this code, remember to replace variable values with your own to avoid errors.

    The API documentation for the task resource can be found at:
    http://www.myintervals.com/api/resource.php?r=task


    //create the xml file to POST
    $putString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    $putString .= "<task>\n";
    $putString .= "<statusid>67329</statusid>\n";
    $putString .= "<projectid>920391</projectid>\n";
    $putString .= "<moduleid>667821</moduleid>\n";
    $putString .= "<title>New Task</title>\n";
    $putString .= "<dateopen>2010-05-26</dateopen>\n";
    $putString .= "<datedue>2010-05-29</datedue>\n";
    $putString .= "<priorityid>46781</priorityid>\n";
    $putString .= "<ownerid>97351</ownerid>\n";
    $putString .= "<assigneeid>101881, 100283</assigneeid>\n";
    $putString .= "<summary>A summary of the task</summary>\n";
    $putString .= "</task>\n";

    //set api token value to your api token
    $apiToken = "";

    //intialize and send the curl request
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.myintervals.com/task");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, $apiToken. ":");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Content-type: application/xml"));
    //POST
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $putString);
    $response = curl_exec($ch);
    curl_close($ch);

    //output the resulting XML
    echo $response;