{"id":28515942,"url":"https://github.com/thybag/php-sharepoint-lists-api","last_synced_at":"2025-07-05T17:32:03.288Z","repository":{"id":456341,"uuid":"2527261","full_name":"thybag/PHP-SharePoint-Lists-API","owner":"thybag","description":"A simple PHP API to make working with SharePoint lists easy.","archived":false,"fork":false,"pushed_at":"2023-01-20T09:09:44.000Z","size":200,"stargazers_count":184,"open_issues_count":59,"forks_count":96,"subscribers_count":19,"default_branch":"develop","last_synced_at":"2025-06-09T03:36:19.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thybag.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-10-06T16:59:42.000Z","updated_at":"2024-08-21T08:18:56.000Z","dependencies_parsed_at":"2023-02-12T00:55:13.364Z","dependency_job_id":null,"html_url":"https://github.com/thybag/PHP-SharePoint-Lists-API","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/thybag/PHP-SharePoint-Lists-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thybag%2FPHP-SharePoint-Lists-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thybag%2FPHP-SharePoint-Lists-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thybag%2FPHP-SharePoint-Lists-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thybag%2FPHP-SharePoint-Lists-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thybag","download_url":"https://codeload.github.com/thybag/PHP-SharePoint-Lists-API/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thybag%2FPHP-SharePoint-Lists-API/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263778551,"owners_count":23510014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-09T03:31:19.791Z","updated_at":"2025-07-05T17:32:03.283Z","avatar_url":"https://github.com/thybag.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP SharePoint Lists API\n\nThe **PHP SharePoint Lists API** is designed to make working with SharePoint Lists in PHP a less painful developer experience. Rather than messing around with SOAP and CAML requests, just include the SharePoint lists API in to your project and you should be good to go. This library is free for anyone to use and is licensed under the MIT license.\n\nUsing the PHP SharePoint Lists API, you can easily create, read, edit and delete from SharePoint list. The API also has support for querying list metadata and the list of lists.\n\nKnown to work with: SharePoint 2007, SharePoint 2013 and SharePoint online (experimental).\n\n### Usage Instructions\n\n#### Installation\n\nDownload the WSDL file for the SharePoint Lists you want to interact with. This can normally be obtained at:\n    `sharepoint.url/subsite/_vti_bin/Lists.asmx?WSDL`\n\nIf you are using [composer](http://getcomposer.org/), just add [thybag/php-sharepoint-lists-api](https://packagist.org/packages/thybag/php-sharepoint-lists-api) to your `composer.json` and run composer.\n\n    {\n        \"require\": {\n            \"thybag/php-sharepoint-lists-api\": \"dev-master\"\n        }\n    }\n\nIf you are not using composer you can download a copy of the SharePointAPI files manually and include the top \"SharePointAPI.php\" class in your project.\n\n#### Creating SharePointAPI object\n\nIn order to use the PHP SharePoint Lists API you will need a valid user/service account with the permissions to the required list. \n\nFor most SharePoint installations, you can create a new instance of the API using:\n\n    use Thybag\\SharePointAPI;\n    $sp = new SharePointAPI('\u003cusername\u003e', '\u003cpassword\u003e', '\u003cpath_to_WSDL\u003e');\n\nIf your installation requires NTLM Authentication, you can instead use:\n\n    use Thybag\\SharePointAPI;\n    $sp = new SharePointAPI('\u003cusername\u003e', '\u003cpassword\u003e', '\u003cpath_to_WSDL\u003e', 'NTLM');\n\nSharePoint Online users must use:\n\n    use Thybag\\SharePointAPI;\n    $sp = new SharePointAPI('\u003cusername\u003e', '\u003cpassword\u003e', '\u003cpath_to_WSDL\u003e', 'SPONLINE');\n\n\nAll methods return an Array by default. `SetReturnType` can be used to specify that results should be returned as objects instead.\n\n#### Reading from a List.\n\n###### To return all items from a list use either\n\n    $sp-\u003eread('\u003clist_name\u003e'); \n\nor\n\n    $sp-\u003equery('\u003clist_name\u003e')-\u003eget();\n\n\n###### To return only the first 10 items from a list use:\n\n    $sp-\u003eread('\u003clist_name\u003e', 10); \n\nor\n\n    $sp-\u003equery('\u003clist_name\u003e')-\u003elimit(10)-\u003eget();\n\n\n###### To return all the items from a list where surname is smith use:\n\n    $sp-\u003eread('\u003clist_name\u003e', NULL, array('surname'=\u003e'smith')); \n\nor\n\n    $sp-\u003equery('\u003clist_name\u003e')-\u003ewhere('surname', '=', 'smith')-\u003eget();\n\n\n###### To return the first 5 items where the surname is smith and the age is 40\n\n    $sp-\u003eread('\u003clist_name\u003e', 5, array('surname'=\u003e'smith','age'=\u003e40)); \n\nor\n\n    $sp-\u003equery('\u003clist_name\u003e')-\u003ewhere('surname', '=', 'smith')-\u003eand_where('age', '=', '40')-\u003elimit(5)-\u003eget();\n\n\n\n###### To return the first 10 items where the surname is \"smith\" using a particular view, call: (It appears views can only be referenced by their GUID)\n\n    $sp-\u003eread('\u003clist_name\u003e', 10, array('surname'=\u003e'smith','age'=\u003e40),'{0FAKE-GUID001-1001001-10001}'); \n\nor\n\n     $sp-\u003equery('\u003clist_name\u003e')-\u003ewhere('surname', '=', 'smith')-\u003eand_where('age', '=', '40')-\u003elimit(10)-\u003eusing('{0FAKE-GUID001-1001001-10001}')-\u003eget();\n\n\n###### To return the first 10 items where the surname is smith, ordered by age use:\n\n    $sp-\u003eread('\u003clist_name\u003e', 10, array('surname'=\u003e'smith'), NULL, array('age' =\u003e 'desc')); \n\nor\n\n    $sp-\u003equery('\u003clist_name\u003e')-\u003ewhere('surname', '=', 'smith')-\u003elimit(10)-\u003esort('age','DESC')-\u003eget();\n\n\n###### To return the first 5 items, including the columns \"favroite_cake\" and \"favorite animal\"\n\n    $sp-\u003eread('\u003clist_name\u003e', 5, NULL, array(\"favroite_cake\", \"favorite_animal\")); \n\nor\n\n    $sp-\u003equery('\u003clist_name\u003e')-\u003efields(array(\"favroite_cake\", \"favorite_animal\")-\u003elimit(5)-\u003eget();\n\n\nBy default list item's are returned as arrays with lower case index's. If you would prefer the results to return as object's, before invoking any read operations use:\n\n    $sp-\u003esetReturnType('object'); \n\nAutomatically making the attribute names lowercase can also be deactivated by using:\n\n    $sp-\u003elowercaseIndexs(FALSE);\n\n\n#### Querying a list\nThe query method can be used when you need to specify a query that is to complex to be easily defined using the read methods. Queries are constructed using a number of (hopefully expressive) pseudo SQL methods.\n\nIf you for example wanted to query a list of pets and return all dogs below the age of 5 (sorted by age) you could use.\n\n    $sp-\u003equery('list of pets')-\u003ewhere('type','=','dog')-\u003eand_where('age','\u003c','5')-\u003esort('age','ASC')-\u003eget();\n\nIf you wanted to get the first 10 pets that were either cats or hamsters you could use:\n\n    $sp-\u003equery('list of pets')-\u003ewhere('type','=','cat')-\u003eor_where('type','=','hamster')-\u003elimit(10)-\u003eget();\n\nIf you need to return 5 items, but including all fields contained in a list, you can use. (pass false to all_fields to include hidden fields).\n\n    $sp-\u003equery('list of pets')-\u003eall_fields()-\u003eget();\n\nIf you have a set of CAML for a specific advanced query you would like to run, you can pass it to the query object using:\n\n    $sp-\u003equery('list of pets')-\u003eraw_where('\u003cEq\u003e\u003cFieldRef Name=\"Title\" /\u003e\u003cValue Type=\"Text\"\u003eHello World\u003c/Value\u003e\u003c/Eq\u003e')-\u003elimit(10)-\u003eget();\n\n\n#### Adding to a list\n\nTo add a new item to a list you can use either the method \"write\", \"add\" or \"insert\" (all function identically). Creating a new record in a List with the columns forename, surname, age and phone may look like:\n\n    $sp-\u003ewrite('\u003clist_name\u003e', array('forename'=\u003e'Bob','surname' =\u003e'Smith', 'age'=\u003e40, 'phone'=\u003e'(00000) 000000' ));\n\nYou can also run multiple write operations together by using:\n\n \t$sp-\u003ewriteMultiple('\u003clist_name\u003e', array(\n\t\tarray('forename' =\u003e 'James'),\n\t\tarray('forename' =\u003e 'Steve')\n\t));\n\n#### Editing Rows\n\nTo edit a row you need to have its ID. Assuming the above row had the ID 5, we could change Bob's name to James with:\n\n    $sp-\u003eupdate('\u003clist_name\u003e','5', array('forename'=\u003e'James'));\n\nAs with the write method you can also run multiple update operations together by using:\n\n \t$sp-\u003eupdateMultiple('\u003clist_name\u003e', array(\n\t\tarray('ID'=\u003e5,'job'=\u003e'Intern'),\n\t\tarray('ID'=\u003e6,'job'=\u003e'Intern')\n\t));\n\nWhen using updateMultiple every item MUST have an ID.\n\n\u003e :heavy_exclamation_mark: This method returns the row that has been updated. It does not always return the updated data, as SharePoint can take longer to update than this method takes to run.\n\u003e It is therefore not recommended to use this as a check to ensure a successful update.\n\n#### Deleting Rows\n\nIn order to delete a row, an ID as well as list name is required. To remove the record for James with the ID 5 you would use:\n\n    $sp-\u003edelete('\u003clist_name\u003e', '5');\n\nIf you wished to delete a number of records at once, an array of ID's can also be passed to the delete multiple method\n\n    $sp-\u003edeleteMultiple('\u003clist_name\u003e', array('6','7','8'));\n\n#### CRUD - Create, Read, Update and Delete\nThe above actions can also be performed using the CRUD wrapper on a list. This may be useful when you\nwant to perform multiple actions on the same list. Crud methods do not require a list name to be passed in.\n\n    $list = $sp-\u003eCRUD('\u003clist_name\u003e');\n    $list-\u003eread(10);\n    $list-\u003ecreate(array( 'id'=\u003e1, 'name'=\u003e'Fred' ));\n\n#### List all Lists.\nYou can get a full listing of all available lists within the connected SharePoint subsite by calling:\n\n    $sp-\u003egetLists();\n\n#### List metaData.\nYou can access a lists meta data (Column configuration for example) by calling\n\n    $sp-\u003ereadListMeta('My List');\n\nBy default the method will attempt to strip out non-useful columns from the results, but keep \"hidden\". If you'd like the full results to be returned call:\n\n    $sp-\u003ereadListMeta('My List',FALSE);\n\nYou can also now ignore \"hidden\" columns:\n\n    $sp-\u003ereadListMeta('My List', FALSE, TRUE);\n\n#### Field history / versions.\nIf your list is versioned in SharePoint, you can read the versions for a specific field using:\n\n    $sp-\u003egetVersions('\u003clist\u003e', '\u003cid\u003e', '\u003cfield_name\u003e');\n\n#### Attach a file to a SharePoint list item\nFiles can be attached to SharePoint list items using:\n\n    $sp-\u003eaddAttachment('\u003clist\u003e', '\u003cid\u003e', '\u003cpath_to_file\u003e');\n\n\n### Helper methods\n\nThe PHP SharePoint API contains a number of helper methods to make it easier to ensure certain values are in the correct format for some of SharePoints special data types.\n\n###### dateTime\n\nThe dataTime method can either be passed a text based date\n\n     $date = \\Thybag\\SharepointApi::dateTime(\"2012-12-21\");\n\nOr a unix timestamp\n\n    $date = \\Thybag\\SharepointApi::dateTime(time(), true);\n\nAnd will return a value which can be stored in to SharePoints DateTime fields without issue.\n\n###### Lookup\n\nThe lookup data type in SharePoint is for fields that reference a row in another list. In order to correctly populate these values you will need to know the ID of the row the value needs to reference.\n\n    $value = \\Thybag\\SharepointApi::lookup('3','Pepperoni Pizza');\n\nIf you do not know the name/title of the value you are storing the method will work fine with just an ID (which SharePoint will also accept directly)\n    \n    $value = \\Thybag\\SharepointApi::lookup('3');\n\n###### Magic Lookup\n\nIf you are attempting to store a value in a \"lookup\" data type but for some reason only know the title/name of the item, not its ID, you can use the MagicLookup method to quickly look this value up and return it for you. This method will need to be passed both the items title \u0026 the list it is contained within.\n\n    $sp-\u003emagicLookup(\"Pepperoni Pizza\", \"Pizza List\");\n\n## Trouble shooting\n\n* Unable to find the wrapper \"https\"\n\nIf you are getting this error it normally means that php_openssl (needed to curl https urls) is not enabled on your webserver. With many local websevers (such as XAMPP) you can simply open your php.ini file and uncomment the php_openssl line (ie. remove the ; before it).\n\nNote: If you are using SharePoint Online and having SSL errors, please pull the latest version which has changed from SSL v3 to TLS for sharepoint online connections - \n\nAdd this line to your `composer.json` file.\n\n     \"thybag/php-sharepoint-lists-api\": \"dev-develop\"\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthybag%2Fphp-sharepoint-lists-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthybag%2Fphp-sharepoint-lists-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthybag%2Fphp-sharepoint-lists-api/lists"}