# Get or assign and get voucher as Profile

- Operation ID: `GetOrAssignAndGetVoucherAsClient`
- HTTP method: `POST`
- Path: `/v4/vouchers/item/get-or-assign`
- [Human-readable API reference](https://hub.synerise.com/api-reference/loyalty-and-engagement#tag/Vouchers/operation/GetOrAssignAndGetVoucherAsClient)

## 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:
  /v4/vouchers/item/get-or-assign:
    post:
      tags:
        - Vouchers
      summary: Get or assign and get voucher as Profile
      description: |
        Retrieve the code assigned to a Profile. If no code was assigned earlier, the method assigns one.


        For each Profile, the same code is retrieved every time. This can be used, for example, to retrieve unique codes used to identify a Profile.

        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=authenticateUsingPOST_v3" target="_blank" rel="noopener">Profile (Client)</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=LogInAnonymouslyV3" target="_blank" rel="noopener">Anonymous Profile</a>, <span title="Available only on mobile SDKs">Incognito Profile</span>

        **User role permission required:** `assets_code_pool: read`
      operationId: GetOrAssignAndGetVoucherAsClient
      parameters:
        - name: Accept
          in: header
          required: true
          style: simple
          explode: false
          schema:
            type: string
            enum:
              - application/json
        - name: Content-Type
          in: header
          required: true
          style: simple
          explode: false
          schema:
            type: string
            enum:
              - application/json
        - name: Api-Version
          in: header
          required: true
          style: simple
          explode: false
          schema:
            type: string
            enum:
              - "4.4"
              - "4.2"
      requestBody:
        content:
          application/json:
            schema:
              required:
                - poolUuid
              type: object
              properties:
                poolUuid:
                  type: string
                  description: UUID of the voucher pool
                  example: faec32b0-c343-4362-ba32-c6148c649da4
                clientUuid:
                  deprecated: true
                  type: string
                  nullable: true
                  description: UUID of the Profile. This field is ignored.
                  example: 17243772-008a-42e1-ba37-c3807cebde8f
        required: true
      responses:
        "200":
          description: Details of the code
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    default: Code found with success
                  data:
                    type: object
                    description: Details of the voucher
                    properties:
                      code:
                        type: string
                        description: |
                          Voucher code
                          Must match the pattern: `^.{0,36}$`
                        example: code123
                        nullable: true
                      expireIn:
                        type: string
                        format: date-time
                        description: Date when the voucher expires.
                        nullable: true
                      redeemAt:
                        type: string
                        format: date-time
                        description: Time when the voucher was redeemed. Defaults to current time when redeeming.
                        nullable: true
                      assignedAt:
                        type: string
                        format: date-time
                        description: Time when the voucher was assigned. Defaults to current time when assigning.
                        nullable: true
                      createdAt:
                        type: string
                        format: date-time
                        description: Time when the voucher was created.
                      updatedAt:
                        type: string
                        format: date-time
                        description: Time when the voucher was last updated.
        "416":
          description: Range Not Satisfiable
          content:
            application/json:
              schema:
                required:
                  - message
                type: object
                properties:
                  message:
                    type: string
                    description: Details of the response
              example:
                message: Out of scope. Pool is empty.
      deprecated: false
      security:
        - JWT: []
      x-snr-doc-urls:
        - /api-reference/loyalty-and-engagement#tag/Vouchers/operation/GetOrAssignAndGetVoucherAsClient
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/v4/vouchers/item/get-or-assign \
              --header 'Accept: SOME_STRING_VALUE' \
              --header 'Api-Version: SOME_STRING_VALUE' \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'Content-Type: SOME_STRING_VALUE' \
              --header 'content-type: application/json' \
              --data '{"poolUuid":"faec32b0-c343-4362-ba32-c6148c649da4","clientUuid":"17243772-008a-42e1-ba37-c3807cebde8f"}'
        - lang: Python
          label: Python
          source: |-
            import http.client

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

            payload = "{\"poolUuid\":\"faec32b0-c343-4362-ba32-c6148c649da4\",\"clientUuid\":\"17243772-008a-42e1-ba37-c3807cebde8f\"}"

            headers = {
                'Accept': "SOME_STRING_VALUE",
                'Content-Type': "SOME_STRING_VALUE",
                'Api-Version': "SOME_STRING_VALUE",
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/v4/vouchers/item/get-or-assign", payload, headers)

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

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "poolUuid": "faec32b0-c343-4362-ba32-c6148c649da4",
              "clientUuid": "17243772-008a-42e1-ba37-c3807cebde8f"
            });

            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/v4/vouchers/item/get-or-assign");
            xhr.setRequestHeader("Accept", "SOME_STRING_VALUE");
            xhr.setRequestHeader("Content-Type", "SOME_STRING_VALUE");
            xhr.setRequestHeader("Api-Version", "SOME_STRING_VALUE");
            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": "/v4/vouchers/item/get-or-assign",
              "headers": {
                "Accept": "SOME_STRING_VALUE",
                "Content-Type": "SOME_STRING_VALUE",
                "Api-Version": "SOME_STRING_VALUE",
                "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({
              poolUuid: 'faec32b0-c343-4362-ba32-c6148c649da4',
              clientUuid: '17243772-008a-42e1-ba37-c3807cebde8f'
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/v4/vouchers/item/get-or-assign');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Accept' => 'SOME_STRING_VALUE',
              'Content-Type' => 'SOME_STRING_VALUE',
              'Api-Version' => 'SOME_STRING_VALUE',
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"poolUuid":"faec32b0-c343-4362-ba32-c6148c649da4","clientUuid":"17243772-008a-42e1-ba37-c3807cebde8f"}');

            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/v4/vouchers/item/get-or-assign")
              .header("Accept", "SOME_STRING_VALUE")
              .header("Content-Type", "SOME_STRING_VALUE")
              .header("Api-Version", "SOME_STRING_VALUE")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"poolUuid\":\"faec32b0-c343-4362-ba32-c6148c649da4\",\"clientUuid\":\"17243772-008a-42e1-ba37-c3807cebde8f\"}")
              .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: Vouchers
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.
```
