跳转到主要内容
POST
/
product-collections
/
{id}
/
groups
JavaScript
import DodoPayments from 'dodopayments';

const client = new DodoPayments({
  bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});

const productCollectionGroupResponse = await client.productCollections.groups.create(
  'pdc_8BWv0hojwUH7iCDabr0NI',
  { products: [{ product_id: 'product_id' }] },
);

console.log(productCollectionGroupResponse.group_id);
import os
from dodopayments import DodoPayments

client = DodoPayments(
bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"), # This is the default and can be omitted
)
product_collection_group_response = client.product_collections.groups.create(
id="pdc_8BWv0hojwUH7iCDabr0NI",
products=[{
"product_id": "product_id"
}],
)
print(product_collection_group_response.group_id)
package main

import (
"context"
"fmt"

"github.com/dodopayments/dodopayments-go"
"github.com/dodopayments/dodopayments-go/option"
)

func main() {
client := dodopayments.NewClient(
option.WithBearerToken("My Bearer Token"),
)
productCollectionGroupResponse, err := client.ProductCollections.Groups.New(
context.TODO(),
"pdc_8BWv0hojwUH7iCDabr0NI",
dodopayments.ProductCollectionGroupNewParams{
ProductCollectionGroupDetails: dodopayments.ProductCollectionGroupDetailsParam{
Products: dodopayments.F([]dodopayments.GroupProductParam{{
ProductID: dodopayments.F("product_id"),
}}),
},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", productCollectionGroupResponse.GroupID)
}
package com.dodopayments.api.example;

import com.dodopayments.api.client.DodoPaymentsClient;
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;
import com.dodopayments.api.models.productcollections.groups.GroupCreateParams;
import com.dodopayments.api.models.productcollections.groups.GroupProduct;
import com.dodopayments.api.models.productcollections.groups.ProductCollectionGroupDetails;
import com.dodopayments.api.models.productcollections.groups.ProductCollectionGroupResponse;

public final class Main {
private Main() {}

public static void main(String[] args) {
DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();

GroupCreateParams params = GroupCreateParams.builder()
.id("pdc_8BWv0hojwUH7iCDabr0NI")
.productCollectionGroupDetails(ProductCollectionGroupDetails.builder()
.addProduct(GroupProduct.builder()
.productId("product_id")
.build())
.build())
.build();
ProductCollectionGroupResponse productCollectionGroupResponse = client.productCollections().groups().create(params);
}
}
package com.dodopayments.api.example

import com.dodopayments.api.client.DodoPaymentsClient
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient
import com.dodopayments.api.models.productcollections.groups.GroupCreateParams
import com.dodopayments.api.models.productcollections.groups.GroupProduct
import com.dodopayments.api.models.productcollections.groups.ProductCollectionGroupDetails
import com.dodopayments.api.models.productcollections.groups.ProductCollectionGroupResponse

fun main() {
val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

val params: GroupCreateParams = GroupCreateParams.builder()
.id("pdc_8BWv0hojwUH7iCDabr0NI")
.productCollectionGroupDetails(ProductCollectionGroupDetails.builder()
.addProduct(GroupProduct.builder()
.productId("product_id")
.build())
.build())
.build()
val productCollectionGroupResponse: ProductCollectionGroupResponse = client.productCollections().groups().create(params)
}
require "dodopayments"

dodo_payments = Dodopayments::Client.new(
bearer_token: "My Bearer Token",
environment: "test_mode" # defaults to "live_mode"
)

product_collection_group_response = dodo_payments.product_collections.groups.create(
"pdc_8BWv0hojwUH7iCDabr0NI",
products: [{product_id: "product_id"}]
)

puts(product_collection_group_response)
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Dodopayments\Client;
use Dodopayments\Core\Exceptions\APIException;

$client = new Client(
bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
environment: 'test_mode',
);

try {
$productCollectionGroupResponse = $client->productCollections->groups->create(
'pdc_8BWv0hojwUH7iCDabr0NI',
products: [['productID' => 'product_id', 'status' => true]],
groupName: 'group_name',
status: true,
);

var_dump($productCollectionGroupResponse);
} catch (APIException $e) {
echo $e->getMessage();
}
using System;
using DodoPayments.Client;
using DodoPayments.Client.Models.ProductCollections.Groups;

DodoPaymentsClient client = new();

GroupCreateParams parameters = new()
{
ID = "pdc_8BWv0hojwUH7iCDabr0NI",
Products =
[
new()
{
ProductID = "product_id",
Status = true,
},
],
};

var productCollectionGroupResponse = await client.ProductCollections.Groups.Create(parameters);

Console.WriteLine(productCollectionGroupResponse);
use dodopayments::Client;

#[tokio::main]
async fn main() -> dodopayments::Result<()> {
let client = Client::from_env()?;
let id = "id";
let result = client
.product_collections()
.groups()
.create()
.id(id)
.body(dodopayments::models::ProductCollectionsGroupsCreateParams {
products: Some(vec![dodopayments::models::GroupProduct {
product_id: "product_id".to_string(),
status: None,
}]),
..Default::default()
})
.await?;
println!("{result:?}");
Ok(())
}
curl --request POST \
--url https://test.dodopayments.com/product-collections/{id}/groups \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"products": [
{
"product_id": "<string>",
"status": true
}
],
"group_name": "<string>",
"status": true
}
'
{
  "group_id": "<string>",
  "products": [
    {
      "addons_count": 123,
      "files_count": 123,
      "has_credit_entitlements": true,
      "id": "<string>",
      "is_recurring": true,
      "license_key_enabled": true,
      "meters_count": 123,
      "product_id": "<string>",
      "status": true,
      "description": "<string>",
      "name": "<string>",
      "price": 123,
      "price_detail": {
        "discount": 123,
        "price": 123,
        "purchasing_power_parity": true,
        "type": "one_time_price",
        "pay_what_you_want": true,
        "suggested_price": 123,
        "tax_inclusive": true
      },
      "tax_inclusive": true
    }
  ],
  "status": true,
  "group_name": "<string>"
}

授权

Authorization
string
header
必填

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

路径参数

id
string
必填

Product Collection Id

请求体

application/json
products
object[]
必填

Products in this group

group_name
string | null

Optional group name. Multiple groups can have null names, but named groups must be unique per collection

status
boolean | null

Status of the group (defaults to true if not provided)

响应

Group added successfully

group_id
string
必填
products
object[]
必填
status
boolean
必填
group_name
string | null
最后修改于 2026年6月18日