# Cancel an scheduled invoice

POST https://services.leadconnectorhq.com/invoices/schedule/{scheduleId}/cancel

API to cancel a scheduled invoice by schedule id

## Authentication

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

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `invoices/schedule.write`
- **Agency token: OAuth access token or Private Integration Token.** Scopes: `invoices/schedule.write`

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `scheduleId` | string | Yes | Schedule Id |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/invoices/schedule/{scheduleId}/cancel": {
      "post": {
        "summary": "Cancel an scheduled invoice",
        "operationId": "cancelAnScheduledInvoice",
        "description": "API to cancel a scheduled invoice by schedule id",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "scheduleId",
            "required": true,
            "in": "path",
            "description": "Schedule Id",
            "schema": {
              "example": "6578278e879ad2646715ba9c",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CancelInvoiceScheduleDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CancelInvoiceScheduleResponseDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "invoices/schedule.write"
            ]
          },
          {
            "Agency-Access": [
              "invoices/schedule.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": {
      "CancelInvoiceScheduleDto": {
        "type": "object",
        "properties": {
          "altId": {
            "type": "string",
            "description": "location Id / company Id based on altType",
            "example": "6578278e879ad2646715ba9c"
          },
          "altType": {
            "type": "string",
            "description": "Alt Type",
            "enum": [
              "location"
            ],
            "example": "location"
          }
        },
        "required": [
          "altId",
          "altType"
        ],
        "title": "CancelInvoiceScheduleDto"
      },
      "CancelInvoiceScheduleResponseDto": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string",
            "description": "Schedule Id",
            "example": "6578278e879ad2646715ba9c"
          },
          "status": {
            "type": "object",
            "description": "Schedule Status",
            "example": "draft"
          },
          "liveMode": {
            "type": "boolean",
            "description": "Live Mode",
            "example": false
          },
          "altId": {
            "type": "string",
            "description": "Location Id or Agency Id",
            "example": "6578278e879ad2646715ba9c"
          },
          "altType": {
            "type": "string",
            "enum": [
              "location"
            ]
          },
          "name": {
            "type": "string",
            "description": "Name of the invoice",
            "example": "New Invoice"
          },
          "schedule": {
            "type": "object",
            "properties": {
              "executeAt": {
                "type": "string"
              },
              "rrule": {
                "type": "object",
                "properties": {
                  "intervalType": {
                    "type": "string",
                    "enum": [
                      "yearly",
                      "monthly",
                      "weekly",
                      "daily",
                      "hourly",
                      "minutely",
                      "secondly"
                    ],
                    "example": "monthly"
                  },
                  "interval": {
                    "type": "number",
                    "example": 2
                  },
                  "startDate": {
                    "type": "string",
                    "description": "Start date in YYYY-MM-DD format",
                    "example": "2023-01-01"
                  },
                  "startTime": {
                    "type": "string",
                    "description": "Start time in HH:mm:ss format",
                    "example": "20:45:00"
                  },
                  "endDate": {
                    "type": "string",
                    "description": "End date in YYYY-MM-DD format",
                    "example": "2029-11-01"
                  },
                  "endTime": {
                    "type": "string",
                    "description": "End time in HH:mm:ss format",
                    "example": "18:45:00"
                  },
                  "dayOfMonth": {
                    "type": "number",
                    "description": "-1, 1, 2, 3, ..., 27, 28",
                    "example": 15
                  },
                  "dayOfWeek": {
                    "type": "string",
                    "enum": [
                      "mo",
                      "tu",
                      "we",
                      "th",
                      "fr",
                      "sa",
                      "su"
                    ],
                    "example": "mo"
                  },
                  "numOfWeek": {
                    "type": "number",
                    "description": "-1, 1, 2, 3, 4",
                    "example": -1
                  },
                  "monthOfYear": {
                    "type": "string",
                    "enum": [
                      "jan",
                      "feb",
                      "mar",
                      "apr",
                      "may",
                      "jun",
                      "jul",
                      "aug",
                      "sep",
                      "oct",
                      "nov",
                      "dec"
                    ],
                    "example": "jan"
                  },
                  "count": {
                    "type": "number",
                    "description": "Max number of task executions",
                    "example": 10
                  },
                  "daysBefore": {
                    "type": "number",
                    "description": "Execute task number of days before",
                    "example": 5
                  },
                  "useStartAsPrimaryUserAccepted": {
                    "type": "boolean",
                    "description": "Start as primary user accepted date",
                    "example": true
                  },
                  "endType": {
                    "type": "string",
                    "description": "End type like after, by, count",
                    "example": "by"
                  }
                },
                "required": [
                  "intervalType",
                  "interval",
                  "startDate"
                ],
                "title": "CustomRRuleOptionsDto"
              }
            },
            "title": "ScheduleOptionsDto"
          },
          "invoices": {
            "description": "List of invoices",
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "_id": {
                  "type": "string",
                  "description": "Invoice Id",
                  "example": "6578278e879ad2646715ba9c"
                },
                "status": {
                  "type": "string",
                  "description": "Invoice Status",
                  "example": "draft",
                  "enum": [
                    "draft",
                    "sent",
                    "payment_processing",
                    "paid",
                    "void",
                    "partially_paid"
                  ]
                },
                "liveMode": {
                  "type": "boolean",
                  "description": "Live Mode",
                  "example": false
                },
                "amountPaid": {
                  "type": "number",
                  "description": "Amount Paid",
                  "example": 0
                },
                "altId": {
                  "type": "string",
                  "description": "Location Id or Agency Id",
                  "example": "6578278e879ad2646715ba9c"
                },
                "altType": {
                  "type": "string",
                  "enum": [
                    "location"
                  ]
                },
                "name": {
                  "type": "string",
                  "description": "Name of the invoice",
                  "example": "New Invoice"
                },
                "businessDetails": {
                  "type": "object",
                  "description": "Business Details",
                  "example": {
                    "name": "Alex",
                    "address": {
                      "addressLine1": "9931 Beechwood",
                      "city": "St. Houston",
                      "state": "TX",
                      "countryCode": "USA",
                      "postalCode": "559-6993"
                    },
                    "phoneNo": "+1-214-559-6993",
                    "website": "www.example.com"
                  }
                },
                "invoiceNumber": {
                  "type": "number",
                  "description": "Invoice Number",
                  "example": "19"
                },
                "currency": {
                  "type": "string",
                  "description": "Currency",
                  "example": "USD"
                },
                "contactDetails": {
                  "type": "object",
                  "description": "Contact Details",
                  "example": {
                    "id": "c6tZZU0rJBf30ZXx9Gli",
                    "phoneNo": "+1-214-559-6993",
                    "email": "alex@example.com",
                    "customFields": [],
                    "name": "Alex",
                    "address": {
                      "countryCode": "US"
                    }
                  }
                },
                "issueDate": {
                  "type": "string",
                  "description": "Issue date in YYYY-MM-DD format",
                  "example": "2023-01-01"
                },
                "dueDate": {
                  "type": "string",
                  "description": "Due date in YYYY-MM-DD format",
                  "example": "2023-01-01"
                },
                "discount": {
                  "type": "object",
                  "description": "Discount",
                  "example": {
                    "type": "percentage",
                    "value": 0
                  }
                },
                "invoiceItems": {
                  "description": "Invoice Items",
                  "example": [
                    {
                      "taxes": [],
                      "_id": "c6tZZU0rJBf30ZXx9Gli",
                      "productId": "c6tZZU0rJBf30ZXx9Gli",
                      "priceId": "c6tZZU0rJBf30ZXx9Gli",
                      "currency": "USD",
                      "name": "Macbook Pro",
                      "qty": 1,
                      "amount": 999
                    }
                  ],
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "total": {
                  "type": "number",
                  "description": "Total Amount",
                  "example": 999
                },
                "title": {
                  "type": "string",
                  "description": "Title",
                  "example": "INVOICE"
                },
                "amountDue": {
                  "type": "number",
                  "description": "Total Amount Due",
                  "example": 999
                },
                "createdAt": {
                  "type": "string",
                  "description": "created at",
                  "example": "2023-12-12T09:27:42.355Z"
                },
                "updatedAt": {
                  "type": "string",
                  "description": "updated at",
                  "example": "2023-12-12T09:27:42.355Z"
                },
                "automaticTaxesEnabled": {
                  "type": "boolean",
                  "description": "Automatic taxes enabled for the Invoice",
                  "example": true
                },
                "automaticTaxesCalculated": {
                  "type": "boolean",
                  "description": "Is Automatic taxes calculated for the Invoice items",
                  "example": true
                },
                "paymentSchedule": {
                  "type": "object",
                  "description": "split invoice into payment schedule summing up to full invoice amount"
                }
              },
              "required": [
                "_id",
                "status",
                "liveMode",
                "amountPaid",
                "altId",
                "altType",
                "name",
                "businessDetails",
                "invoiceNumber",
                "currency",
                "contactDetails",
                "issueDate",
                "dueDate",
                "invoiceItems",
                "total",
                "title",
                "amountDue",
                "createdAt",
                "updatedAt"
              ],
              "title": "DefaultInvoiceResponseDto"
            }
          },
          "businessDetails": {
            "description": "Business Details",
            "example": {
              "name": "Alex",
              "address": {
                "addressLine1": "9931 Beechwood",
                "city": "St. Houston",
                "state": "TX",
                "countryCode": "USA",
                "postalCode": "559-6993"
              },
              "phoneNo": "+1-214-559-6993",
              "website": "www.example.com"
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "logoUrl": {
                    "type": "string",
                    "description": "Business Logo URL",
                    "example": "https://example.com/logo.png"
                  },
                  "name": {
                    "type": "string",
                    "description": "Business Name",
                    "example": "ABC Corp."
                  },
                  "phoneNo": {
                    "type": "string",
                    "description": "Business Phone Number",
                    "example": "+1-214-559-6993"
                  },
                  "address": {
                    "description": "Business Address",
                    "example": "9931 Beechwood, TX",
                    "allOf": [
                      {
                        "type": "object",
                        "properties": {
                          "addressLine1": {
                            "type": "string",
                            "description": "Address Line 1",
                            "example": "9931 Beechwood"
                          },
                          "addressLine2": {
                            "type": "string",
                            "description": "Address Line 2",
                            "example": "Beechwood"
                          },
                          "city": {
                            "type": "string",
                            "description": "City",
                            "example": "St. Houston"
                          },
                          "state": {
                            "type": "string",
                            "description": "State",
                            "example": "TX"
                          },
                          "countryCode": {
                            "type": "string",
                            "description": "Country Code",
                            "example": "US"
                          },
                          "postalCode": {
                            "type": "string",
                            "description": "Postal Code",
                            "example": "559-6993"
                          }
                        },
                        "title": "AddressDto"
                      }
                    ]
                  },
                  "website": {
                    "type": "string",
                    "description": "Business Website Link",
                    "example": "wwww.example.com"
                  },
                  "customValues": {
                    "description": "Custom Values",
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "title": "BusinessDetailsDto"
              }
            ]
          },
          "currency": {
            "type": "string",
            "description": "Currency",
            "example": "USD"
          },
          "contactDetails": {
            "description": "Contact Details",
            "example": {
              "id": "c6tZZU0rJBf30ZXx9Gli",
              "phoneNo": "+1-214-559-6993",
              "email": "alex@example.com",
              "customFields": [],
              "name": "Alex",
              "address": {
                "countryCode": "US"
              }
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Contact ID",
                    "example": "6578278e879ad2646715ba9c"
                  },
                  "name": {
                    "type": "string",
                    "description": "Contact Name",
                    "example": "Alex"
                  },
                  "phoneNo": {
                    "type": "string",
                    "description": "Contact Phone Number",
                    "example": "+1234567890"
                  },
                  "email": {
                    "type": "string",
                    "description": "Contact Email",
                    "example": "alex@example.com"
                  },
                  "additionalEmails": {
                    "description": "Secondary email addresses for the contact to be saved",
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "email": {
                          "type": "string",
                          "example": "alex@example.com"
                        }
                      },
                      "required": [
                        "email"
                      ],
                      "title": "AdditionalEmailsDto"
                    }
                  },
                  "companyName": {
                    "type": "string",
                    "description": "Contact Company Name",
                    "example": "ABC Corp."
                  },
                  "address": {
                    "type": "object",
                    "properties": {
                      "addressLine1": {
                        "type": "string",
                        "description": "Address Line 1",
                        "example": "9931 Beechwood"
                      },
                      "addressLine2": {
                        "type": "string",
                        "description": "Address Line 2",
                        "example": "Beechwood"
                      },
                      "city": {
                        "type": "string",
                        "description": "City",
                        "example": "St. Houston"
                      },
                      "state": {
                        "type": "string",
                        "description": "State",
                        "example": "TX"
                      },
                      "countryCode": {
                        "type": "string",
                        "description": "Country Code",
                        "example": "US"
                      },
                      "postalCode": {
                        "type": "string",
                        "description": "Postal Code",
                        "example": "559-6993"
                      }
                    },
                    "title": "AddressDto"
                  },
                  "customFields": {
                    "description": "Custom Values",
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "id",
                  "name",
                  "phoneNo",
                  "email"
                ],
                "title": "ContactDetailsDto"
              }
            ]
          },
          "discount": {
            "description": "Discount",
            "example": {
              "type": "percentage",
              "value": 0
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "value": {
                    "type": "number",
                    "description": "Discount Value",
                    "example": 10,
                    "default": 0
                  },
                  "type": {
                    "type": "string",
                    "description": "Discount type",
                    "enum": [
                      "percentage",
                      "fixed"
                    ],
                    "example": "percentage",
                    "default": "percentage"
                  },
                  "validOnProductIds": {
                    "description": "Product Ids on which discount is applicable",
                    "example": "[ '6579751d56f60276e5bd4154' ]",
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "type"
                ],
                "title": "DiscountDto"
              }
            ]
          },
          "items": {
            "description": "Invoice Items",
            "example": [
              {
                "taxes": [],
                "_id": "c6tZZU0rJBf30ZXx9Gli",
                "productId": "c6tZZU0rJBf30ZXx9Gli",
                "priceId": "c6tZZU0rJBf30ZXx9Gli",
                "currency": "USD",
                "name": "Macbook Pro",
                "qty": 1,
                "amount": 999
              }
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "total": {
            "type": "number",
            "description": "Total Amount",
            "example": 999
          },
          "title": {
            "type": "string",
            "description": "Title",
            "example": "INVOICE"
          },
          "termsNotes": {
            "type": "string",
            "description": "Terms notes",
            "example": "Confidential"
          },
          "compiledTermsNotes": {
            "type": "string",
            "description": "Compiled terms notes",
            "example": "Confidential"
          },
          "createdAt": {
            "type": "string",
            "description": "created at",
            "example": "2023-12-12T09:27:42.355Z"
          },
          "updatedAt": {
            "type": "string",
            "description": "updated at",
            "example": "2023-12-12T09:27:42.355Z"
          }
        },
        "required": [
          "_id",
          "status",
          "liveMode",
          "altId",
          "altType",
          "name",
          "invoices",
          "businessDetails",
          "currency",
          "contactDetails",
          "items",
          "total",
          "title",
          "termsNotes",
          "compiledTermsNotes",
          "createdAt",
          "updatedAt"
        ],
        "title": "CancelInvoiceScheduleResponseDto"
      },
      "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/invoices/schedule/<scheduleId>/cancel' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "altId": "6578278e879ad2646715ba9c",
      "altType": "location"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/invoices/schedule/<scheduleId>/cancel', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/invoices/schedule/{scheduleId}/cancel"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "altId": "6578278e879ad2646715ba9c",
    "altType": "location"
}

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/invoices/schedule/<scheduleId>/cancel',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/invoices/schedule/<scheduleId>/cancel")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"altId\":\"6578278e879ad2646715ba9c\",\"altType\":\"location\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/invoices/schedule/<scheduleId>/cancel"
  payload := strings.NewReader(`{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  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/invoices/schedule/<scheduleId>/cancel")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location"
}'

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

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/invoices/schedule/<scheduleId>/cancel' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
