Update items in bundle - Fabric

Update items in bundle

cURL

curl --request POST \
  --url https://live.copilot.fabric.inc/api-product/v1/product/bundle/update \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-site-context: <x-site-context>' \
  --data '
{
  "action": "UPDATE",
  "bundles": [
    {
      "action": "SET",
      "bundleSku": "iPhoneBundle",
      "itemSku": "iPhone12",
      "quantity": 1
    }
  ]
}
'```

### Python

```python
import requests

url = "https://live.copilot.fabric.inc/api-product/v1/product/bundle/update"

payload = {
    "action": "UPDATE",
    "bundles": [
        {
            "action": "SET",
            "bundleSku": "iPhoneBundle",
            "itemSku": "iPhone12",
            "quantity": 1
        }
    ]
}
headers = {
    "x-site-context": "<x-site-context>",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)

JavaScript (Fetch)

const options = {
  method: 'POST',
  headers: {
    'x-site-context': '<x-site-context>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    action: 'UPDATE',
    bundles: [{action: 'SET', bundleSku: 'iPhoneBundle', itemSku: 'iPhone12', quantity: 1}]
  })
};

fetch('https://live.copilot.fabric.inc/api-product/v1/product/bundle/update', 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://live.copilot.fabric.inc/api-product/v1/product/bundle/update",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'action' => 'UPDATE',
    'bundles' => [
        [
            'action' => 'SET',
            'bundleSku' => 'iPhoneBundle',
            'itemSku' => 'iPhone12',
            'quantity' => 1
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json",
    "x-site-context: <x-site-context>"
  ],
]);

$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://live.copilot.fabric.inc/api-product/v1/product/bundle/update"

payload := strings.NewReader("{\n  \"action\": \"UPDATE\",\n  \"bundles\": [\n    {\n      \"action\": \"SET\",\n      \"bundleSku\": \"iPhoneBundle\",\n      \"itemSku\": \"iPhone12\",\n      \"quantity\": 1\n    }\n  ]\n}")

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

req.Header.Add("x-site-context", "<x-site-context>")
    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 (Unirest)

HttpResponse<String> response = Unirest.post("https://live.copilot.fabric.inc/api-product/v1/product/bundle/update")
  .header("x-site-context", "<x-site-context>")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"action\": \"UPDATE\",\n  \"bundles\": [\n    {\n      \"action\": \"SET\",\n      \"bundleSku\": \"iPhoneBundle\",\n      \"itemSku\": \"iPhone12\",\n      \"quantity\": 1\n    }\n  ]\n}")
  .asString();

Ruby

require 'uri'
require 'net/http'

url = URI("https://live.copilot.fabric.inc/api-product/v1/product/bundle/update")

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

request = Net::HTTP::Post.new(url)
request["x-site-context"] = '<x-site-context>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"action\": \"UPDATE\",\n  \"bundles\": [\n    {\n      \"action\": \"SET\",\n      \"bundleSku\": \"iPhoneBundle\",\n      \"itemSku\": \"iPhone12\",\n      \"quantity\": 1\n    }\n  ]\n}";

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

Response Examples

Success (200)

[
  {
    "id": "625367673ab7402268d8cccf",
    "itemId": "624d94fb27c894222534b260",
    "bundleId": "624d939227c894222534b247",
    "quantity": 1,
    "createdOn": "2022-04-08T23:25:27.753Z",
    "modifiedOn": "2022-04-08T23:25:27.753Z"
  }
]

Client Error (400)

{
  "code": 400,
  "message": "Client error"
}

Internal Error (500)

{
  "code": 500,
  "message": "An internal error occurred. If the issue persists please contact support@fabric.inc."
}