//create attachment item and upload imported_file
$importedFileItem = $library->getTemplateItem('attachment', 'imported_file');
//create attachment item that is linked_file
$linkedFileItem = $library->getTemplateItem('attachment', 'linked_file');
//create attachment item that is imported_url
$importedUrlItem = $library->getTemplateItem('attachment', 'imported_url');
//create attachment item that is linked_url
$linkedUrlItem = $library->getTemplateItem('attachment', 'linked_url');
//add child attachment
//get attachment template
echo "adding attachment item\n";
try {
    $templateItem = $library->getTemplateItem('attachment', 'imported_file');
    $templateItem->parentKey = 'HP8M9UQB';
    echo "creating attachment \n";
    $createAttachmentResponse = $library->createItem($templateItem);
    if ($createAttachmentResponse->isError()) {
        echo $createAttachmentResponse->getStatus() . "\n";
        echo $createAttachmentResponse->getBody() . "\n";
        die("Error creating attachment item\n\n");
    } else {
        //read new item we created
        $createdAttachmentFeed = new Zotero_Feed($createAttachmentResponse->getBody());
        $createdAttachment = $library->items->addItemsFromFeed($createdAttachmentFeed);
        $createdAttachment = $createdAttachment[0];
        echo "attachment item created \n";
        //upload file for attachment
        $fileContents = file_get_contents('./zotero_sticker.ai');
        $fileinfo = array('md5' => md5($fileContents), 'filename' => 'zotero_sticker.ai', 'filesize' => filesize('./zotero_sticker.ai'), 'mtime' => filemtime('./zotero_sticker.ai'));
        echo "<br /><br />\n\nFile Info:";
        var_dump($fileinfo);
<?php

require_once './user_writing_config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new Zotero_Library($libraryType, $libraryID, $userSlug, $apiKey);
//create a new item of type book
$newItem = $library->getTemplateItem('book');
$newItem->set('title', 'This is a book');
$newItem->set('abstractNote', 'Created using a zotero php library and the write api');
$createItemResponse = $library->createItem($newItem);
if ($createItemResponse->isError()) {
    echo $createItemResponse->getStatus() . "\n";
    echo $createItemResponse->getBody() . "\n";
    die("Error creating Zotero item\n\n");
} else {
    //load the item into the library so it is included and has the itemKey and etag
    //and anything else the api populates that we didn't set in our item
    $createItemFeed = new Zotero_Feed($createItemResponse->getBody());
    $createdItem = $library->items->addItemsFromFeed($createItemFeed);
    $createdItem = $createdItem[0];
    echo "Item created\n\n\n<br />";
}
$existingItem = new Zotero_Item($createItemResponse->getBody());
//add child note
$newNoteItem = $library->getTemplateItem('note');
$addNoteResponse = $library->addNotes($existingItem, $newNoteItem);
if ($addNoteResponse->isError()) {
    echo $addNoteResponse->getStatus() . "\n";
    echo $addNoteResponse->getBody() . "\n";
    die("error adding child note to item");