previewSegment
Query CRM API — POST https://crm.api.gist.link/graphql
Live preview of an unsaved criteria set: count + a member sample.
Required permission
Section titled “Required permission”crm:query:previewSegmentThe calling IAM key must hold this permission (or a wildcard that covers it:
crm:query:* or crm:*) and the access token
must have been minted with audience=crm. See
Permissions.
Definition
Section titled “Definition”type Query { previewSegment(targetType: String!, criteria: JSON!, first: Int): SegmentPreview!}Arguments
Section titled “Arguments”| Argument | Type | Required | Description |
|---|---|---|---|
targetType |
String! |
Yes | — |
criteria |
JSON! |
Yes | — |
first |
Int |
No | — |
Returns
Section titled “Returns”SegmentPreview! — see the CRM types reference.
Example
Section titled “Example”curl https://crm.api.gist.link/graphql \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H 'Content-Type: application/json' \ -d @- <<'JSON' { "query": "query PreviewSegment($targetType: String!, $criteria: JSON!, $first: Int) { previewSegment(targetType: $targetType, criteria: $criteria, first: $first) { count members } }", "variables": { "targetType": "example", "criteria": {}, "first": 10 } }JSONconst response = await fetch('https://crm.api.gist.link/graphql', { method: 'POST', headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ query: `query PreviewSegment($targetType: String!, $criteria: JSON!, $first: Int) { previewSegment(targetType: $targetType, criteria: $criteria, first: $first) { count members } }`, variables: { "targetType": "example", "criteria": {}, "first": 10 }, }),});
const { data, errors } = await response.json();if (errors) throw new Error(errors[0].message);console.log(data);<?php
$payload = json_encode([ 'query' => 'query PreviewSegment($targetType: String!, $criteria: JSON!, $first: Int) { previewSegment(targetType: $targetType, criteria: $criteria, first: $first) { count members } }', 'variables' => json_decode('{"targetType":"example","criteria":{},"first":10}', true),]);
$ch = curl_init('https://crm.api.gist.link/graphql');curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . $accessToken, 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => $payload,]);
$result = json_decode(curl_exec($ch), true);curl_close($ch);
if (isset($result['errors'])) { throw new RuntimeException($result['errors'][0]['message']);}
var_dump($result['data']);import requests
response = requests.post( "https://crm.api.gist.link/graphql", headers={ "Authorization": f"Bearer {access_token}", "Content-Type": "application/json", }, json={ "query": """query PreviewSegment($targetType: String!, $criteria: JSON!, $first: Int) { previewSegment(targetType: $targetType, criteria: $criteria, first: $first) { count members } }""", "variables": { "targetType": "example", "criteria": {}, "first": 10 }, }, timeout=30,)body = response.json()if body.get("errors"): raise RuntimeError(body["errors"][0]["message"])print(body["data"])