Adding folder with a custom identifier and subsequent call of this folder.

Task:

Create a folder in the system and link it to an additional unique identifier in an external system.

Solution:

First we have to create in the system a folder containing at least one media file and add entry “customer_session_id” with the value “test_id_123456” (unique identifier in an external system) to this folder’s metadata.

A method for creating folders in the system is described in the relevant section of these FAQs.

Requests for creation a target folder for this example:

HTTP

Bash

Python

php

Java

                
POST /api/folders/ HTTP/1.1
Host: youradress.ru
X-Forensic-Access-Token: 0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1
User-Agent: PostmanRuntime/7.15.2
Accept: */*
Cache-Control: no-cache
Postman-Token: d500554e-8de5-4856-9723-832ada519efb,34b7b965-2f63-423d-87a4-f2ed717a6ee9
Host: youradress.ru
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: 147649
Connection: keep-alive
cache-control: no-cache


Content-Disposition: form-data; name="photo1"; filename="/X:/1.jpg


------WebKitFormBoundary7MA4YWxkTrZu0gW--,
Content-Disposition: form-data; name="photo1"; filename="/X:/1.jpg


------WebKitFormBoundary7MA4YWxkTrZu0gW--
Content-Disposition: form-data; name="payload"

{
  "folder:meta_data": {
    "customer_session_id": "test_id_123456"
  },
  "media:tags": {
       "photo1": [
      "photo_selfie"
    ]
  }
}
------WebKitFormBoundary7MA4YWxkTrZu0gW--


            
                
curl -X POST \
  https://youradress.ru/api/folders/ \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 147649' \
  -H 'Content-Type: multipart/form-data; boundary=--------------------------505656178980517917065194' \
  -H 'Host: youradress.ru' \
  -H 'Postman-Token: d500554e-8de5-4856-9723-832ada519efb,e85955dd-3e06-4ebf-8339-cb125a9f5608' \
  -H 'User-Agent: PostmanRuntime/7.15.2' \
  -H 'X-Forensic-Access-Token: 0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F photo1=@/X:/1.jpg \
  -F 'payload={
  "folder:meta_data": {
    "customer_session_id": "test_id_123456"
  },
  "media:tags": {
       "photo1": [
      "photo_selfie"
    ]
  }
}'


            
                
import requests

url = "https://youradress.ru/api/folders/"

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"photo1\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"payload\"\r\n\r\n{\n  \"folder:meta_data\": {\n    \"customer_session_id\": \"test_id_123456\"\n  },\n  \"media:tags\": {\n       \"photo1\": [\n      \"photo_selfie\"\n    ]\n  }\n}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
    'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    'X-Forensic-Access-Token': "0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1",
    'User-Agent': "PostmanRuntime/7.15.2",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Postman-Token': "d500554e-8de5-4856-9723-832ada519efb,25dc506f-a40c-4d09-95a8-bdeb8995af98",
    'Host': "youradress.ru",
    'Accept-Encoding': "gzip, deflate",
    'Content-Type': "multipart/form-data; boundary=--------------------------505656178980517917065194",
    'Content-Length': "147649",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)


            
                
setUrl('https://youradress.ru/api/folders/');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'Connection' => 'keep-alive',
  'Content-Length' => '147649',
  'Content-Type' => 'multipart/form-data; boundary=--------------------------505656178980517917065194',
  'Accept-Encoding' => 'gzip, deflate',
  'Host' => 'youradress.ru',
  'Postman-Token' => 'd500554e-8de5-4856-9723-832ada519efb,90578152-4757-4142-8706-331eaf212d99',
  'Cache-Control' => 'no-cache',
  'Accept' => '*/*',
  'User-Agent' => 'PostmanRuntime/7.15.2',
  'X-Forensic-Access-Token' => '0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1',
  'content-type' => 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
));

$request->setBody('------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="photo1"; filename="1.jpg"
Content-Type: image/jpeg


------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="payload"

{
  "folder:meta_data": {
    "customer_session_id": "test_id_123456"
  },
  "media:tags": {
       "photo1": [
      "photo_selfie"
    ]
  }
}
------WebKitFormBoundary7MA4YWxkTrZu0gW--');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}


            
                
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
RequestBody body = RequestBody.create(mediaType, "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"photo1\"; filename=\"1.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"payload\"\r\n\r\n{\n  \"folder:meta_data\": {\n    \"customer_session_id\": \"test_id_123456\"\n  },\n  \"media:tags\": {\n       \"photo1\": [\n      \"photo_selfie\"\n    ]\n  }\n}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
Request request = new Request.Builder()
  .url("https://youradress.ru/api/folders/")
  .post(body)
  .addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
  .addHeader("X-Forensic-Access-Token", "0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1")
  .addHeader("User-Agent", "PostmanRuntime/7.15.2")
  .addHeader("Accept", "*/*")
  .addHeader("Cache-Control", "no-cache")
  .addHeader("Postman-Token", "d500554e-8de5-4856-9723-832ada519efb,a31152f2-d8cc-4007-bf87-b88964eff756")
  .addHeader("Host", "youradress.ru")
  .addHeader("Accept-Encoding", "gzip, deflate")
  .addHeader("Content-Type", "multipart/form-data; boundary=--------------------------505656178980517917065194")
  .addHeader("Content-Length", "147649")
  .addHeader("Connection", "keep-alive")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();


            

Server response to the request for creation a target folder:

JSON

                
{
    "time_created": 1580120277,
    "time_updated": 1580120277,
    "meta_data": {
        "customer_session_id": "test_id_123456"
    },
    "folder_id": "132b7b74-b646-4486-94b3-daec8fc304b9",
    "resolution_time": null,
    "resolution_status": "INITIAL",
    "resolution_endpoint": null,
    "resolution_state_hash": "e20907e4c6101607",
    "resolution_comment": null,
    "resolution_suggest": null,
    "resolution_author_id": null,
    "is_archive": false,
    "media": [
        {
            "time_created": 1580120277,
            "time_updated": 1580120277,
            "meta_data": {},
            "media_id": "b7260a6e-d87d-4628-8940-3f513005dd88",
            "media_type": "IMAGE_FOLDER",
            "info": {
                "thumb": {
                    "md5": "1827f89da365f01a24deb0329d231f80",
                    "size": 18261,
                    "width": 300,
                    "height": 300,
                    "mime-type": "image/jpeg"
                },
                "original": {
                    "md5": "9b1393886e54d93e1303ff284ae4dedf",
                    "size": 147204,
                    "width": 492,
                    "height": 492,
                    "mime-type": "image/jpeg"
                }
            },
            "tags": [
                "photo_selfie"
            ],
            "original_name": "1.jpg",
            "image_id": "b7260a6e-d87d-4628-8940-3f513005dd88",
            "original_url": "http://youradress.ru/static/132b7b74-b646-4486-94b3-daec8fc304b9/b7260a6e-d87d-4628-8940-3f513005dd88.jpeg",
            "thumb_url": "http://youradress.ru/static/132b7b74-b646-4486-94b3-daec8fc304b9/b7260a6e-d87d-4628-8940-3f513005dd88_thumb.jpeg"
        }
    ],
    "analyses": []
}


            

Then we have to find in the system a folder with a particular “customer_session_id” parameter value with the use of Folder [LIST] method with metadata filtering.

Search requests within the task:

HTTP

Bash

Python

php

Java

                
GET /api/folders/?meta_data=customer_session_id==test_id_123456 HTTP/1.1
Host: youradress.ru
X-Forensic-Access-Token: 0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1
User-Agent: PostmanRuntime/7.15.2
Accept: */*
Cache-Control: no-cache
Postman-Token: a22b713a-ef9f-442e-a8e8-97228ceb8016,0583e0db-f856-4cbe-a9bf-c73989bfd4f0
Host: youradress.ru
Accept-Encoding: gzip, deflate
Connection: keep-alive
cache-control: no-cache


            
                
curl -X GET \
  'https://youradress.ru/api/folders/?meta_data=customer_session_id==test_id_123456' \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Host: youradress.ru' \
  -H 'Postman-Token: a22b713a-ef9f-442e-a8e8-97228ceb8016,9659fbab-0983-4ce3-ae7b-b89c549109b5' \
  -H 'User-Agent: PostmanRuntime/7.15.2' \
  -H 'X-Forensic-Access-Token: 0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1' \
  -H 'cache-control: no-cache'


            
                
import requests

url = "https://youradress.ru/api/folders/"

querystring = {"meta_data":"customer_session_id==test_id_123456"}

headers = {
    'X-Forensic-Access-Token': "0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1",
    'User-Agent': "PostmanRuntime/7.15.2",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Postman-Token': "a22b713a-ef9f-442e-a8e8-97228ceb8016,c3fcf80e-67ea-4622-8d34-52d78b2f310e",
    'Host': "youradress.ru",
    'Accept-Encoding': "gzip, deflate",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)


            
                
setUrl('https://youradress.ru/api/folders/');
$request->setMethod(HTTP_METH_GET);

$request->setQueryData(array(
  'meta_data' => 'customer_session_id==test_id_123456'
));

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'Connection' => 'keep-alive',
  'Accept-Encoding' => 'gzip, deflate',
  'Host' => 'youradress.ru',
  'Postman-Token' => 'a22b713a-ef9f-442e-a8e8-97228ceb8016,27eff900-6ab8-48a0-8408-ea3a9787eaa4',
  'Cache-Control' => 'no-cache',
  'Accept' => '*/*',
  'User-Agent' => 'PostmanRuntime/7.15.2',
  'X-Forensic-Access-Token' => '0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}


            
                
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://youradress.ru/api/folders/?meta_data=customer_session_id==test_id_123456")
  .get()
  .addHeader("X-Forensic-Access-Token", "0ccbdb4627c9d07c6c5b8f6e6cca44b5f8cb0c54ad7659098fa336240d494b0f9035e14bc42fc461224a9719f105e41026fed0f6f14188d9107b8c3d697a0cb1")
  .addHeader("User-Agent", "PostmanRuntime/7.15.2")
  .addHeader("Accept", "*/*")
  .addHeader("Cache-Control", "no-cache")
  .addHeader("Postman-Token", "a22b713a-ef9f-442e-a8e8-97228ceb8016,ae1f660d-19c9-428b-bfcb-6b70a5560b97")
  .addHeader("Host", "youradress.ru")
  .addHeader("Accept-Encoding", "gzip, deflate")
  .addHeader("Connection", "keep-alive")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();


            

Server response to the search request:

JSON

                
{
    "offset": 0,
    "limit": 20,
    "total_count": 1,
    "items": [
        {
            "time_created": 1580120277,
            "time_updated": 1580120277,
            "meta_data": {
                "customer_session_id": "test_id_123456"
            },
            "folder_id": "132b7b74-b646-4486-94b3-daec8fc304b9",
            "resolution_time": null,
            "resolution_status": "INITIAL",
            "resolution_endpoint": null,
            "resolution_state_hash": "e20907e4c6101607",
            "resolution_comment": null,
            "resolution_suggest": null,
            "resolution_author_id": null,
            "is_archive": false,
            "media": [
                {
                    "time_created": 1580120277,
                    "time_updated": 1580120277,
                    "meta_data": {},
                    "media_id": "b7260a6e-d87d-4628-8940-3f513005dd88",
                    "media_type": "IMAGE_FOLDER",
                    "info": {
                        "thumb": {
                            "md5": "1827f89da365f01a24deb0329d231f80",
                            "size": 18261,
                            "width": 300,
                            "height": 300,
                            "mime-type": "image/jpeg"
                        },
                        "original": {
                            "md5": "9b1393886e54d93e1303ff284ae4dedf",
                            "size": 147204,
                            "width": 492,
                            "height": 492,
                            "mime-type": "image/jpeg"
                        }
                    },
                    "tags": [
                        "photo_selfie"
                    ],
                    "original_name": "1.jpg",
                    "image_id": "b7260a6e-d87d-4628-8940-3f513005dd88",
                    "original_url": "http://youradress.ru/static/132b7b74-b646-4486-94b3-daec8fc304b9/b7260a6e-d87d-4628-8940-3f513005dd88.jpeg",
                    "thumb_url": "http://youradress.ru/static/132b7b74-b646-4486-94b3-daec8fc304b9/b7260a6e-d87d-4628-8940-3f513005dd88_thumb.jpeg"
                }
            ]
        }
    ]
}


            

One folder with the target “customer_session_id” was found in the available folders’ list that can be used for subsequent interactions and integration with external systems.