|
| 1 | +Use case example |
| 2 | +================ |
| 3 | + |
| 4 | +Here are two simple examples showing how you can use the API endpoints to access data. The first example demonstrates how to find all instruments associated with a field, and the second example demonstrates how to find all risers with a specified length and sort them by field. |
| 5 | + |
| 6 | +To build your own application using your desired API endpoints, you can find a complete overview of the available API endpoints in the `4insight REST API`_ documentation. |
| 7 | + |
| 8 | +.. caution:: |
| 9 | + Do not use the INTERNAL API endpoints. You can however use the endpoints from version 1.0, 1.1 and 1.2. |
| 10 | + |
| 11 | +.. code-block:: python |
| 12 | + |
| 13 | + from fourinsight.api import UserSession |
| 14 | +
|
| 15 | + session = UserSession() |
| 16 | +
|
| 17 | + #Find the FlexTrackEntityId of the field |
| 18 | + field_name = "INSERT FIELD NAME HERE" |
| 19 | + field_url = f"https://api.4insight.io/v1.1/FieldsLookups?%24filter=Title%20eq%20%27{field_name}%27" |
| 20 | + field = session.get(field_url).json() |
| 21 | + field_id = field['value'][0]['FlexTrackEntityId'] |
| 22 | +
|
| 23 | + #Find all instruments associated with the field |
| 24 | + instruments_url = f"https://api.4insight.io/v1.1/Instruments?%24filter=FlexTrackFieldEntityId%20eq%20{field_id}" |
| 25 | + instruments = session.get(instruments_url).json() |
| 26 | + all_instruments = instruments['value'] |
| 27 | +
|
| 28 | +.. code-block:: python |
| 29 | +
|
| 30 | + from fourinsight.api import UserSession |
| 31 | +
|
| 32 | + session = UserSession() |
| 33 | +
|
| 34 | + # Set length of riser to filter by |
| 35 | + length_riser = 800 |
| 36 | +
|
| 37 | + # Find all risers with the specified length and sort them by field |
| 38 | + riser_url = f"https://api.4insight.io/v1.1/Risers?%24filter=Length%20eq%20{length_riser}" |
| 39 | + riser = session.get(riser_url).json()['value'] |
| 40 | + sorted_risers = sorted(riser, key=lambda x: x['FlexTrackFieldEntityId']) |
| 41 | +
|
| 42 | + # Find the field associated with each riser |
| 43 | + risers_with_fields = [] |
| 44 | + for riser in sorted_risers: |
| 45 | + field_id = riser['FlexTrackFieldEntityId'] |
| 46 | + field_url = f"https://api.4insight.io/v1.1/FieldsLookups?%24filter=FlexTrackEntityId%20eq%20{field_id}" |
| 47 | + try: |
| 48 | + field_title = session.get(field_url).json()['value'][0]['Title'] |
| 49 | + riser["Field"] = field_title |
| 50 | + except: |
| 51 | + riser["Field"] = "Field not found" |
| 52 | + risers_with_fields.append(riser) |
| 53 | +
|
| 54 | +Additionally, here is a video on how to authorize and obtain the URL for the endpoint you wish to use, found under `Request URL`. |
| 55 | + |
| 56 | +.. video:: fig/swagger.mp4 |
| 57 | + :width: 800 |
| 58 | + :height: 600 |
| 59 | + |
| 60 | +.. _4insight REST API: https://4insight-api-prod.4subsea.net/swagger/index.html |
| 61 | + |
| 62 | + |
0 commit comments