{
    "info": {
        "name": "Affilibee API (Sandbox)",
        "description": "Postman collection for Affilibee API (Sandbox)",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "item": [
        {
            "name": "Affiliate Invites",
            "item": [
                {
                    "name": "List affiliate invites",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/affiliates/invites",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "affiliates",
                                "invites"
                            ],
                            "query": [
                                {
                                    "key": "per_page",
                                    "value": "15",
                                    "description": "The number of invites to return per page. Default is 15.",
                                    "disabled": true
                                },
                                {
                                    "key": "page",
                                    "value": "1",
                                    "description": "The page number to retrieve.",
                                    "disabled": true
                                },
                                {
                                    "key": "email",
                                    "value": "example.com",
                                    "description": "Filter invites by affiliate email (partial match).",
                                    "disabled": true
                                }
                            ],
                            "variable": []
                        },
                        "description": "API reference for retrieving a paginated list of affiliate invitations for the authenticated merchant.\n\nOnly invitations associated with your merchant account are returned."
                    }
                },
                {
                    "name": "Invite affiliate",
                    "request": {
                        "method": "POST",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            },
                            {
                                "key": "Content-Type",
                                "value": "application/json"
                            }
                        ],
                        "body": {
                            "mode": "raw",
                            "raw": "{\n    \"email\": \"{{$randomEmail}}\",\n    \"sender_email\": \"{{sender_email}}\",\n    \"content\": \"We would love to have you in our affiliate program!\"\n}"
                        },
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/affiliates/invite",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "affiliates",
                                "invite"
                            ],
                            "query": [],
                            "variable": []
                        },
                        "description": "API reference for inviting a new affiliate to your program.\n\n"
                    }
                }
            ]
        },
        {
            "name": "Affiliate Requests",
            "item": [
                {
                    "name": "Accept affiliate request",
                    "request": {
                        "method": "POST",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/affiliate-requests/:uuid/accept",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "affiliate-requests",
                                ":uuid",
                                "accept"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "uuid",
                                    "value": "{{affiliate_request_uuid}}",
                                    "description": "Filled in from the affiliate_request_uuid collection variable."
                                }
                            ]
                        },
                        "description": "Accept a pending affiliate request for your merchant account.\n\nAccepting a request will move the affiliate to your active affiliate list.\nThe affiliate will be notified of the acceptance."
                    }
                },
                {
                    "name": "Decline affiliate request",
                    "request": {
                        "method": "POST",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/affiliate-requests/:uuid/decline",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "affiliate-requests",
                                ":uuid",
                                "decline"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "uuid",
                                    "value": "{{affiliate_request_uuid}}",
                                    "description": "Filled in from the affiliate_request_uuid collection variable."
                                }
                            ]
                        },
                        "description": "Decline a pending affiliate request for your merchant account.\n\nDeclining a request will notify the affiliate of the decision.\nDeclined requests can still be viewed in the declined requests list."
                    }
                },
                {
                    "name": "List affiliate requests",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/affiliate-requests",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "affiliate-requests"
                            ],
                            "query": [
                                {
                                    "key": "status",
                                    "value": "pending",
                                    "description": "Filter requests by status. Allowed values: pending, accepted, declined. Multiple values can be separated by a comma. Default: pending.",
                                    "disabled": true
                                },
                                {
                                    "key": "per_page",
                                    "value": "15",
                                    "description": "Number of results per page. Default: 15.",
                                    "disabled": true
                                },
                                {
                                    "key": "page",
                                    "value": "1",
                                    "description": "The page number to retrieve. Default: 1.",
                                    "disabled": true
                                }
                            ],
                            "variable": []
                        },
                        "description": "Retrieve a paginated list of affiliate requests for your merchant account.\n\nAffiliate requests are created when an affiliate applies to join your program.\nThe default behavior is to return only pending requests. Use the status filter to retrieve accepted or declined requests."
                    },
                    "event": [
                        {
                            "listen": "test",
                            "script": {
                                "type": "text/javascript",
                                "exec": [
                                    "// Saves data.0.uuid as {{affiliate_request_uuid}} for the requests that use it.",
                                    "const value = pm.response.code < 300 ? pm.response.json()?.data?.[0]?.uuid : undefined;",
                                    "if (value && !pm.collectionVariables.get('affiliate_request_uuid')) {",
                                    "    pm.collectionVariables.set('affiliate_request_uuid', value);",
                                    "}"
                                ]
                            }
                        }
                    ]
                },
                {
                    "name": "Show affiliate request",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/affiliate-requests/:uuid",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "affiliate-requests",
                                ":uuid"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "uuid",
                                    "value": "{{affiliate_request_uuid}}",
                                    "description": "Filled in from the affiliate_request_uuid collection variable."
                                }
                            ]
                        },
                        "description": "Retrieve a single affiliate request for your merchant account.\n\nUse the UUID returned in the list response to retrieve a specific request."
                    }
                }
            ]
        },
        {
            "name": "Affiliates",
            "item": [
                {
                    "name": "List affiliates",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/affiliates",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "affiliates"
                            ],
                            "query": [
                                {
                                    "key": "per_page",
                                    "value": "15",
                                    "description": "The number of affiliates to return per page. Default is 15.",
                                    "disabled": true
                                },
                                {
                                    "key": "page",
                                    "value": "1",
                                    "description": "The page number to retrieve.",
                                    "disabled": true
                                },
                                {
                                    "key": "tier_slug",
                                    "value": "{{tier_slug}}",
                                    "description": "Filter affiliates by their assigned tier slug.",
                                    "disabled": true
                                }
                            ],
                            "variable": []
                        },
                        "description": "API reference for retrieving a paginated list of affiliates for the authenticated merchant.\n\nThe response is paginated and includes metadata about the pagination state.\nOnly affiliates associated with your merchant account are returned."
                    },
                    "event": [
                        {
                            "listen": "test",
                            "script": {
                                "type": "text/javascript",
                                "exec": [
                                    "// Saves data.affiliates.0.slug as {{affiliate_slug}} for the requests that use it.",
                                    "const value = pm.response.code < 300 ? pm.response.json()?.data?.affiliates?.[0]?.slug : undefined;",
                                    "if (value && !pm.collectionVariables.get('affiliate_slug')) {",
                                    "    pm.collectionVariables.set('affiliate_slug', value);",
                                    "}"
                                ]
                            }
                        }
                    ]
                },
                {
                    "name": "Get an affiliate",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/affiliates/:affiliate",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "affiliates",
                                ":affiliate"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "affiliate",
                                    "value": "{{affiliate_slug}}",
                                    "description": "The slug of the affiliate to retrieve."
                                }
                            ]
                        },
                        "description": "API reference for retrieving a single affiliate by its slug.\n\nThe affiliate must be associated with your merchant account."
                    }
                }
            ]
        },
        {
            "name": "Orders",
            "item": [
                {
                    "name": "Cancel order",
                    "request": {
                        "method": "POST",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/orders/:uuid/cancel",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "orders",
                                ":uuid",
                                "cancel"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "uuid",
                                    "value": "{{order_uuid}}",
                                    "description": "Filled in from the order_uuid collection variable."
                                }
                            ]
                        },
                        "description": "API reference for cancelling an order.\n\nThe order must belong to the authenticated merchant.\nThe order cannot be cancelled if it is already cancelled."
                    }
                },
                {
                    "name": "Create order",
                    "request": {
                        "method": "POST",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            },
                            {
                                "key": "Content-Type",
                                "value": "application/json"
                            }
                        ],
                        "body": {
                            "mode": "raw",
                            "raw": "{\n    \"affiliate_slug\": \"{{affiliate_slug}}\",\n    \"order_no\": \"ORDER-{{$timestamp}}\",\n    \"total_shipping_value\": 495,\n    \"currency_code\": \"{{currency_code}}\",\n    \"customer\": {\n        \"name\": \"{{$randomFullName}}\",\n        \"email\": \"{{$randomEmail}}\"\n    },\n    \"order_rows\": [\n        {\n            \"product_sku\": \"SKU-001\",\n            \"product_name\": \"{{$randomProductName}}\",\n            \"segment_slug\": \"default\",\n            \"price_value\": 1999,\n            \"tax_value\": 500,\n            \"quantity\": 1\n        }\n    ]\n}"
                        },
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/orders/create",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "orders",
                                "create"
                            ],
                            "query": [],
                            "variable": []
                        },
                        "description": "API reference for sending completed orders from your platform into Affilibee for attribution and commission processing.\n\nSend monetary values in the smallest currency unit, such as cents for USD.\nIf your platform sells in multiple currencies, convert values before submission and make sure they match the currency registered for the merchant account.\nSubmit the order only after your platform has captured the affiliate slug, stored the attribution, and determined that the order is valid to report."
                    },
                    "event": [
                        {
                            "listen": "test",
                            "script": {
                                "type": "text/javascript",
                                "exec": [
                                    "// Saves data.order.uuid as {{order_uuid}} for the requests that use it.",
                                    "const value = pm.response.code < 300 ? pm.response.json()?.data?.order?.uuid : undefined;",
                                    "if (value) {",
                                    "    pm.collectionVariables.set('order_uuid', value);",
                                    "}"
                                ]
                            }
                        }
                    ]
                },
                {
                    "name": "List orders",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/orders",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "orders"
                            ],
                            "query": [
                                {
                                    "key": "per_page",
                                    "value": "15",
                                    "description": "The number of orders to return per page. Default is 15.",
                                    "disabled": true
                                },
                                {
                                    "key": "page",
                                    "value": "1",
                                    "description": "The page number to retrieve.",
                                    "disabled": true
                                }
                            ],
                            "variable": []
                        },
                        "description": "API reference for retrieving a paginated list of orders for the authenticated merchant.\n\nThe response is paginated and includes metadata about the pagination state.\nOrders are returned in descending order by creation date by default."
                    },
                    "event": [
                        {
                            "listen": "test",
                            "script": {
                                "type": "text/javascript",
                                "exec": [
                                    "// Saves data.orders.0.uuid as {{order_uuid}} for the requests that use it.",
                                    "const value = pm.response.code < 300 ? pm.response.json()?.data?.orders?.[0]?.uuid : undefined;",
                                    "if (value && !pm.collectionVariables.get('order_uuid')) {",
                                    "    pm.collectionVariables.set('order_uuid', value);",
                                    "}"
                                ]
                            }
                        }
                    ]
                },
                {
                    "name": "Get order",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/orders/:uuid",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "orders",
                                ":uuid"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "uuid",
                                    "value": "{{order_uuid}}",
                                    "description": "Filled in from the order_uuid collection variable."
                                }
                            ]
                        },
                        "description": "API reference for retrieving a single order by its UUID.\n\nThe order must belong to the authenticated merchant.\nThe response includes the order details, currency, order rows, and customer information."
                    }
                },
                {
                    "name": "Update order",
                    "request": {
                        "method": "PATCH",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            },
                            {
                                "key": "Content-Type",
                                "value": "application/json"
                            }
                        ],
                        "body": {
                            "mode": "raw",
                            "raw": "{\n    \"total_shipping_value\": 995\n}"
                        },
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/orders/:uuid",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "orders",
                                ":uuid"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "uuid",
                                    "value": "{{order_uuid}}",
                                    "description": "Filled in from the order_uuid collection variable."
                                }
                            ]
                        },
                        "description": "API reference for updating certain fields on an order.\n\nThe order must belong to the authenticated merchant.\nCurrently, only the `total_shipping_value` field can be updated."
                    }
                }
            ]
        },
        {
            "name": "Segments",
            "item": [
                {
                    "name": "List segments",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/segments",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "segments"
                            ],
                            "query": [
                                {
                                    "key": "per_page",
                                    "value": "15",
                                    "description": "The number of segments to return per page. Default is 15.",
                                    "disabled": true
                                },
                                {
                                    "key": "page",
                                    "value": "1",
                                    "description": "The page number to retrieve.",
                                    "disabled": true
                                }
                            ],
                            "variable": []
                        },
                        "description": "API reference for retrieving a paginated list of segments for the authenticated merchant.\n\nThe response is paginated and includes metadata about the pagination state.\nOnly segments associated with your merchant account are returned."
                    },
                    "event": [
                        {
                            "listen": "test",
                            "script": {
                                "type": "text/javascript",
                                "exec": [
                                    "// Saves data.segments.0.uuid as {{segment_uuid}} for the requests that use it.",
                                    "const value = pm.response.code < 300 ? pm.response.json()?.data?.segments?.[0]?.uuid : undefined;",
                                    "if (value && !pm.collectionVariables.get('segment_uuid')) {",
                                    "    pm.collectionVariables.set('segment_uuid', value);",
                                    "}"
                                ]
                            }
                        }
                    ]
                },
                {
                    "name": "Get a segment",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/segments/:uuid",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "segments",
                                ":uuid"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "uuid",
                                    "value": "{{segment_uuid}}",
                                    "description": "The unique UUID of the segment."
                                }
                            ]
                        },
                        "description": "API reference for retrieving a single segment by its UUID for the authenticated merchant.\n\nOnly segments associated with your merchant account can be retrieved.\nIf the segment does not exist or does not belong to your merchant account, a 404 error will be returned."
                    }
                }
            ]
        },
        {
            "name": "Tiers",
            "item": [
                {
                    "name": "List tiers",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/tiers",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "tiers"
                            ],
                            "query": [
                                {
                                    "key": "per_page",
                                    "value": "15",
                                    "description": "The number of tiers to return per page. Default is 15.",
                                    "disabled": true
                                },
                                {
                                    "key": "page",
                                    "value": "1",
                                    "description": "The page number to retrieve.",
                                    "disabled": true
                                }
                            ],
                            "variable": []
                        },
                        "description": "API reference for retrieving a paginated list of tiers for the authenticated merchant.\n\nThe response is paginated and includes metadata about the pagination state.\nOnly tiers associated with your merchant account are returned."
                    },
                    "event": [
                        {
                            "listen": "test",
                            "script": {
                                "type": "text/javascript",
                                "exec": [
                                    "// Saves data.tiers.0.slug as {{tier_slug}} for the requests that use it.",
                                    "const value = pm.response.code < 300 ? pm.response.json()?.data?.tiers?.[0]?.slug : undefined;",
                                    "if (value && !pm.collectionVariables.get('tier_slug')) {",
                                    "    pm.collectionVariables.set('tier_slug', value);",
                                    "}"
                                ]
                            }
                        }
                    ]
                },
                {
                    "name": "Get a tier",
                    "request": {
                        "method": "GET",
                        "header": [
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": [],
                        "url": {
                            "raw": "{{base_url}}/api/v2/sandbox/tiers/:slug",
                            "host": [
                                "{{base_url}}"
                            ],
                            "path": [
                                "api",
                                "v2",
                                "sandbox",
                                "tiers",
                                ":slug"
                            ],
                            "query": [],
                            "variable": [
                                {
                                    "key": "slug",
                                    "value": "{{tier_slug}}",
                                    "description": "The unique slug of the tier."
                                }
                            ]
                        },
                        "description": "API reference for retrieving a single tier by its slug for the authenticated merchant.\n\nOnly tiers associated with your merchant account can be retrieved.\nIf the tier does not exist or does not belong to your merchant account, a 404 error will be returned."
                    }
                }
            ]
        }
    ],
    "auth": {
        "type": "bearer",
        "bearer": [
            {
                "key": "token",
                "value": "{{api_token}}",
                "type": "string"
            }
        ]
    },
    "variable": [
        {
            "key": "base_url",
            "value": "https://affilibee.com",
            "type": "string",
            "description": "The Affilibee URL."
        },
        {
            "key": "api_token",
            "value": "",
            "type": "string",
            "description": "Your API token. Create one on the Affilibee API page: a testing token for the sandbox collection, a live token for the live collection."
        },
        {
            "key": "currency_code",
            "value": "USD",
            "type": "string",
            "description": "Your merchant account currency; orders must use it."
        },
        {
            "key": "affiliate_slug",
            "value": "",
            "type": "string",
            "description": "The affiliate that new orders are credited to. Filled in by \"List affiliates\" when empty."
        },
        {
            "key": "sender_email",
            "value": "",
            "type": "string",
            "description": "The email of one of your team members; affiliate invites are sent in their name."
        },
        {
            "key": "affiliate_request_uuid",
            "value": "",
            "type": "string",
            "description": "Filled in automatically by the create and list requests; you can also set it yourself."
        },
        {
            "key": "order_uuid",
            "value": "",
            "type": "string",
            "description": "Filled in automatically by the create and list requests; you can also set it yourself."
        },
        {
            "key": "segment_uuid",
            "value": "",
            "type": "string",
            "description": "Filled in automatically by the create and list requests; you can also set it yourself."
        },
        {
            "key": "tier_slug",
            "value": "",
            "type": "string",
            "description": "Filled in automatically by the create and list requests; you can also set it yourself."
        }
    ]
}