- For eg. I want to set "Contribute" permission so we have to get a Role definition Id. you can set it as per your requirement. for more details to refer to this article.
- Then get list by title and break list permission.
- Get list item by id.
- Break list item permission and then set permission. To add permission we require two parameters UserId and Role definition ID. The meaning of this method is to give permission to a specific user.
Setting list item permission to one user:

Setting list item permission to multiple users:

Here logic will be the same as above. just have to add one array with required user IDs and then will iterate this array and set the permissions.
Output
After successfully running the query now we will check the permission. so first select the list item and click on the details panel from the right corner second last icon (above the list title). you can see the panel as below,
Click on manage access and then click on Advanced as below,
It will open another tab and in this, you can see all the list item level permission as below,
Summary
In this article, we have seen how to break and add permission to list items using PNP js.
Hope this helps! If it is helpful to you then share it with others. Give your valuable feedback and suggestions in the comments section below.
Sharing is caring!