Skip to main content
Version: 8.1

Stream data type request examples

Level: advanced

The following elements have the Stream data type:

  • Images
  • Files
  • Binaries

Use the following standard methods to work with the Stream data type:

  • GET – retrieve data
  • POST – add data
  • PUT – modify data
  • DELETE – delete data

Clear the browser cache to display Creatio request results when working with the Stream data type.

Retrieve data

Example

Use the OData service to retrieve the “New user” contact's photo.

Implement the example

  1. Retrieve the identifier of the “New user” contact's photo.

    The contact's photo is stored in the [Data] column of the [SysImage] database table. Run the following SQL query to retrieve the identifier of the “New user” contact's photo.

    select Id from SysImage where Id = (select PhotoId from Contact where Name = 'New user')
  2. Retrieve the “New user” contact's photo.

    Execute the following request to retrieve the “New user” contact's photo.

    // Retrieve the [Data] field value for the 29FE7EDF-4DB9-4E09-92B0-018047BA1F71 [Id] object instance in the [SysImage] collection.
    GET http://mycreatio.com/0/odata/SysImage(29FE7EDF-4DB9-4E09-92B0-018047BA1F71)/Data

Add data

Example

Use the OData service to add the “New user” contact. Then, add a photo to the contact.

Implement the example

  1. Add the “New user” contact.

    Creatio stores all contacts in the [Contact] database table. Execute the following request to add the “New user” contact.

    // Add an object instance to the [Contact] collection.
    POST http://mycreatio.com/0/odata/Contact

    Accept: application/json; odata=verbose
    Content-Type: application/json; odata=verbose; IEEE754Compatible=true
    BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO

    {
    // Write the "New user" contact name to the [Name] field.
    "Name": "New user"
    }

    The “New user” contact identifier is “4c63c8fa-467b-48a6-973f-b2069298404f.”

  2. Add a photo to the “New user” contact.

    The contact photo must be stored in the [Data] column of the [SysImage] database table. Since there is no table record for this contact, you must add it. Execute the following request to add a record to the table.

    // Add an object instance to the [SysImage] collection.
    POST http://mycreatio.com/0/odata/SysImage

    Accept: application/json; odata=verbose
    Content-Type: application/json; odata=verbose; IEEE754Compatible=true
    BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO

    {
    // Write the filename of the contact photo to the [Name] field.
    "Name": "scr_NewContactPhoto.png",
    // Write an arbitrary record identifier to the [Id] field of the [SysImage] table.
    "Id": "410006E1-CA4E-4502-A9EC-E54D922D2C01",
    // Write the file type of the contact photo to the [MimeType] field.
    "MimeType": "image/png"
    }

    The record was added to the [SysImage] database table, however the value of the [Data] column is “0x.”

    Pass the image in the request body. The image filename must match the value of the [Name] field. Execute the following request to add the contact photo to the [Data] column.

    // Update the value of the [Data] field for the 410006e1-ca4e-4502-a9ec-e54d922d2c01 [Id] object instance in the [SysImage] collection.
    PUT http://mycreatio.com/0/odata/SysImage(410006e1-ca4e-4502-a9ec-e54d922d2c01)/Data

    Accept: application/json; text/plain; */*
    Content-Type: application/octet-stream; IEEE754Compatible=true
    BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO
  3. Bind the added photo to the “New user” contact.

    Link the [Data] field of the [SysImage] table to the [PhotoId] field of the [Contact] table to bind the photo to the “New user” contact. Execute the following request to set up the binding.

    // Update the value of the [PhotoId] field for the 4c63c8fa-467b-48a6-973f-b2069298404f [Id] object instance in the [Contact] collection.
    PATCH http://mycreatio.com/0/odata/Contact(4c63c8fa-467b-48a6-973f-b2069298404f)

    Accept: application/json;odata=verbose
    Content-Type: application/json; odata=verbose; IEEE754Compatible=true
    BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO

    {
    // Write the identifier of the record in the [SysImage] table to the [PhotoId] field.
    "PhotoId": "410006e1-ca4e-4502-a9ec-e54d922d2c01"
    }

Execute the following to add a photo to an existing contact:

  1. A POST request to add an object instance to the [SysImage] collection.
  2. A PUT request to update the value of the [Data] field for the object instance in the [SysImage] collection.
  3. A PATCH request to bind the added photo to the “New user” contact.

Modify data

Example

Use the OData service to update the photo of the existing “New user” contact.

Implement the example

  1. Retrieve the identifier of the “New user” contact's photo.

    The contact's photo is stored in the [Data] column of the [SysImage] database table. Run the following SQL query to retrieve the identifier of the “New user” contact's photo.

    select Id from SysImage where Id = (select PhotoId from Contact where Name = 'New user')
  2. Update the “New user” contact's photo.

    Execute the following request to update the “New user” contact's photo.

    // Update the [Data] field for the 29FE7EDF-4DB9-4E09-92B0-018047BA1F71 [Id] object instance in the [SysImage] collection.
    PUT http://mycreatio.com/0/odata/SysImage(29FE7EDF-4DB9-4E09-92B0-018047BA1F71)/Data

    Accept: application/json; text/plain; */*
    Content-Type: application/octet-stream; IEEE754Compatible=true
    BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO

Delete data

Example

Use the OData service to delete the photo of the “New user” contact.

Implement the example

  1. Retrieve the identifier of the “New user” contact's photo.

    The contact's photo is stored in the [Data] column of the [SysImage] database table. Run the following SQL query to retrieve the identifier of the “New user” contact's photo.

    select Id from SysImage where Id = (select PhotoId from Contact where Name = 'New user')
  2. Delete the “New user” contact's photo.

    Execute the following request to delete the “New user” contact's photo.

    // Delete the value of the [Data] field for the 29FE7EDF-4DB9-4E09-92B0-018047BA1F71 [Id] object instance in the [SysImage] collection.
    DELETE http://mycreatio.com/0/odata/SysImage(29FE7EDF-4DB9-4E09-92B0-018047BA1F71)/Data

    Accept: application/json; text/plain; */*
    Content-Type: application/json; charset=utf-8; IEEE754Compatible=true
    BPMCSRF: OpK/NuJJ1w/SQxmPvwNvfO

Resources

Creatio API documentation