Update a subscription discount - Fabric

Update a subscription discount

cURL

curl --request PUT \
  --url https://prod01.copilot.fabric.inc/data-subscription/v1/subscriptionDiscount/{offerId} \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "discount": {
    "amount": 10
  },
  "message": "Offer terms and conditions",
  "skus": [
    "MOBO-X570"
  ],
  "categories": [
    "holiday-best-sellers"
  ],
  "frequency": {
    "shippingFrequency": 1,
    "shippingFrequencyType": "daily",
    "billingFrequency": 1,
    "billingFrequencyType": "daily"
  },
  "itemQuantity": 1,
  "channel": "WEBSITE",
  "target": "PDP"
}
'

Python

import requests

url = "https://prod01.copilot.fabric.inc/data-subscription/v1/subscriptionDiscount/{offerId}"

payload = {
    "discount": { "amount": 10 },
    "message": "Offer terms and conditions",
    "skus": ["MOBO-X570"],
    "categories": ["holiday-best-sellers"],
    "frequency": {
        "shippingFrequency": 1,
        "shippingFrequencyType": "daily",
        "billingFrequency": 1,
        "billingFrequencyType": "daily"
    },
    "itemQuantity": 1,
    "channel": "WEBSITE",
    "target": "PDP"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)

JavaScript (Fetch)

const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    discount: {amount: 10},
    message: 'Offer terms and conditions',
    skus: ['MOBO-X570'],
    categories: ['holiday-best-sellers'],
    frequency: {
      shippingFrequency: 1,
      shippingFrequencyType: 'daily',
      billingFrequency: 1,
      billingFrequencyType: 'daily'
    },
    itemQuantity: 1,
    channel: 'WEBSITE',
    target: 'PDP'
  })
};

fetch('https://prod01.copilot.fabric.inc/data-subscription/v1/subscriptionDiscount/{offerId}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

PHP

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://prod01.copilot.fabric.inc/data-subscription/v1/subscriptionDiscount/{offerId}",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => json_encode([
    'discount' => [
        'amount' => 10
    ],
    'message' => 'Offer terms and conditions',
    'skus' => [
        'MOBO-X570'
    ],
    'categories' => [
        'holiday-best-sellers'
    ],
    'frequency' => [
        'shippingFrequency' => 1,
        'shippingFrequencyType' => 'daily',
        'billingFrequency' => 1,
        'billingFrequencyType' => 'daily'
    ],
    'itemQuantity' => 1,
    'channel' => 'WEBSITE',
    'target' => 'PDP'
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Go

package main

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

func main() {

url := "https://prod01.copilot.fabric.inc/data-subscription/v1/subscriptionDiscount/{offerId}"

payload := strings.NewReader("{\n  \"discount\": {\n    \"amount\": 10\n  },\n  \"message\": \"Offer terms and conditions\",\n  \"skus\": [\n    \"MOBO-X570\"\n  ],\n  \"categories\": [\n    \"holiday-best-sellers\"\n  ],\n  \"frequency\": {\n    \"shippingFrequency\": 1,\n    \"shippingFrequencyType\": \"daily\",\n    \"billingFrequency\": 1,\n    \"billingFrequencyType\": \"daily\"\n  },\n  \"itemQuantity\": 1,\n  \"channel\": \"WEBSITE\",\n  \"target\": \"PDP\"\n}")

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

req.Header.Add("Authorization", "Bearer <token>")
    req.Header.Add("Content-Type", "application/json")

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

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

fmt.Println(string(body))
}

Java

HttpResponse<String> response = Unirest.put("https://prod01.copilot.fabric.inc/data-subscription/v1/subscriptionDiscount/{offerId}")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"discount\": {\n    \"amount\": 10\n  },\n  \"message\": \"Offer terms and conditions\",\n  \"skus\": [\n    \"MOBO-X570\"\n  ],\n  \"categories\": [\n    \"holiday-best-sellers\"\n  ],\n  \"frequency\": {\n    \"shippingFrequency\": 1,\n    \"shippingFrequencyType\": \"daily\",\n    \"billingFrequency\": 1,\n    \"billingFrequencyType\": \"daily\"\n  },\n  \"itemQuantity\": 1,\n  \"channel\": \"WEBSITE\",\n  \"target\": \"PDP\"}\n")
  .asString();

Ruby

require 'uri'
require 'net/http'

url = URI("https://prod01.copilot.fabric.inc/data-subscription/v1/subscriptionDiscount/{offerId}")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"discount\": {\n    \"amount\": 10\n  },\n  \"message\": \"Offer terms and conditions\",\n  \"skus\": [\n    \"MOBO-X570\"\n  ],\n  \"categories\": [\n    \"holiday-best-sellers\"\n  ],\n  \"frequency\": {\n    \"shippingFrequency\": 1,\n    \"shippingFrequencyType\": \"daily\",\n    \"billingFrequency\": 1,\n    \"billingFrequencyType\": \"daily\"\n  },\n  \"itemQuantity\": 1,\n  \"channel\": \"WEBSITE\",\n  \"target\": \"PDP\"}\n"

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

Response examples

Success (200)

{
  "responseStatus": "OK",
  "message": "Request processed successfully",
  "data": {
    "id": "62d9196aeec12800095633f2",
    "status": "ACTIVE",
    "offerCode": "SUB-D45DD7",
    "validity": {
      "startDate": "2022-07-21T13:14:51.474Z",
      "endDate": "2022-07-21T13:14:51.474Z",
      "applyOnOrders": [
        2,
        3
      ]
    },
    "message": "Offer terms and conditions",
    "discount": {
      "amount": 10
    },
    "skus": [
      "MOBO-X570"
    ],
    "categories": [
      "holiday-best-sellers"
    ],
    "frequency": {
      "shippingFrequency": 1,
      "shippingFrequencyType": "daily",
      "billingFrequency": 1,
      "billingFrequencyType": "daily"
    },
    "itemQuantity": 1,
    "channel": "WEBSITE",
    "target": "PDP",
    "customerSegment": [
      "employee"
    ],
    "isDeleted": false,
    "DeletedAt": "2019-01-01T00:00:00.000Z",
    "createdAt": "2021-10-12T21:35:05.756Z",
    "updatedAt": "2021-10-14T05:40:55.997Z"
  }
}

Bad Request (400)

{
  "responseStatus": "BAD_REQUEST",
  "message": "Bad request"
}

Unauthorized (403)

{
  "Message": "User is not authorized to access this resource with an explicit deny"
}

Not Found (404)

{
  "responseStatus": "NOT_FOUND",
  "message": "Not found"
}