Home > Forum > General > Access datasource or BPS internal view via Javascript

Access datasource or BPS internal view via Javascript
0

Hi all!

I am new to WebCon BPS.

I wonder if it is possible to get all items of a process or a datasource/dictionary defined in BPS from client side via REST API.

In SharePoint I did something like this: _api/web/lists/getbytitle('MyList')/items?select=Title...

This does not seem to be possible with BPS REST API or at least I did not find it ;-)


I am thankful for every hint pushing me into the right direction.


Thanks in advance, best regards, Nik

MVP

Hi Nik,

welcome to WEBCON BPS and I'm sure that you are going to stay. :)

I will provide some information this I don't know what you already know.

My best bet is to use the Report API, to access the defined fields and workflows. If you need more, you could page through them with the page parameter:
https://developer.webcon.com/2021/resources/rest_api3.0/#operation/GetDefaultViewReportData
/api/data/v2.0/db/{dbId}/applications/{appid}/reports/{reportid}/views/{viewid}?page=

Other resources
- BPS REST in general: https://developer.webcon.com/docs/rest-api/
- Local swagger documentation/test: https://hostname/api/index.html?urls.primaryName=API%20v2.0

Personal opinion regarding using the BPS REST inside JS
You need to create an App and use its Id along with the secret to get an authentication token. So the client knows these therefore you should be careful with the permissions which are granted to this App. Maybe it's also an option to use impersonation.

In version 2020.1.3 there's a small issue. The returned view must not contain an indicator field this will throw an internal error. I haven't checke the new version.

Best regards,
Daniel

In reply to: Daniel Krüger (Cosmo Consult)

Hi Nik,

welcome to WEBCON BPS and I'm sure that you are going to stay. :)

I will provide some information this I don't know what you already know.

My best bet is to use the Report API, to access the defined fields and workflows. If you need more, you could page through them with the page parameter:
https://developer.webcon.com/2021/resources/rest_api3.0/#operation/GetDefaultViewReportData
/api/data/v2.0/db/{dbId}/applications/{appid}/reports/{reportid}/views/{viewid}?page=

Other resources
- BPS REST in general: https://developer.webcon.com/docs/rest-api/
- Local swagger documentation/test: https://hostname/api/index.html?urls.primaryName=API%20v2.0

Personal opinion regarding using the BPS REST inside JS
You need to create an App and use its Id along with the secret to get an authentication token. So the client knows these therefore you should be careful with the permissions which are granted to this App. Maybe it's also an option to use impersonation.

In version 2020.1.3 there's a small issue. The returned view must not contain an indicator field this will throw an internal error. I haven't checke the new version.

Best regards,
Daniel

Hi Daniel!

Thanks for the fast and very useful answer. I will give it a try, when it comes to implementation.

And yes, I intend to stay, but I still have to learn a lot ;-)

I know the concept of ClientId and ClientSecret from SharePoint and I also took a look into Swagger UI, which is very useful.

Do you know by any chance, if there are already some existing typings for the returned JSON objects (C# interfaces or TypeScript).

Thanks a lot in advance and have a nice day,

Best regards, Nik

MVP
In reply to: Nikolaus Schusser

Hi Daniel!

Thanks for the fast and very useful answer. I will give it a try, when it comes to implementation.

And yes, I intend to stay, but I still have to learn a lot ;-)

I know the concept of ClientId and ClientSecret from SharePoint and I also took a look into Swagger UI, which is very useful.

Do you know by any chance, if there are already some existing typings for the returned JSON objects (C# interfaces or TypeScript).

Thanks a lot in advance and have a nice day,

Best regards, Nik

Hi Nik,

I've created a custom "wrapper" for the communication at my previous employee two years ago. So there's no chance of asking to share it.

What I can tell you though:

- You can generate a client from the OpenAPI specification, depending on your use case it may help.
http://api.openapi-generator.tech/index.html
- In my case it didn't so I opted to use RestSharp for the client and extended it where necessary (authentication/impersonation)
https://restsharp.dev/
- If you want to work with individual workflows and want to have a strongly typed object representing a workflow. You will need to write a wrapper. The properties (fields) are stored in an array inside the JSON. I created custom attributes for "mapping" my typed c# properties to the appropriate BPS field type and it's GUID.
- I created a T4 file to fetch all relevant GUIDs from the database for a given application and create a class. In my case these have been Application, Process, Workflow, Steps, Paths and Fields. Example for a TT file:
https://stackoverflow.com/questions/24957737/t4-tt-using-custom-classes-in-tt-files

I tried to get AutoRest to work for a few hours last year but wasn't successfull.
https://github.com/Azure/AutoRest

I hope this helps.

Best regards,
Daniel

In reply to: Daniel Krüger (Cosmo Consult)

Hi Nik,

I've created a custom "wrapper" for the communication at my previous employee two years ago. So there's no chance of asking to share it.

What I can tell you though:

- You can generate a client from the OpenAPI specification, depending on your use case it may help.
http://api.openapi-generator.tech/index.html
- In my case it didn't so I opted to use RestSharp for the client and extended it where necessary (authentication/impersonation)
https://restsharp.dev/
- If you want to work with individual workflows and want to have a strongly typed object representing a workflow. You will need to write a wrapper. The properties (fields) are stored in an array inside the JSON. I created custom attributes for "mapping" my typed c# properties to the appropriate BPS field type and it's GUID.
- I created a T4 file to fetch all relevant GUIDs from the database for a given application and create a class. In my case these have been Application, Process, Workflow, Steps, Paths and Fields. Example for a TT file:
https://stackoverflow.com/questions/24957737/t4-tt-using-custom-classes-in-tt-files

I tried to get AutoRest to work for a few hours last year but wasn't successfull.
https://github.com/Azure/AutoRest

I hope this helps.

Best regards,
Daniel

Hi Daniel!

Yes, I thought I would have to implement some custom wrappers to get all the typings I need.

I have been using T4 for many years now, so I think this is a good way to go and generate some interfaces / wrappers for WebCon BPS. I'm already on it, but this will take some time.

Thanks for the very helpful links, I will have a look into it.

Have a nice day and best regards, Nik