# Create a custom app to call APP Runtime REST API

### **Step-by-step to get entity data by REST API.**

**Step 1**- configure entity to get data by REST API. For this example, we will prepare entity named Work Order. This Entity includes 3 Tabs and 4 Modules. See picture below.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2Fd9TnJ94Bf9dyxhpQn1eg%2Fimage.png?alt=media\&token=2451433e-a249-4395-b2b7-672359477ecc)

**Step 2** - Get Key Data to send parameters into the URL. The image below is the Update Screen of Work Order. For this example, the key is sale\_order\_no and the value is 0000000010.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F1jsGqafoKBTJURf2yGxd%2Fimage.png?alt=media\&token=90af6b97-6e5f-4dda-8261-ddc25dda2df2)

**Step 3** - The login process uses Post Method. Run URL [http://localhost:9084/eaf-rest/login](http://localhost:9084/eaf-rest/login) with parameter Content-Type: application/json and Body contains 3 values in JSON format. \
&#x20;           "username" : "administrator", \
&#x20;           "password" : "P@55w0rd", \
&#x20;           "clientId" : "123456789" \
After run login URL, the system will return **id\_token** for use in other process. See picture below.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F5tjXfxLBhz5EQkI67MZA%2Fimage.png?alt=media\&token=0f643dc6-0c89-40e2-942d-5a98eb2fa5ce)

**Step 4** - Call URL to get data from Entity. The Format is ServerName, Port, Context&#x20;

Root and Parameter Value.&#x20;

Format: ServerName:Port/Context Root/Parameter Value&#x20;

Example: [http://localhost:9084/eaf-rest/entity/EN\_431959963131500/get?handleForm=Y\&SALE\_ORDER\_NO=0000000010\&cbMethod=callback](http://localhost:9084/eaf-rest/entity/EN_431959963131500/get?handleForm=Y\&SALE_ORDER_NO=0000000010\&cbMethod=callback)

**Step 5** - Set the following 3 Header parameters as shown below.&#x20;

* **Content-Type**: application/json
* **Authorization:** Start value Bearer then space and token id received from login process.&#x20;
* **clientId:** use clientId same as in login process.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FOwJ4g1PqRNCNGN98MDVo%2Fimage.png?alt=media\&token=cba880ef-dae3-4248-84b6-1499a7592172)

**Step 6** - Run Step 3 and Step 4 to get result JSON DATA as in picture below

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FWeSusApw7fYzCTKO9X3n%2Fimage.png?alt=media\&token=f98bc930-add7-4003-a858-defb07e23272)

JSON Data contains following fields.

* **ENTITY\_ID** value of entityID
* **MODULE\_ID** value of moduleID
* **UPDATE** is process mode
* **SALE\_ORDER\_ITEM** is table name
* **PRODUCT\_ID, PRODUCT\_NAME** etc. is field name
* **KEY** is the key of module/record In this Data will see ModuleID 4 value which is same with configuration of this entity.

### **Test API from a custom app**&#x20;

You already saw how to get data from entity. Now assume another application need to find customer contact from Order No. You can get the information by REST API.

**Step 1** - In the Login Screen enter the userName value and call Login REST.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FUHZsFHXF8gJ9NPy6cAXN%2Fimage.png?alt=media\&token=f07ed21f-a5a5-4a25-8016-f74fe2894552)

**Step 2** - Use Ajax to call Rest Service to keep id\_token into session for use by other processes.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F8gfRy2NjD1cI9zJ7eDuA%2Fimage.png?alt=media\&token=bfa237d9-49f2-433a-aef8-bd80eff35711)

**Step 3** - Prepare Screen to Input Order No.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FkU5TKf5FoV1jnM4CzE8W%2Fimage.png?alt=media\&token=9dd9eaaa-a605-4bbb-baec-fa26e98c8892)

**Step 4** - Input value Order No, then click Find Customer contact.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FBfi1OlSiIFvEgoI8tzCg%2Fimage.png?alt=media\&token=787007b7-c63d-47ee-8d2f-d2f0d288b13a)

**Step 5** - use the JavaScript function to call Ajax REST API to get Data Customer contact by passing parameter Order No. In headers set Content-Type, Authorization (use id\_token from the session), and clientId from the login process.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FTkAt4b3aefDi2QwgL2Z6%2Fimage.png?alt=media\&token=23ec89c9-b6d7-41a1-93b0-d73a3ae0bf13)

**Step 6** - call REST API and get JSON DATA. The highlighting module has CUST\_CONTACT which need result. It can get Data from JSONObject through MODULE\_ID > UPDATE > SALE\_ORDER\_DELIVERY > CUST\_CONTACT.

**Step 7** - Use JQuery or JavaScript to Display Result Data.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FRgP1xJGrJAmFrUFhpHuW%2Fimage.png?alt=media\&token=eed15cf8-634f-4453-bff1-a3922dd1851a)
