Smart Materials (SMaT) Web API 2.1 supports Read only Dynamic APIs. To enable Dynamic APIs , you must create Views in the SMaT database with prefix (MVWD_) in M_SYS Schema. For example: MVWD_COMPANY_SYMBOLS in M_SYS Schema, and it can be accessed via NLS API.
Example: if View is MVWD_COMPANY_SYMBOLS, then API will be:
https://localhost:44307/Smat/V1/Projects('M12_EP3_Q')/Disciplines('PROS')/Nls('ENGLISH')/COMPANY_SYMBOLS
URL Format:
https://localhost:44307/Smat/V1/Projects(':project')/Disciplines(':discipline')/Nls(':language')/{Views without MVWD_prefix}
Steps to create a Dynamic API
-
Create a View on M_SYS schema starting with prefix MVWD, let's take here MVWD_RECV_REPORTS as a View name.
In MVWD_Name, Name should be unique and in plural form. If in case, any API is created with a name that pre-exists in another API, then the new view is not created as a Dynamic API.
For example: You already have an API with the name Locations, and you created a new view with MVWD_Locations, then Dynamic API will not get created for this View.
-
Let the View definition be:
CREATE OR REPLACE FORCE VIEW MVWD_RECV_REPORTS(INV_RECEIPT_ID,
MRR_ID,
PROJ_ID,
MRR_NUMBER,
MRR_CREATE_DATE,
IDENT,
TAG_NUMBER,
RECV_QTY,
RECV_DATE)
AS
SELECT INV.INV_RECEIPT_ID, MRR.MRR_ID, MRR.PROJ_ID, MRR.MRR_NUMBER, MRR.MRR_CREATE_DATE, INV.IDENT, INV.TAG_NUMBER, INV.RECV_QTY, INV.RECV_DATE
FROM M_MATL_RECV_RPTS MRR, M_INV_RECEIPTS INV
WHERE MRR.MRR_ID = INV.MRR_ID
AND MRR.PROJ_ID = MPCK_LOGIN_WEB.CURRENT_PROJ_ID OR MRR.PROJ_ID IN (SELECT PG_CODE FROM
M_PROJECT_PRODUCT_DISCIPLINES WHERE PROJ_ID=MPCK_LOGIN_WEB.CURRENT_PROJ_ID)
-
Once the View is created in the database, give read permissions to the role Webapi_site_role by using the below grant statement:
GRANT SELECT ON M_SYS.MVWD_RECV_REPORTS TO WEBAPI_SITE_role.
-
Start the application/website in the IIS Server, the RECV_REPORTS API will get created automatically.
-
Check for this API in the metadata also after NLS.
-
To access this API, a privilege same as View name should be created in Privilege screen (A.10.18) of SMaT Classic. Here privilege name should be MVWD_RECV_REPORTS.
-
Assign this privilege to a user/role to access the created API.
-
Using GET method, send the request to the URL
https://<Hostname>/<application name>/Smat/v1/Projects(':project')/Disciplines(':discipline')/Nls(':language')/RECV_REPORTS.
-
Views should be in valid state.
-
First property (Column) of the View should be a unique key, For example, any primary key of the table.
-
If a View is modified, you can still see the modified properties data through API but ODataModel will not reflect the changes. To view changes, you must restart the application/website.
-
To publish a View as an API, you must restart the application/website after the View is created.
-
Restart your application/website once any View is deleted.
-
If you want to filter data based on the login context (particular project) then you can filter the project property with MPCK_LOGIN_WEB.CURRENT_PROJ_ID that will have the current project. For example: PROJ_ID = MPCK_LOGIN_WEB.CURRENT_PROJ_ID.