Orders-orderId-account-products-productId-services-serviceId-discounts:PUT

From Hostway API Documentation
Jump to: navigation, search

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts

Set discounts for the specified service. Note: This will replace any existing discounts that were configured for the specified service.

Contents


Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts

Request Parameters

orderId - string
The unique order Id. The URI of the order is returned by the POST /orders call.
productId - string
UUID specifying the product for which actions are to be performed
serviceId - string
UUID specifying the service for which actions are to be performed

URI Parameters

None.

Request Headers

Content-Type
Required. Set this header to application/json; charset=UTF-8
Cookie
A cookie named OwnerId to identify the client (for most browser clients, the browser will do this automatically, depending on the browser configuration). The value of the cookie would come from the response to the create order request in the Set-Cookie response header.

Request Body

Body for adding an indefinite discount of 1 dollar for the recurring fee for the service:

{
  "discounts": [
    {
      "priceName": "recurring",
      "recurrences": -1,
      "type": "amount",
      "value": 1.00
    }
  ]
}

Body for adding a 1 dollar amount discount for the first cycle for a domain registration fee:

{
  "discounts": [
    {
      "priceName": "domain_registration_fee",
      "recurrences": 1,
      "type": "amount",
      "value": 1.00
    }
  ]
}

Body for adding a 10% discount for the first three monthly cycles for a service's recurring fee:

{
  "discounts": [
    {
      "priceName": "recurring",
      "recurrences": 3,
      "type": "percent",
      "value": 0.1
    }
  ]
}

Parameters

discounts - list
A list of discounts. Each discount contains the following:
priceName - string
The type of price to which the discount will be applied.
Validation: Should match the fee types configured in the back-end (eg. 'recurring', 'domain_registration_fee', 'setup_fee' etc.) and should be configured for the corresponding franchise.
recurrences - integer
The number of times that the discount will be applied. A value of "-1" means the discount will be applied every time the fee is charged.
Validation: Should be either a positive integer or -1.
Note: Value must be -1 if the priceName is "recurring".
type - string
Specifies the discount type which determines the method used to calculate the amount that is discounted. Possible values are:
amount: Discount will be treated as an exact amount
percent: Discount will be treated as a percentage
Validation: Should be set to either amount or percent.
value - string
The discount amount. The value will be interpreted based on the specified discount type.
Validation: Should be a positive number.

Response

Status Code

Status Code Error Message Description
204 No Content - The discount was successfully set.
400 Bad Request POST data error Required fields are missing.
Validation Error:
{priceName} discount fee type is invalid Type of price is not recognized by the system.
{value} discount amount is invalid Discount amount should be a positive number.
{type} discount type is unsupported Type should be set to either amount or percent.
{recurrences} discount period is invalid Number of reccurences should be either a positive integer or -1. If price type is recurring, it should be -1.
401 Unauthorized - The request was not properly authorized.
403 Forbidden Unauthorized: DiscountsView failed permission check The client does not have sufficient privileges.
404 Not Found Resource not found Order does not exist.
Product could not be found in this order.
Service could not be found for this product.
502 Bad Gateway - Unexpected backend response. Cannot set custom discounts.

Example

Success

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

204 No Content

Invalid discount amount

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "-5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "computeFault": {
    "guid": "c3563e61-a297-4dbe-b072-24aace7b5e44",
    "message": "-5.00 discount amount is invalid",
    "code": 400,
    "details": ""
  }
}

Invalid discount type

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "numbers",
    "value": "5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "computeFault": {
    "guid": "1a94f744-5b33-4d54-ab28-77b875934829",
    "message": "numbers discount type is unsupported",
    "code": 400,
    "details": ""
  }
}

Unsupported price type

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring_yearly",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "computeFault" : {
    "guid" : "43357b7a-0bba-4e40-b565-21422937b7df",
    "message" : "recurring_yearly discount fee type is invalid",
    "code" : 400,
    "details" : ""
  }
}

Invalid discount number of recurrences

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-10",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "computeFault" : {
    "guid" : "bc360508-3392-4185-a07f-8f8cfff6884e",
    "message" : "-10 discount period is invalid",
    "code" : 400,
    "details" : ""
  }
}

Missing price type

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{,
    "recurrences": "-10",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "badRequest" : {
    "guid" : "5f2c19c5-ae18-4fee-b509-476b7ebe4b9c",
    "message" : "POST data error",
    "code" : 400,
    "details" : {
      "discounts.0.priceName" : "Required"
    }
  }
}

Missing authorization

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

401 Unauthorized
Content-Type : text/plain; charset=UTF-8

401 Unauthorized

This server could not verify that you are authorized to access the document you requested.
Either you supplied the wrong credentials (e.g., bad password),
or your browser does not understand how to supply the credentials required.

Insuffucient privileges

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic ZWdjUlBtZWZiWnJVQHNpdGVjb250cm9sX2hvc3R3YXlfdXNfbWFpbjpTdnVROGlWOUFTVTc0
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

403 Forbidden
Content-Type : application/json; charset=UTF-8

{
  "forbidden": {
    "guid": "1912d9fa-5fbe-4e16-b0ba-00d50c9c1ec4",
    "message": "Unauthorized: DiscountsView failed permission check",
    "code": 403,
    "details": ""
  }
}

Order does not exist

Request

PUT /orders/{orderId}/account/products/{productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

404 Not Found
Content-Type : application/json; charset=UTF-8

{
  "itemNotFound": {
    "guid": "cca219c5-3e2b-481d-8e7f-7083064872ff",
    "message": "Resource not found",
    "code": 404,
    "details": ""
  }
}

Product not found

Request

PUT /orders/{orderId}/account/products/{non-existent_productId}/services/{serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

404 Not Found
Content-Type : application/json; charset=UTF-8

{
  "itemNotFound": {
    "guid": "cca219c5-3e2b-481d-8e7f-7083064872ff",
    "message": "Resource not found",
    "code": 404,
    "details": ""
  }
}

Service not found

Request

PUT /orders/{orderId}/account/products/{productId}/services/{non-existent_serviceId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

404 Not Found
Content-Type : application/json; charset=UTF-8

{
  "itemNotFound": {
    "guid": "cca219c5-3e2b-481d-8e7f-7083064872ff",
    "message": "Resource not found",
    "code": 404,
    "details": ""
  }
}


See also


blog comments powered by Disqus

Personal tools
Namespaces
Variants
Actions
APIs
Navigation
Toolbox