# Grant loyalty points (proxy)

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://apidocs.cata.sg/pos-integration-service-api/api/v-1/loyalty/earn-points/llms.txt.
> For full documentation content, see https://apidocs.cata.sg/pos-integration-service-api/api/v-1/loyalty/earn-points/llms-full.txt.

POST http://localhost:8080/api/v1/loyalty/earn-points
Content-Type: application/json

Proxy to loyalty-service `POST /v1/h2h/grant-points`. Resolves the
tenant's loyalty credential from per-tenant configuration and
forwards the request. Idempotent via `refCode`.


Reference: https://apidocs.cata.sg/pos-integration-service-api/api/v-1/loyalty/earn-points/grant-loyalty-points-proxy

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: collection
  version: 1.0.0
paths:
  /api/v1/loyalty/earn-points:
    post:
      operationId: grant-loyalty-points-proxy
      summary: Grant loyalty points (proxy)
      description: |
        Proxy to loyalty-service `POST /v1/h2h/grant-points`. Resolves the
        tenant's loyalty credential from per-tenant configuration and
        forwards the request. Idempotent via `refCode`.
      tags:
        - >-
          subpackage_api.subpackage_api/v1.subpackage_api/v1/loyalty.subpackage_api/v1/loyalty/earnPoints
      parameters:
        - name: X-Api-Key
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/api_v1_loyalty_earn-points_Grant loyalty
                  points (proxy)_Response_200
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PostApiV1LoyaltyEarn-pointsRequestBadRequestError
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PostApiV1LoyaltyEarn-pointsRequestUnauthorizedError
        '502':
          description: Bad Gateway
          content:
            application/json:
              schema:
                description: Any type
        '503':
          description: Service Unavailable
          content:
            application/json:
              schema:
                description: Any type
        '504':
          description: Gateway Timeout
          content:
            application/json:
              schema:
                description: Any type
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                customerUuid:
                  type: string
                  format: uuid
                points:
                  type: integer
                refCode:
                  type: string
                displayNotes:
                  type: string
              required:
                - customerUuid
                - points
                - refCode
                - displayNotes
servers:
  - url: http://localhost:8080
components:
  schemas:
    api_v1_loyalty_earn-points_Grant loyalty points (proxy)_Response_200:
      type: object
      properties:
        code:
          type: integer
        isSuccess:
          type: boolean
        message:
          type: string
      required:
        - code
        - isSuccess
        - message
      title: api_v1_loyalty_earn-points_Grant loyalty points (proxy)_Response_200
    ApiV1LoyaltyEarnPointsPostResponsesContentApplicationJsonSchemaError:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
        details:
          type: string
        field:
          type: string
      required:
        - code
        - message
        - details
        - field
      title: ApiV1LoyaltyEarnPointsPostResponsesContentApplicationJsonSchemaError
    PostApiV1LoyaltyEarn-pointsRequestBadRequestError:
      type: object
      properties:
        error:
          $ref: >-
            #/components/schemas/ApiV1LoyaltyEarnPointsPostResponsesContentApplicationJsonSchemaError
      required:
        - error
      title: PostApiV1LoyaltyEarn-pointsRequestBadRequestError
    PostApiV1LoyaltyEarn-pointsRequestUnauthorizedError:
      type: object
      properties:
        error:
          $ref: >-
            #/components/schemas/ApiV1LoyaltyEarnPointsPostResponsesContentApplicationJsonSchemaError
      required:
        - error
      title: PostApiV1LoyaltyEarn-pointsRequestUnauthorizedError
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key

```

## SDK Code Examples

```python api_v1_loyalty_earn-points_Grant loyalty points (proxy)_example
import requests

url = "http://localhost:8080/api/v1/loyalty/earn-points"

payload = {
    "customerUuid": "61953923-1d28-11f1-ae62-42010a0a200d",
    "points": 25,
    "refCode": "order-12345-earn",
    "displayNotes": "Reward for order #12345"
}
headers = {
    "X-Api-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript api_v1_loyalty_earn-points_Grant loyalty points (proxy)_example
const url = 'http://localhost:8080/api/v1/loyalty/earn-points';
const options = {
  method: 'POST',
  headers: {'X-Api-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"customerUuid":"61953923-1d28-11f1-ae62-42010a0a200d","points":25,"refCode":"order-12345-earn","displayNotes":"Reward for order #12345"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go api_v1_loyalty_earn-points_Grant loyalty points (proxy)_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://localhost:8080/api/v1/loyalty/earn-points"

	payload := strings.NewReader("{\n  \"customerUuid\": \"61953923-1d28-11f1-ae62-42010a0a200d\",\n  \"points\": 25,\n  \"refCode\": \"order-12345-earn\",\n  \"displayNotes\": \"Reward for order #12345\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-Api-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby api_v1_loyalty_earn-points_Grant loyalty points (proxy)_example
require 'uri'
require 'net/http'

url = URI("http://localhost:8080/api/v1/loyalty/earn-points")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["X-Api-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"customerUuid\": \"61953923-1d28-11f1-ae62-42010a0a200d\",\n  \"points\": 25,\n  \"refCode\": \"order-12345-earn\",\n  \"displayNotes\": \"Reward for order #12345\"\n}"

response = http.request(request)
puts response.read_body
```

```java api_v1_loyalty_earn-points_Grant loyalty points (proxy)_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://localhost:8080/api/v1/loyalty/earn-points")
  .header("X-Api-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"customerUuid\": \"61953923-1d28-11f1-ae62-42010a0a200d\",\n  \"points\": 25,\n  \"refCode\": \"order-12345-earn\",\n  \"displayNotes\": \"Reward for order #12345\"\n}")
  .asString();
```

```php api_v1_loyalty_earn-points_Grant loyalty points (proxy)_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:8080/api/v1/loyalty/earn-points', [
  'body' => '{
  "customerUuid": "61953923-1d28-11f1-ae62-42010a0a200d",
  "points": 25,
  "refCode": "order-12345-earn",
  "displayNotes": "Reward for order #12345"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Api-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp api_v1_loyalty_earn-points_Grant loyalty points (proxy)_example
using RestSharp;

var client = new RestClient("http://localhost:8080/api/v1/loyalty/earn-points");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Api-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"customerUuid\": \"61953923-1d28-11f1-ae62-42010a0a200d\",\n  \"points\": 25,\n  \"refCode\": \"order-12345-earn\",\n  \"displayNotes\": \"Reward for order #12345\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift api_v1_loyalty_earn-points_Grant loyalty points (proxy)_example
import Foundation

let headers = [
  "X-Api-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "customerUuid": "61953923-1d28-11f1-ae62-42010a0a200d",
  "points": 25,
  "refCode": "order-12345-earn",
  "displayNotes": "Reward for order #12345"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:8080/api/v1/loyalty/earn-points")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```