Connect Your SAP Build Application to a Public API
- How to add and configure data resources in your SAP Build application
- How to call a public API by scanning a barcode
In the previous tutorial, you configured your application to open a device camera once the scan button had been tapped. This currently reads the barcode and returns only the barcode number, which on it’s own is just a reference with no further information.
To improve this, you need to configure a data source connected to that information. In this example, we’ll use the Open Food Facts public API. Here the application will make an HTTPS request to their URL, returning the information provided there.
- Step 1
Open your draft application in the Composer account.
Click your Scan button, and then click Data.
Click Add Data Resources – Rest API direct integration.
Configure the resource with the following details:
Field Value Resource ID
Short description Data from Open Food Facts API Resource URL https://world.openfoodfacts.org/api/v0
Click Save, saving the data resource.
- Step 2
You now need to configure which information is taken from the Open Food Facts API. For your application, you need to configure this to fetch the barcode information, since that’s what’s being scanned with the device camera. This can be achieved using a Get Record request.
To configure this, click Get Record (Get).
In the Relative path field enter:
Click the existing URL placeholder key, and then configure the following settings:
Field Value Label Barcode Key barcode Value type Text Description Resource ID to retrieve Is encoded Enabled Is static Disabled Is optional Enabled
- Step 3
To now test that the HTTPS is configured and able to fetch information, click Test.
Under the Barcode placeholder, click Currently bound to: static text.
Click Static Text.
Enter 6416453061361 into the Type a text field. This is an example barcode number, taken from a confectionary wrapper.
Click Run Test.
The test now runs, displaying a Test API call response. In this response, you can see information about the confectionary. This includes the product categories, allergen information, and the brand who manufactured the product.
Which allergens to you get back from the API call?
- Step 4
After a successful test you should now set the data schema. This stores the data structure from the URL, enabling the application to easily identify the types of information it is fetching.
To do this, click Set Schema from Response.
Your draft application is now saved and available in your AppGyver Preview app.
In the example, what is the barcode number of the scanned food item?