Home / Selection / Random row

Selection ‐ Random row


Getting random row from a selection

Endpoint

GET /api/selection/:selectionId/random

Parameters:

  • :selectionId is the id of the selection from which we want to obtain random row.

Headers

see Using authentication token

Response

  • Invalid response: See Invalid response in Standard response rules
  • Valid response contains info if its indeed valid (property valid of the returned JSON), data of the random row and extra info about eventual e-mail field in that data (which field from the returned row is of type e-mail, if none of the fields is of this type then extra.email _field.field_name === null

        {
            "valid": true,
            "data": [ 
                {
                    "table_name.email": "some@email.com",
                    "table_name.field": "value 1"
                },
                {
                    "table_name.email": "other@email.com",
                    "table_name.field": "value 2"
                }, 
            ],
            "extra": {
               "email_field": {
                   "field_name": null
               }
            },
            "pagination": {
                "next_page"      : 2,
                "rows_per_page"  : 2,
                "total_rows"     : 4,
                "total_pages"    : 2
            } 
        }

Example code:

<?php

require_once 'RestOpen.php';

$username = 'my_username';
$password = 'my_password';
$workspaceId = 999;
$selectionId = 999;

$rest = new RestOpen($username, $password, $workspaceId);
$result = $rest->getSelectionRandomRow($selectionId);

var_dump($result);