# Create Payout Method

POST https://services.leadconnectorhq.com/affiliate-manager/{locationId}/affiliate/{affiliateId}/payout-method

Store a payout method for an affiliate. An affiliate can hold one PayPal and one bank method; the first method stored becomes the primary one. Bank fields are validated against the requirements of the account country.

## Authentication

Send `Authorization: Bearer <token>` using any one of:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `affiliate-manager.write`
- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `affiliate-manager.write`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location Id |
| `affiliateId` | string | Yes | Affiliate Id |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "2023-02-21"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/affiliate-manager/{locationId}/affiliate/{affiliateId}/payout-method": {
      "post": {
        "summary": "Create Payout Method",
        "operationId": "createPayoutMethod",
        "description": "Store a payout method for an affiliate. An affiliate can hold one PayPal and one bank method; the first method stored becomes the primary one. Bank fields are validated against the requirements of the account country.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "2023-02-21"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "path",
            "description": "Location Id",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          },
          {
            "name": "affiliateId",
            "required": true,
            "in": "path",
            "description": "Affiliate Id",
            "schema": {
              "example": "63e35ac8b4dac93dfc2757c7",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateUpdateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PayoutMethodResponseDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden"
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "affiliate-manager.write"
            ]
          },
          {
            "Location-Access": [
              "affiliate-manager.write"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "CreateUpdateRequest": {
        "type": "object",
        "properties": {
          "paypalEmail": {
            "type": "string",
            "description": "PayPal Email (required if method is PAYPAL)",
            "example": "john@deo.com"
          },
          "payoutMethod": {
            "type": "string",
            "description": "Payout method to store the details under",
            "example": "PAYPAL",
            "enum": [
              "PAYPAL",
              "BANK"
            ]
          },
          "bankDetails": {
            "description": "Bank Details (required if method is BANK)",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "bankCountry": {
                    "type": "string",
                    "description": "Country the account is held in",
                    "example": "United States",
                    "maxLength": 128
                  },
                  "accountHolderName": {
                    "type": "string",
                    "description": "Name on the account",
                    "example": "John Doe",
                    "maxLength": 128
                  },
                  "recipientAddress": {
                    "description": "Address of the account holder",
                    "allOf": [
                      {
                        "type": "object",
                        "properties": {
                          "country": {
                            "type": "string",
                            "description": "Country of the account holder",
                            "example": "United States",
                            "maxLength": 128
                          },
                          "state": {
                            "type": "string",
                            "description": "State or province of the account holder",
                            "example": "California",
                            "maxLength": 128
                          },
                          "city": {
                            "type": "string",
                            "description": "City of the account holder",
                            "example": "San Francisco",
                            "maxLength": 128
                          },
                          "postalCode": {
                            "type": "string",
                            "description": "Postal code of the account holder",
                            "example": "94105",
                            "maxLength": 128
                          }
                        },
                        "required": [
                          "country",
                          "city",
                          "postalCode"
                        ],
                        "title": "BankRecipientAddressDto"
                      }
                    ]
                  },
                  "fields": {
                    "description": "Bank fields required by the account country",
                    "example": [
                      {
                        "key": "accountNumber",
                        "value": "12345678"
                      },
                      {
                        "key": "routingNumber",
                        "value": "021000021"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "key": {
                          "type": "string",
                          "description": "Field key, as declared by the country bank mapping",
                          "example": "accountNumber"
                        },
                        "value": {
                          "type": "string",
                          "description": "Value for the field",
                          "example": "12345678"
                        }
                      },
                      "required": [
                        "key",
                        "value"
                      ],
                      "title": "BankFieldDto"
                    }
                  }
                },
                "required": [
                  "bankCountry",
                  "accountHolderName",
                  "recipientAddress",
                  "fields"
                ],
                "title": "BankDetailsDto"
              }
            ]
          }
        },
        "required": [
          "payoutMethod"
        ],
        "title": "CreateUpdateRequest"
      },
      "PayoutMethodResponseDto": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string",
            "description": "Payout method id",
            "example": "63e35ac8b4dac93dfc2757c7"
          },
          "locationId": {
            "type": "string",
            "description": "Location the payout method belongs to",
            "example": "ve9EPM428h8vShlRW1KT"
          },
          "affiliateId": {
            "type": "string",
            "description": "Affiliate the payout method belongs to",
            "example": "6385d230f6d19db03eef6fb2"
          },
          "method": {
            "type": "string",
            "description": "Payout method type",
            "example": "PAYPAL",
            "enum": [
              "PAYPAL",
              "BANK"
            ]
          },
          "paypalEmail": {
            "type": "string",
            "description": "PayPal email, when the method is PAYPAL",
            "example": "john@doe.com"
          },
          "bankDetails": {
            "description": "Bank details, when the method is BANK",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "bankCountry": {
                    "type": "string",
                    "description": "Country the account is held in",
                    "example": "United States"
                  },
                  "accountHolderName": {
                    "type": "string",
                    "description": "Name on the account",
                    "example": "John Doe"
                  },
                  "recipientAddress": {
                    "description": "Address of the account holder",
                    "allOf": [
                      {
                        "type": "object",
                        "properties": {
                          "country": {
                            "type": "string",
                            "description": "Country of the account holder",
                            "example": "United States"
                          },
                          "state": {
                            "type": "string",
                            "description": "State or province",
                            "example": "California"
                          },
                          "city": {
                            "type": "string",
                            "description": "City",
                            "example": "San Francisco"
                          },
                          "postalCode": {
                            "type": "string",
                            "description": "Postal code",
                            "example": "94105"
                          }
                        },
                        "required": [
                          "country",
                          "city",
                          "postalCode"
                        ],
                        "title": "PayoutMethodRecipientAddressResponseDto"
                      }
                    ]
                  },
                  "fields": {
                    "description": "Bank fields required by the account country, with values reduced to their last four characters",
                    "example": [
                      {
                        "key": "accountNumber",
                        "value": "********5678"
                      },
                      {
                        "key": "bankName",
                        "value": "Bank of America"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "key": {
                          "type": "string",
                          "description": "Field key, as declared by the country bank mapping",
                          "example": "accountNumber"
                        },
                        "value": {
                          "type": "string",
                          "description": "Account-identifying values are masked to their last four characters, with the rest replaced by asterisks so the length is preserved. Descriptive fields such as the bank and branch name are returned in full.",
                          "example": "********5678"
                        }
                      },
                      "required": [
                        "key",
                        "value"
                      ],
                      "title": "PayoutMethodBankFieldResponseDto"
                    }
                  }
                },
                "required": [
                  "bankCountry",
                  "accountHolderName",
                  "recipientAddress",
                  "fields"
                ],
                "title": "PayoutMethodBankDetailsResponseDto"
              }
            ]
          },
          "isPrimary": {
            "type": "boolean",
            "description": "Whether payouts default to this method",
            "example": true
          },
          "createdAt": {
            "type": "string",
            "description": "Created at timestamp",
            "example": "2024-06-16T00:00:00.000Z"
          },
          "updatedAt": {
            "type": "string",
            "description": "Updated at timestamp",
            "example": "2024-06-16T00:00:00.000Z"
          }
        },
        "required": [
          "_id",
          "locationId",
          "affiliateId",
          "method",
          "isPrimary",
          "createdAt",
          "updatedAt"
        ],
        "title": "PayoutMethodResponseDto"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/affiliate-manager/<locationId>/affiliate/<affiliateId>/payout-method' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: 2023-02-21' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "paypalEmail": "john@deo.com",
  "payoutMethod": "PAYPAL",
  "bankDetails": {
    "bankCountry": "United States",
    "accountHolderName": "John Doe",
    "recipientAddress": {
      "country": "United States",
      "state": "California",
      "city": "San Francisco",
      "postalCode": "94105"
    },
    "fields": [
      {
        "key": "accountNumber",
        "value": "12345678"
      },
      {
        "key": "routingNumber",
        "value": "021000021"
      }
    ]
  }
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: '2023-02-21',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "paypalEmail": "john@deo.com",
      "payoutMethod": "PAYPAL",
      "bankDetails": {
        "bankCountry": "United States",
        "accountHolderName": "John Doe",
        "recipientAddress": {
          "country": "United States",
          "state": "California",
          "city": "San Francisco",
          "postalCode": "94105"
        },
        "fields": [
          {
            "key": "accountNumber",
            "value": "12345678"
          },
          {
            "key": "routingNumber",
            "value": "021000021"
          }
        ]
      }
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/affiliate-manager/<locationId>/affiliate/<affiliateId>/payout-method', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/affiliate-manager/{locationId}/affiliate/{affiliateId}/payout-method"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "2023-02-21"
}

payload = {
    "paypalEmail": "john@deo.com",
    "payoutMethod": "PAYPAL",
    "bankDetails": {
        "bankCountry": "United States",
        "accountHolderName": "John Doe",
        "recipientAddress": {
            "country": "United States",
            "state": "California",
            "city": "San Francisco",
            "postalCode": "94105"
        },
        "fields": [
            {
                "key": "accountNumber",
                "value": "12345678"
            },
            {
                "key": "routingNumber",
                "value": "021000021"
            }
        ]
    }
}

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

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/affiliate-manager/<locationId>/affiliate/<affiliateId>/payout-method',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: 2023-02-21',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "paypalEmail": "john@deo.com",
  "payoutMethod": "PAYPAL",
  "bankDetails": {
    "bankCountry": "United States",
    "accountHolderName": "John Doe",
    "recipientAddress": {
      "country": "United States",
      "state": "California",
      "city": "San Francisco",
      "postalCode": "94105"
    },
    "fields": [
      {
        "key": "accountNumber",
        "value": "12345678"
      },
      {
        "key": "routingNumber",
        "value": "021000021"
      }
    ]
  }
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/affiliate-manager/<locationId>/affiliate/<affiliateId>/payout-method")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "2023-02-21")
  .header("Content-Type", "application/json")
  .body("{\"paypalEmail\":\"john@deo.com\",\"payoutMethod\":\"PAYPAL\",\"bankDetails\":{\"bankCountry\":\"United States\",\"accountHolderName\":\"John Doe\",\"recipientAddress\":{\"country\":\"United States\",\"state\":\"California\",\"city\":\"San Francisco\",\"postalCode\":\"94105\"},\"fields\":[{\"key\":\"accountNumber\",\"value\":\"12345678\"},{\"key\":\"routingNumber\",\"value\":\"021000021\"}]}}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/affiliate-manager/<locationId>/affiliate/<affiliateId>/payout-method"
  payload := strings.NewReader(`{
  "paypalEmail": "john@deo.com",
  "payoutMethod": "PAYPAL",
  "bankDetails": {
    "bankCountry": "United States",
    "accountHolderName": "John Doe",
    "recipientAddress": {
      "country": "United States",
      "state": "California",
      "city": "San Francisco",
      "postalCode": "94105"
    },
    "fields": [
      {
        "key": "accountNumber",
        "value": "12345678"
      },
      {
        "key": "routingNumber",
        "value": "021000021"
      }
    ]
  }
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "2023-02-21")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/affiliate-manager/<locationId>/affiliate/<affiliateId>/payout-method")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "2023-02-21"
request["Content-Type"] = "application/json"
request.body = '{
  "paypalEmail": "john@deo.com",
  "payoutMethod": "PAYPAL",
  "bankDetails": {
    "bankCountry": "United States",
    "accountHolderName": "John Doe",
    "recipientAddress": {
      "country": "United States",
      "state": "California",
      "city": "San Francisco",
      "postalCode": "94105"
    },
    "fields": [
      {
        "key": "accountNumber",
        "value": "12345678"
      },
      {
        "key": "routingNumber",
        "value": "021000021"
      }
    ]
  }
}'

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

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "2023-02-21"
}

$body = '{
  "paypalEmail": "john@deo.com",
  "payoutMethod": "PAYPAL",
  "bankDetails": {
    "bankCountry": "United States",
    "accountHolderName": "John Doe",
    "recipientAddress": {
      "country": "United States",
      "state": "California",
      "city": "San Francisco",
      "postalCode": "94105"
    },
    "fields": [
      {
        "key": "accountNumber",
        "value": "12345678"
      },
      {
        "key": "routingNumber",
        "value": "021000021"
      }
    ]
  }
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/affiliate-manager/<locationId>/affiliate/<affiliateId>/payout-method' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
