# Preview screen view with a profile context

- Operation ID: `generateScreenViewByIdentifierPostV2`
- HTTP method: `POST`
- Path: `/schema-service/v2/screen-views/{feedSlug}/generate/by/{identifierType}`
- [Human-readable API reference](https://hub.synerise.com/api-reference/loyalty-and-engagement#tag/Screen-views/operation/generateScreenViewByIdentifierPostV2)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /schema-service/v2/screen-views/{feedSlug}/generate/by/{identifierType}:
    post:
      tags:
        - Screen views
      summary: Preview screen view with a profile context
      description: |
        This endpoint can be used to preview a generated document as a Workspace or Synerise User. To generate the output as a profile (client), use one of the following methods:
        - [POST `/v3/screen-views/{feedSlug}/generate`](#operation/generateScreenViewByFeedPostV2)
        - [GET `/v3/screen-views/{feedSlug}/generate`](#operation/generateScreenViewByFeedGetV2)


        When this method is called, the Synerise backend finds all screen view campaigns in the requested feed which are applicable to the profile and returns the screen view with the highest priority (1). Inserts are processed. If an insert can't be processed, the returned `data` is empty.


        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>

        **API key permission required:** `SCHEMA_SERVICE_SCHEMA_READ`

        **User role permission required:** `assets_docs: read`
      operationId: generateScreenViewByIdentifierPostV2
      security:
        - JWT: []
      parameters:
        - in: path
          name: feedSlug
          description: Slug of the screen view feed
          required: true
          schema:
            type: string
        - in: path
          name: identifierType
          description: Type of the profile identifier. The value is sent in `identifierValue` in the request body.
          required: true
          schema:
            type: string
            enum:
              - id
              - uuid
              - email
              - custom_identify
      requestBody:
        content:
          application/json:
            schema:
              title: Generate Screen View Request Data
              type: object
              required:
                - identifierValue
              properties:
                identifierValue:
                  type: string
                  description: Value of the profile identifier selected in `identifierType` (profile ID is sent as a string)
                params:
                  type: object
                  description: Additional parameters
                  additionalProperties:
                    description: |
                      If you are generating the resource with a context that doesn't have the data for inserts in the resource (for example, a document has a `{% customer param %}` insert, but you're authenticated with a workspace JWT, so the customer context can't be extracted from the JWT), you can include the parameters in the request body. If an insert can't be processed, the returned content is empty.

                      **Usage example**: if the `{% customer firstName %}` insert is used in a document, you can pass its value by sending `"customer.firstName": "Joe"`

                      Because inserts are always encapsulated with quotation marks, inserts that return a number or a boolean value return it as a string.
                    anyOf:
                      - type: string
                      - type: number
      responses:
        "200":
          description: Processed JSON content
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                  - hash
                  - priority
                  - name
                  - createdAt
                  - updatedAt
                  - audience
                  - data
                  - path
                properties:
                  id:
                    type: string
                    format: uuid
                    description: UUID of the screen view
                  hash:
                    type: string
                    format: uuid
                    description: UUID of the screen view
                  priority:
                    type: integer
                    description: Priority determines which screen view to show to a customer if their profile matches the conditions of more than one screen view. `1` is the highest priority.
                    default: 99
                  name:
                    type: string
                    description: Name of the screen view
                  createdAt:
                    type: string
                    description: Creation date
                    format: date-time
                  updatedAt:
                    type: string
                    format: date-time
                    description: Last update time
                  audience:
                    type: object
                    description: The profiles (clients) which have access to this resource
                    required:
                      - targetType
                    properties:
                      targetType:
                        type: string
                        description: |
                          The method of defining the audience:
                          - SEGMENT sets the audience to segmentations whose UUIDs are provided in `segments`
                          - QUERY sets the audience to an analytics query provided in `query`
                          - ALL sets the audience to all profiles in the database
                        enum:
                          - SEGMENT
                          - QUERY
                          - ALL
                      segments:
                        type: array
                        description: "An array of segmentation IDs. Used with `targetType: SEGMENT`"
                        items:
                          type: string
                      query:
                        type: string
                        description: "Stringified `analysis` object for the segmentation analytics engine. Used with `targetType: QUERY`. Refer to the [Analytics API Reference](https://developers.synerise.com/#operation/addSegmentationPOST_v2)."
                        example: '{"analysis":{"title":"Unnamed segmentation","description":"","unique":true,"segments":[{"title":"Segmentation A","description":"","filter":{"matching":true,"expressions":[{"_id":"a9b76c8e-34bd-4ac3-be8f-f37041d126bd","name":"","type":"FUNNEL","matching":true,"funnel":{"_id":"5c759d73-49c6-409f-96a3-b569dff8f8ff","title":"Unnamed","completedWithin":null,"dateFilter":{"type":"RELATIVE","offset":{"type":"DAYS","value":0},"duration":{"type":"DAYS","value":30}},"steps":[{"_id":"78b97ae0-1bc5-45fb-82a4-4f1280cfbdff","title":"","action":{"id":944,"name":"page.visit"},"eventName":"page.visit","expressions":[]}],"exact":false}}]}}]}}'
                  data:
                    type: object
                    description: The JSON structure of the screen view, with inserts processed
                    properties:
                      collection:
                        type: array
                        description: By default, the `collection` property exists in each screen view, unless the default content was overwritten. This property's value is the output of the `{% screenviewcollection %}` insert. If you moved the insert into a different position in the JSON structure, its result (the array) will be stored at the position where you placed the insert (you can modify the screen definition so that the insert is under a key different than `collection`).
                        items:
                          type: object
                          description: Processed document
                          required:
                            - id
                            - slug
                            - schema
                            - content
                          properties:
                            uuid:
                              type: string
                              format: uuid
                              description: UUID of the document
                            slug:
                              type: string
                              description: Slug of the document
                              example: basket
                              pattern: "[a-z0-9]+(?:-[a-z0-9]+)*"
                            schema:
                              type: string
                              description: Schema of the document (called "Type" in the Synerise Web Application)
                              example: containers
                            content:
                              description: Content of the document
                              anyOf:
                                - type: object
                                  description: The processed JSON content of the document
                                  additionalProperties:
                                    description: JSON keys in the document and their values
                                  example:
                                    someBoolean: true
                                    someString: Lorem ipsum
                                    aNestedDocument:
                                      uuid: 772d94f7-a604-409a-bfa9-24a64b8a5051
                                      slug: apple
                                      schema: fruit
                                      content:
                                        color: red
                                - type: string
                                  description: Processed string value of a document (for example, a small document which only includes an insert to return an expression result)
                    additionalProperties:
                      description: Other JSON entities included in the screen view's JSON structure.
                  path:
                    type: string
                    description: Address of the screen view definition
                    example: /v2/screen-views/f9215cb9-4a7e-410b-88cb-8bc40363cc10
        "400":
          description: See error message for details
          content:
            application/json:
              schema:
                type: object
                properties:
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred
                  errorCode:
                    type: string
                    description: |
                      Code of the error, needed for troubleshooting

                      See error reference: [https://developers.synerise.com/errors.html](https://developers.synerise.com/errors.html)
                  status:
                    type: integer
                    description: Error's HTTP status code
                  message:
                    type: string
                    description: Description of the problem
        "401":
          description: "Unauthorized: wrong consumer scope; token missing/expired/invalid; invalid API key; etc."
          content:
            application/json:
              schema:
                type: object
                properties:
                  timestamp:
                    type: string
                    description: Time when the error occurred
                  error:
                    type: string
                    description: Summary of the error
                  message:
                    type: string
                    description: Description of the problem
                  status:
                    type: integer
                    format: int32
                    description: HTTP status code
        "403":
          description: Forbidden; insufficient permissions
          content:
            application/json:
              schema:
                type: object
                properties:
                  timestamp:
                    type: string
                    description: Time when the error occurred
                  error:
                    type: string
                    description: Summary of the error
                  message:
                    type: string
                    description: Description of the problem
                  status:
                    type: integer
                    format: int32
                    description: HTTP status code
        "404":
          description: Resource not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred
                  errorCode:
                    type: string
                    description: |
                      Code of the error, needed for troubleshooting

                      See error reference: [https://developers.synerise.com/errors.html](https://developers.synerise.com/errors.html)
                  status:
                    type: integer
                    description: Error's HTTP status code
                  message:
                    type: string
                    description: Description of the problem
        "500":
          description: See error message for details
          content:
            application/json:
              schema:
                type: object
                properties:
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred
                  errorCode:
                    type: string
                    description: |
                      Code of the error, needed for troubleshooting

                      See error reference: [https://developers.synerise.com/errors.html](https://developers.synerise.com/errors.html)
                  status:
                    type: integer
                    description: Error's HTTP status code
                  message:
                    type: string
                    description: Description of the problem
      x-snr-doc-urls:
        - /api-reference/loyalty-and-engagement#tag/Screen-views/operation/generateScreenViewByIdentifierPostV2
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/schema-service/v2/screen-views/%7BfeedSlug%7D/generate/by/%7BidentifierType%7D \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"identifierValue":"string","params":{"property1":"string","property2":"string"}}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"identifierValue\":\"string\",\"params\":{\"property1\":\"string\",\"property2\":\"string\"}}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/schema-service/v2/screen-views/%7BfeedSlug%7D/generate/by/%7BidentifierType%7D", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "identifierValue": "string",
              "params": {
                "property1": "string",
                "property2": "string"
              }
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/schema-service/v2/screen-views/%7BfeedSlug%7D/generate/by/%7BidentifierType%7D");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/schema-service/v2/screen-views/%7BfeedSlug%7D/generate/by/%7BidentifierType%7D",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({identifierValue: 'string', params: {property1: 'string', property2: 'string'}}));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/schema-service/v2/screen-views/%7BfeedSlug%7D/generate/by/%7BidentifierType%7D');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"identifierValue":"string","params":{"property1":"string","property2":"string"}}');

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

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/schema-service/v2/screen-views/%7BfeedSlug%7D/generate/by/%7BidentifierType%7D")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"identifierValue\":\"string\",\"params\":{\"property1\":\"string\",\"property2\":\"string\"}}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Screen views
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
