Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
protogrid:api_endpoints [2017-12-08 11:44] – created 46.140.51.3protogrid:api_endpoints [2021-12-20 15:38] (current) – [/api/v2/apps/<app_name>/protos/<proto_key>/card-keys] dru
Line 3: Line 3:
 This section lists the different API endpoints you can use to access or update Protogrid data. The respective http method is defined as [METHOD] following the endpoint in this documentation. This section lists the different API endpoints you can use to access or update Protogrid data. The respective http method is defined as [METHOD] following the endpoint in this documentation.
  
-=== Response ===+===== Response =====
 Every request to such an API endpoint returns a JSON object. The returned JSON object always contains an error and a result object. If the request was successful, the result object contains the requested or updated data. When the request fails, the errors object contains the error messages which occurred when trying to execute the request. Every request to such an API endpoint returns a JSON object. The returned JSON object always contains an error and a result object. If the request was successful, the result object contains the requested or updated data. When the request fails, the errors object contains the error messages which occurred when trying to execute the request.
  
-== Example successful response ==+==== Example successful response ==== 
 +<code javascript> 
 +
 +  "errors": [],  
 +  "protogrid_environment_version": "1.3.9", 
 +  "result":
 +    "key": {…}, 
 +    "key": […], 
 +    "key": "data" 
 +  } 
 +
 +</code> 
 + 
 +==== Example failure response ==== 
 +<code javascript> 
 +
 +  "errors":
 +    { … }, 
 +    { … } 
 +  ],  
 +  "protogrid_environment_version": "1.3.9", 
 +  "result": {} 
 +
 +</code> 
 + 
 +===== Field Types ===== 
 +In Protogrid there exist different types of fields such as numbers, text or dates. 
 + 
 +==== Number Field ==== 
 +==== Text Field ==== 
 +==== Date Time Field ==== 
 +Protogrid always uses [[https://en.wikipedia.org/wiki/ISO_8601|ISO 8601 standard]] in UTC timezone for storing date time values. 
 +==== Relation Field ==== 
 +==== Role Field ==== 
 + 
 +==== Rich Text Field ==== 
 + 
 +===== Endpoints ===== 
 +The Protogrid JSON API offers the following API endpoints: 
 + 
 +==== /api/v2/apps ==== 
 +[GET] Returns a list of all Applications to which the authenticated user has access to. 
 + 
 +Example request:  
 +<code http> 
 +https://example.protogrid.com/api/v2/apps 
 +</code> 
 + 
 +Example response: 
 +<code javascript> 
 +
 +  "errors": [],  
 +  "protogrid_environment_version": "1.3.9", 
 +  "result":
 +    { 
 +      "app_id": "app_example_id",  
 +      "description": "Example App",  
 +      "logo_url": "",  
 +      "theme_color": "blue-dark",  
 +      "title": "Example App ",  
 +      "url": "/example",  
 +      "url_name": "example" 
 +    }, 
 +    { 
 +      "app_id": "appID", 
 +      "description": "Your awesome app", 
 +      … 
 +    }, 
 +    … 
 +  ] 
 +
 +</code> 
 + 
 +==== /api/v2/apps/<app_name> ==== 
 +[GET] Returns basic information about one Application. 
 + 
 +Example request:  
 <code> <code>
 +https://example.protogrid.com/api/v2/apps/example
 +</code>
 +
 +Example response:
 +
 +<code javascript>
 +
 +  "errors": [],
 +  "protogrid_environment_version": "1.3.9",
 +  "result":
 +    "app_id": "appID",
 +    "description": "Example App",
 +    "logo_url": "",
 +    "theme_color": "blue-dark",
 +    "title": "Example App ", 
 +    "url": "/example",
 +    "url_name": "example"
 +  }
 +}
 +</code>
 +
 +==== /api/v2/apps/<app_name>/views ====
 +[GET] Returns a list of all view names in this Application. 
 +Details on what views are supported, see [[protogrid:json_api_database_views|all available views]].
 +
 +Example request: 
 +
 +<code>
 +https://example.protogrid.com/api/v2/apps/example/views
 +</code>
 +
 +Example response:
 +
 +<code javascript>
 { {
- "errors": [],  +  "errors": [], 
- "protogrid_environment_version": "1.3.9", +  "protogrid_environment_version": "1.3.9", 
- "result":+  "result":
- “key”: {}, +    "views"
- “key”: [], +      {"view_name": "examples_by_id"}, 
- “key”: “data” +      {} 
- }+    ] 
 +  }
 } }
 +</code>
  
 +==== /api/v2/apps/<app_name>/views/<view_name> ====
 +Most of the API endpoints except you to specify App or Card IDs. At the time at which this data is requested, these ids therefore already need to be known. It is therefore necessary to have convenient ways of asking Protogrid about what ids are available based on different search criteria. Database views can be used to acquire collections of data based on sorting and filtering URL parameters. 
 +
 +[GET] Returns all the entries in the specified view. Please note that URL parameters must be URI encoded.
 +URL Parameter:
 +  * start_key: ["proto_key", "column_key", "filter_value", null], where column_key and filter_value are optional.
 +  * end_key: ["proto_key", "column_key", "filter_value", {}], where column_key and filter_value are optional
 +  * keys: ["key1", "key2", "key3", …], only returns the entries for the specified keys
 +  * page_number: Number of the desired page starting at 0 for the first page. Page length is determined by the 'limit' parameter (counted before filtering for read access rights).
 +  * limit: Accepts a number, which defines how many Cards are returned at most with the result object. Fewer Cards can be returned if not all Cards are visible due to read acces restrictions.
 +    * Example: limit=15
 +    * Default value: 10
 +  * descending: If set to true the results will be in descending order. If set to true start_key and end_key must be exchanged.
 +    * Example: descending=true
 +    * Default value: False
 +  * include_cards: If set to true the result contains the cards for the keys as well.
 +    * Example: include_cards=true
 +    * Default value: False
 +    * Please note that the “include_cards” parameter has a high cost in terms of performance. We therefore recommend using this functionality very economically, i.e. on as few view rows as possible.
 +
 +    
 +Please note:
 +  * You may only use either "keys" or "start_key" and "end_key".
 +  * Key values must be cut off after 300 characters (e. g. string values and sortstrings) because these values are also cut off in the view index.
 +
 +Details: For more details about the URL parameters see the [[http://docs.couchdb.org/en/stable/api/ddoc/views.html|CouchDB documentation]].
 +
 +Full list of views can be found [[protogrid:json_api_database_views|here]].
 +
 +Example request: 
 +
 +<code>
 +https://example.protogrid.com/api/v2/apps/example/views/example_view?start_key=["example_proto_key",null]&end_key=["example_proto_key",{}]&page_number=1&limit=2&descending=false
 +</code>
 +
 +The URL parameters need to be URI encoded. So from the example above the start_key parameter would look like 
 +<code>
 +start_key= %5B%22example_proto_key%22%2Cnull%5D
 +</code>
 +
 +Example response:
 +
 +<code javascript>
 +{
 +  "errors": [],
 +  "protogrid_environment_version": "1.3.9",
 +  "result": {
 +    "next_card_key": "key",
 +    "rows": [
 +      {"key": "example_document_key"},
 +      {…}
 +    ]
 +  }
 +}
 +</code>
 +
 +==== /api/v2/apps/<app_name>/cards ====
 +
 +[POST] Creates a new Card. It is necessary to specify a 'proto_key' denoting the Proto on which the new Card will be based. Initial values for the 'design_elements' can be sent along. Mandatory design elements must always be set. If a Card ID of an existing card is specified in the property '_id', Protogrid updates this Card with the provided data. If an array of Card objects is supplied in the POST request body, all of them will be created/updated as a bulk operation. Note that in bulk operation either all or none of the passed Cards will be saved. For example, out of 100 Cards, none will be saved if a single Card has caused validation errors.  As response this endpoint returns a list of all created/updated Cards.
 +
 +Example request: 
 +<code>
 +https://example.protogrid.com/api/v2/apps/example/cards
 +</code>
 +
 +In the POST request body, a JSON object needs to be sent as shown in the following example:
 +<code javascript>
 +
 +  "proto_key": "some_proto_key",
 +  "design_elements": [
 +    {
 +      "definition_key": "example_design_element_key",
 +      "value": "example_value"
 +    },
 +    …
 +  ]
 +}
 +</code>
 +
 +Example response:
 +<code javascript>
 +{
 +  "errors": [],
 +  "messages": [],
 +  "protogrid_environment_version": "2.1.5",
 +  "result": {
 +    "_id": "some_card_id",
 +    "_rev": "some_rev_id",
 +    "denormalized": {…},
 +    "design_elements": {…},
 +    …
 +  }
 +}
 +</code>
 +
 +Deprecated functionalities:
 +  * Specification of a user-defined Card ID for a new Card: In previous versions, it was possible to freely specify the Card ID for a new Card in the '_id' property. This functionality is deprecated and cannot be used in future releases. In particular, instead of relying on this feature to insert foreign IDs into Protogrid, we suggest using an additional auxiliary field containing the foreign ID.
 +
 +==== /api/v2/apps/<app_name>/cards/<card_key> ====
 +[GET] Returns a specific Card identified by 'card_key'.
 +
 +[DELETE] Logically deletes a specific Card identified by 'card_key'. Please note that the deleted Card will be still available, either through the API or the UI using the trash. The return value contains the newly deleted Card.
 +
 +[POST] Updates an existing Card identified by 'card_key'. If the '_id' property is set in the JSON, it needs to match the 'card_key'. In addition, the 'proto_key' must match that of the existing Card.
 +
 +Example request: 
 +<code>
 +https://example.protogrid.com/api/v2/apps/example/cards/some_card_id
 +</code>
 +
 +In the POST request body, a JSON object needs to be sent as shown in the following example:
 +<code javascript>
 +{
 +  "_id": "some_card_id",
 +  "proto_key": "some_proto_key",
 +  "design_elements": [
 +    {
 +      "definition_key": "example_design_element_key",
 +      "value": "example_value"
 +    },
 +    …
 +  ]
 +}
 +</code>
 +Example response:
 +<code javascript>
 +{
 +  "errors": [],
 +  "messages": [],
 +  "protogrid_environment_version": "2.1.5",
 +  "result": {
 +    "_id": "some_card_id",
 +    "_rev": "some_rev_id",
 +    "denormalized": {…},
 +    "design_elements": {…},
 +    …
 +  }
 +}
 +</code>
 +
 +==== /api/v2/apps/<app_name>/cards/<card_key>/attachments/<file_name> ====
 +[GET] Returns the attachment identified by 'file_name' of a Card identified by 'card_key'.
 +
 +[PUT] Uploads the Form Data attachment with name 'attachment-upload' to the specified Card. If this Card already has an attachment with the specified file name, the existing attachment is replaced by the uploaded one.
 +
 +Example GET request: 
 +<code>
 +https://example.protogrid.com/api/v2/apps/example_app/cards/89e74e40-b0ef-4bc3-8e89-a43a43763087/attachments/Bildschirmfoto%202021-01-22%20um%2014.11.15.png
 +</code>
 +
 +Example code for PUT request:
 +<code javascript>
 +var HOST = "https://example.protogrid.com/";
 +var APP_NAME = "example_app";
 +var CARD_KEY = "89e74e40-b0ef-4bc3-8e89-a43a43763087";
 +
 +function uploadFile(file, progressCallback, successCallback) {
 +    function createFormData(file) {
 +        var data = new FormData();
 +        data.append("Content-Type", file.type);
 +        data.append("attachment-upload", file);
 +        return data;
 +    }
 +
 +    var attachment_base_url = HOST + "api/v2/apps/" + APP_NAME + "/cards/" + CARD_KEY + "/attachments/";
 +    var initial_file_name = file.name;
 +    var xhr = new XMLHttpRequest();
 +    xhr.open("PUT", attachment_base_url + initial_file_name, true);
 +    xhr.upload.addEventListener("progress", function(progress_event) {
 +        var progress = progress_event.loaded / progress_event.total * 66; // We want the progress bar to show "loading" until the server response is back.
 +        progressCallback(progress);
 +    });
 +    xhr.addEventListener("load", function() {
 +        if (xhr.status == 200) {
 +            var saved_filename = initial_file_name;
 +            if (xhr.response && typeof(xhr.response) === 'string' && xhr.response !== '') {
 +                var response = JSON.parse(xhr.response);
 +                if (response && typeof(response) === 'object' && response.result && typeof(response.result) === 'object' && response.result.file_name && typeof(response.result.file_name) === 'string' && response.result.file_name !== '') {
 +                    saved_filename = response.result.file_name;
 +                }
 +            }
 +            progressCallback(100);
 +            successCallback({
 +                url: attachment_base_url + saved_filename
 +            });
 +        }
 +    });
 +    xhr.send(createFormData(file));
 +}
 +</code>
 +
 +
 +The corresponding Form Data: 
 +<code>
 +------WebKitFormBoundarya04hDppsnTo2uPOR
 +Content-Disposition: form-data; name="Content-Type"
 +
 +image/png
 +------WebKitFormBoundarya04hDppsnTo2uPOR
 +Content-Disposition: form-data; name="attachment-upload"; filename="Bildschirmfoto 2021-01-22 um 14.11.15.png"
 +Content-Type: image/png
 +
 +
 +------WebKitFormBoundarya04hDppsnTo2uPOR--
 +</code>
 +
 +Example response after successful attachment upload:
 +<code javascript>
 +{
 +  "errors": [], 
 +  "result": {
 +    "file_name": "Bildschirmfoto_2021-01-22_um_14.11.15.png"
 +  }
 +}
 +</code>
 +
 +==== /api/v2/apps/<app_name>/protos ====
 +[GET] Returns a list of all protos of the specified application.
 + 
 +The following URL parameter can be used for paging:
 +  * limit: Defines how many proto keys are returned. Takes a number between 1 and 1000, default is 10.
 +The returned result contains a key "next_card_key" whose value is the next key not returned in this answer.
 +
 +Example request: 
 +<code>
 +https://example.protogrid.com/api/v2/apps/example/protos?limit=1
 +</code>
 +
 +Example result: 
 +<code javascript>
 +{
 +  "errors": [],
 +  "protogrid_environment_version": "1.3.9",
 +  "result": {
 +    "next_card_key": "NextProtoKey"
 +    "protos": [
 +      {"key": "ExampleProtoKey"}
 +    ]
 +  }
 +}
 +</code>
 +
 +==== /api/v2/apps/<app_name>/protos/<proto_key> == 
 +[GET] Returns detailed information about the specified Proto.
 +
 +Example request: 
 +<code>
 +https://example.protogrid.com/api/v2/apps/example/protos/example_proto_key
 +</code>
 +
 +Example result:
 +<code javascript>
 +{
 +  "errors": [],
 +  "protogrid_environment_version": "1.3.9",
 +  "result": {
 +    "key": "example_proto_key",
 +    "shortname": "Example Proto",
 +    "field_and_widget_keys": [
 +      {
 +        "allow_new_cards": true,
 +        "cardinality_setting": 2,
 +        "couchdb_viewname": "",
 +        "disable_label": false,
 +        "display_priority": 7,
 +        "element_type": "Relation",
 +        "grid_size_setting": 0,
 +        "help_text": "",
 +        "hidden": false,
 +        "label_multilanguage_key": "&&mlkey_design_elements",
 +        "multiple_values_setting": 1,
 +        "name": "card_design_elements",
 +        "parent_application_setting": "",
 +        "parent_entity_proto_setting": "DesignElementDefinition",
 +        "requirement_setting": 0,
 +        "show_card_type": true,
 +        "show_created_setting": false,
 +        "show_creator_setting": false,
 +        "show_modified_setting": false,
 +        "show_modifier_setting": false,
 +        "show_short_name_setting": false,
 +        "show_to_users": 0,
 +        "user_enabled_setting": 0,
 +        "value": [
 +          "design_element_key_1 ",
 +          "design_element_key_2",
 +          …
 +        ],
 +        "value_type": "key"
 +      },
 +      {…},
 +      …
 +    ]
 +  }
 +}
 +</code>
 +
 +==== /api/v2/apps/<app_name>/protos/<proto_key>/card-keys ====
 +[GET] Returns the keys for all Cards based on the specified proto.
 +
 +The following URL parameter can be used for paging:
 +  * limit: Defines how many card keys are returned. Takes a number between 1 and 1000, default is 10.
 +
 +The returned result contains a key “next_card_key” whose value is the next key not returned in this answer.
 +
 +Example request: 
 +<code>
 +https://example.protogrid.com/api/v2/apps/example/protos/example_proto/card-keys?limit=1
 +</code>
 +
 +Example result:
 +<code javascript>
 +{
 +  "errors": [],
 +  "protogrid_environment_version": "1.3.9",
 +  "result": [
 +    "card_keys":[
 +      "ExampleProtoKey",
 +      "ExampleSortstring",
 +      "ExampleCardKey"
 +    ],
 +    "next_card_key": "NextCardKey"
 +  ]
 +}
 +</code>
 +
 +==== /api/v2/apps/<app_name>/mailsend ====
 +[POST] Send an email
 +
 +To be able to use this endpoint, the SMTP mail server of your organization must first be configured as the designated mail relay server in your Environment. If this has not been done yet, please contact [[protogrid-customer-support@ategra.ch|Protogrid Support]].
 +
 +Protogrid will fist try to establish a TLS session to the specified mail relay server and authenticate using the supplied credentials. If TLS is not available it will try to connect using SSL. Finally if SSL is not available the function tries to connect using unsecured SMTP protocol.
 +
 +The mail will be sent according to the currently logged in user (mail address specified in user profile and the field "SMTP Server Password" if requested by the mailserver).
 +
 +The following JSON data fields can be used:
 +  * to: TO addresses (Array of Strings, mandatory)
 +  * cc: CC addresses (Array of Strings)
 +  * bcc: BCC addresses (Array of Strings)
 +  * reply_to: ReplyTo addresses (Array of Strings)
 +  * from: From address if other than logged in user (String)
 +  * subject: Subject (String, mandatory)
 +  * body_text_plain: Body text in plain text format (String)
 +  * body_text_html: Body text in HTML format (String)
 +  * inline_images: Images for embedded display in HTML body using "cid" references (Array of Objects)
 +  * attachments: Documents to attach to the email (Array of Objects)
 +
 +Attachments and inline images must already reside inside Protogrid, each attached to a Card. The logged in user must have read access to this Card(s). Attachments and inline images are specified using an Object with the following structure:
 +<code javascript>
 +{
 +    "card_id": "<ID of the Card on which the attachment or image resides>",
 +    "file_name": "<Name of the file as it is listed in the Card specified above>"
 +}
 +</code>
 +
 +By default, users can send a mail to up to 10 recipients. This limit can be increased via the roles assigned to the users using the field "Allowed Number of Recipients per Mail Sent" on each Role Definition. However, a mail never can be sent to more than 500 recipients.
 +
 +The returned result will include a success message or details about the particular error.
 +
 +Example client-side jQuery request:
 +<code javascript>
 +$.post({
 +    url: "https://example.protogrid.com/api/v2/apps/example/mailsend",
 +    data: JSON.stringify({
 +        "to": ["Tester 1️⃣ <test1@ategra.ch>", "Tester 2️⃣ <test2@ategra.ch>"],
 +        "cc": ["Tester 3️⃣ <test3@ategra.ch>", "Tester 4️⃣ <test4@ategra.ch>"],
 +        "bcc": ["Tester 5️⃣ <test5@ategra.ch>", "Tester 6️⃣ <test6@ategra.ch>"],
 +        "reply_to": ["Tester 7️⃣ <test7@ategra.ch>", "Tester 8️⃣ <test8@ategra.ch>"],
 +        "from": "Tester 0️⃣ <test0@ategra.ch>",
 +        "subject": "Test Email with Emojis 👍",
 +        "body_text_plain": "This is a test message in plain text 😎.",
 +        "body_text_html": "This is a <b>test</b> message 🤖.<br><br>Please check if the message is displayed correctly using several different mail clients or tools like Mailtrap (<a href='https://mailtrap.io'>link</a>).<br><br><img src='cid:logo.png'></img>",
 +        "inline_images": [
 +            {"card_id": "ffc3a027-2fed-45f8-8aa8-adec18a90439", "file_name": "logo.png"}
 +        ],
 +        "attachments": [
 +            {"card_id": "ffc3a027-2fed-45f8-8aa8-adec18a90439", "file_name": "Protogrid_Quickstart_Tutorial.pdf"}
 +        ]
 +    }),
 +    contentType: 'application/json; charset=utf-8'
 +}).done(function (response) {
 +    alert("Data: " + JSON.stringify(response));
 +});
 +</code>
 +
 +As a response you receive a JSON with the following structure:
 +  * errors [Array]: Contains information if no single email could be sent, otherwise it is empty.
 +  * messages [Array]: Contains information if Protogrid could not establish the connection to the mail server with the most secure transport encryption, otherwise it is empty.
 +  * result [Object]: Contains information regarding individual recipients to whom the email could not be delivered. If the email could be delivered to all recipients equals to { "success": true }.
 +
 +Example response:
 +<code javascript>
 +{
 +    "errors": [],
 +    "messages":
 +    [
 +        "Couldn't send the mail using a secure TlS communication channel. Trying SSL instead.",
 +        "Couldn't send the mail an SSL communication channel. Trying without encryption."
 +    ],
 +    "result":
 +    {
 +        "external@recipient.ch":
 +        [
 +            554,
 +            "5.7.1 <external@recipient.ch>: Relay access denied"
 +        ]
 +    }
 +}
 </code> </code>
Print/export