Discussion
Pegasystems Inc.
JP
Last activity: 14 Jul 2023 15:27 EDT
How to use Repository API
Hi,
Recently I have written up an article about how to set up Repository at https://collaborate.pega.com/discussion/how-set-repository. In this post, I am sharing how to use Repository API, which allows developers to do files / folders CRUD operation in Repository. Be noted, other type of methods such as custom Java are not supported for Repository interaction. You can reference Help for API, but I've included a concrete sample code and hope that helps beginners understand quicker. Please see attached for the documentation.
Below is a table of Repository APIs that I included.
No | Repository API | Rule name | Rule type | Parameters | Note |
---|---|---|---|---|---|
1 | Create folder API | D_pxNewFolder | Savable Data Page |
|
This API creates a folder in a repository. If you want to create a sub folder under existing folder, use slash (ex. "/parentfolder/childfolder"). To call this API, in an activity, use Save-DataPage method and specify "D_pxNewFolder". |
2 | Create file API | D_pxNewFile | Savable Data Page |
|
This API creates (uploads) a file in a repository. You need to prepare a file contents before calling API. You can either pass file contents to API either by String (pyContents) or Stream (pyStream). Unlike Get file API, there is no explicit parameter that differentiates these and whichever property is populated will be used. If both properties are populated, String will take precedence. |
3 | Get file API | D_pxGetFile | Read-only Data Page |
|
This API retrieves (downloads) a file from repository. In order to download file to client terminal, you can use tools.sendFile API in a Java step. You can handle the file either by String or Stream (the best practice is to use Stream). If you use Jave step, D_pxGetFile has to be spcified in the Step Page. |
4 | List files API | D_pxListFiles | Read-only Data Page |
|
This API lists all the files and folders in a folder in a repository. This is limited to only the specified folder and it won't give you all the folder hierarchy. The returned information is put into pxResults page list of D_pxListFiles. |
5 | Exists API | pxExists | When rule |
|
This API evaluates if the specified folder or file exists in a repository and returns Boolean value. You may want to use this before Create file API or Delete file API to confirm. |
6 | Delete API | D_pxDelete | Read-only Data Page |
|
This API deletes a file or folder in a repository. If "recursiveDelete" parameter is checked, it recursively deletes all the folder contents. As a best practice, set this parameter to true. If you set this value to false for a folder, and the folder is not empty, system throws an error "The target folder was not empty". |
Thanks,