Skip to main content
Enough talking, let’s get to action!

Sending your first API request - create a new Product.

Let’s create a new product called Super Product.
Don’t forget to replace <YOUR_SECRET_KEY_HERE> with your API Secret Key
For more details about the Product Create endpoint, refer to its API Reference.
curl --request POST \
  --url https://pay.chargily.net/test/api/v2/products \
  --header 'Authorization: Bearer <YOUR_SECRET_KEY_HERE>' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "Super Product"
}'
import requests

url = "https://pay.chargily.net/test/api/v2/products"

payload = {"name": "Super Product"}
headers = {
    "Authorization": "Bearer <YOUR_SECRET_KEY_HERE>",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)
const options = {
  method: "POST",
  headers: {
    Authorization: "Bearer <YOUR_SECRET_KEY_HERE>",
    "Content-Type": "application/json",
  },
  body: '{"name":"Super Product"}',
};

fetch("https://pay.chargily.net/test/api/v2/products", options)
  .then((response) => response.json())
  .then((response) => console.log(response))
  .catch((err) => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://pay.chargily.net/test/api/v2/products",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n  \"name\": \"Super Product\"\n}",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <YOUR_SECRET_KEY_HERE>",
    "Content-Type: application/json"
  ],
]);

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

curl_close($curl);

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

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

func main() {

	url := "https://pay.chargily.net/test/api/v2/products"

	payload := strings.NewReader("{\n  \"name\": \"Super Product\"\n}")

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

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

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

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

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

}
HttpResponse<String> response = Unirest.post("https://pay.chargily.net/test/api/v2/products")
  .header("Authorization", "Bearer <YOUR_SECRET_KEY_HERE>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Super Product\"\n}")
  .asString();

Response

If everything worked, you should get a response like this:
json
{
  "id": "01hhyjnrdbc1xhgmd34hs1v3en",
  "entity": "product",
  "livemode": false,
  "name": "Super Product",
  "description": null,
  "images": [],
  "metadata": [],
  "created_at": 1702907011,
  "updated_at": 1702911993
}
Which is the Product object you just created. Good job!

Next

Next, you’ll create a Price for this product.

Create a price

Let’s now create a Price for the Product you just created.