Write into Cloud Collection from an App



Introduction
In this tutorial we show how to use the Remote Query to write into a Cloud Collection from an app.
 

You MUST authorize your app to write into your Cloud Collection. See how.


Tip: If you are familiar with Web Services, know that Cloud Collection are accessible through the Cloud Collection API.

    


Note: 
 Cloud Collection is accessible through a RESTful web service. Meaning this Tutorial can be extended to the use of any web service. The Remote Query uses RESTful, that means you can store content in a any CMS, not solely EachScape Cloud Collection.
  



Install the Demo


Install the Tutorial App "WRITE IN CLOUD COLLECTION"

 
Click here it install

You MUST authorize your app to write into your Cloud Collection. See how.
 
A fresh copy of the app will be installed in your Workspace.
Along with is, a fresh copy of the Cloud Collection used by the app.

 (Free free to edit both the app and collection, these are yours)



The App


This Tutorial app allows a user to enter text then store that text into a Cloud Collection.


It uses

  • Text Input Block
  • A simple Text Block used as a 'Submit' button
  • A list block to load Cloud Collection Data.
  • Most importantly: The Remote Query Block to write into the Collection.


Writing into the Collection



The app asks for a name (text) that will be stored in the collection

 

  App Screenshot
 

Implementation: The app stores the result of the Text Input Block into a variable name: 'Var_Name'
 
This a screenshot of the View 'Enter Text'
 



Remote Query

When you push the 'Submit' button, the app adds the Layer 'Remote Query Layer' which runs the Remote Query Block.
The Remote Query Block takes the 'Var_Name' variable and constructs a call (REST) to write into the collection (It uses Cloud Collection API)
 
 
Remote Query write into the Collection using the RESTful protocol

Settings for the Remote Query

2 critical things ought to happen.
 

FIRST: You need to create a key to be able to write into that Cloud Collection.


SECOND: You need to use that key (api_key) as a parameter in the Query Block . This lets the app authenticate itself with that collection.

 
 

1. Create a key

The key creation is very easy. Follow the Tutorial Authorize Write Access into A cloud Collection

2. Use the key: api_key
 
Query Block on the Remote Query Layer
 

Settings:
  • URL The call to the cloud collection.
    • The default value in the URL field is the URL used for any Cloud Collection.
    • If you are using a different service than the EachScape Cloud Collection then remove that URL and enter the one pointing to your web services.

 

  • Fields #1you have to configure that field with the API KEY:  
    • Name: You have to enter 'api_key' in the Name field.
      • Tech Note: This is the name of the parameter you are passing to the end point. 
    • Value: The unique api_key you generated from your cloud collection. Copy paste the value in that field. It uniquely identify your app and authorize your app to write in that collection.

 

  • Fields #2The text value to update in the Collection
    • Name: Enter the EXACT name of the column of the cloud collection using the following format:
      • values[EXACT name of the column] 
      • For example, for a column named 'Name' the syntax would be
        • values[Name]
        • (see screenshot above for example)
    • Value: The value to be saved to the column specified in Name. In our case that value in the variable from the Text input block.
      • [[var: VAR_Name]]
      • That variable comes from the Editor you can pick it from the 'Variable' section.

 

  • Fields #N...  In this Tutorial we only use one field to save one variable. 
    • You can use up to 28 fiels in a Remote Query 
    • The set up is the same as above for each new field.

 

TIP

When your column name have more than one word, for example "My Column Name"

enters the name in Remote Query Block exactly as you see it in your collection:

 

values[My Column Name]

 

Additional Settings for Remote Query

 
The last fields we setup on the Remote Query Service are the
  • "Status Code Key" 
  • "Status Reason Key"

These will be set as Variable values of the status of the server when the app communicates with it.


We set the Response Type as "XML"
and the Response Parser as "XPath".
 


Success, Failure, No Response
 
The Remote Query generate 3 mutually exclusive events.
These are visible under the Event tab of the Remote Query.
The 3 events are:
  • Success
  • Failure
  • No Response.

Success
That Event is triggered when the call to Cloud Collection is successful.

When the app receives a "Success" event it switches to the View called "Success View".
It also removes the Layer that contains the Remote Query.


Failure
That Event is triggered when the call to Cloud Collection returns a failure.

When the app receives a "Failure" event it shows a pop-up alert to let the user know the upload was a failure.
It also remove the Layer that contains the Remote Query.

No Response
That Event is triggered when the call to Cloud Collection times out. No response is received.

When the app receives a "No response" event it shows a pop-up alert to let the user know that it can't communicate with the server.
It also removes the Layer that contains the Remote Query.
 
 


 
Success 
 
When the call runs successfully the value in Var_Name is stored in the column 'Name' of the Cloud Collection called 'Write into Collection' and uniquely identified by its api_key.
 

App success screen.

At that point, if you go to the Cloud Collection (or reload the page if you were already on) you will see the name 'John Doe' previously entered stored in the Collection:

Screenshot of the Cloud Collection updated with new content from the app

Similarly if you select the 'See List from Cloud Collection' in the app
the app will display the newly updated Cloud Collection

Collection are easily displayed in any app.- They each generate standard XML feeds -

Reminder

This Remote Query Service is setup with an API key that references a specific Cloud Collection. To make your app write into the copy of the Cloud Collection installed in your workspace you need to generate the unique key from the Cloud Collection attached to the app (api_key). 
 

How to generate that api_key is described in the Tutorial: Authorize Write access to a Cloud Collection

Reminder of the settings of the Remote Query in Studio

 
 
Learn More
- Add, Delete, Update a row from a Cloud Collection
- Use RESTful with EachScape: Introduction to Remote Query Services