Orders-orderId-discounts:PUT

From Hostway API Documentation
Jump to: navigation, search

PUT /orders/{orderId}/discounts

Set discounts for the entire Order. Discounts that are applied to an entire order will be applied to all of the product and services within the order. Note: This will replace any existing discounts that were configured at the order level.

Contents


Request

PUT /orders/{orderId}/discounts

Request Parameters

orderId - string
The unique order Id. The URI of the order is returned by the POST /orders call.

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

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

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.
Note: Only "recurring" is currently supported
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 A required field is missing.
Validation Error:
Bad request Reccurences should be either a positive integer or -1.
Price type should be reccuring.
{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.
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.
502 Bad Gateway - Unexpected backend response. Cannot set custom discounts.

Example

Success

Request

PUT /orders/{orderId}/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}/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}/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": "amounts discount type is unsupported",
    "code": 400,
    "details": ""
  }
}

Invalid discount number of recurrences

Request

PUT /orders/{orderId}/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": "e15a6425-1cad-4154-b8f9-c10a0e46bf2c",
    "message": "Bad Request",
    "code": 400,
    "details": ""
  }
}

Missing price type

Request

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

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

Response

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

{
  "badRequest" : {
    "guid" : "bb3da718-f0e1-4787-acd4-8cf4215f0c44",
    "message" : "POST data error",
    "code" : 400,
    "details" : {
      "discounts.0.priceName" : "Required"
    }
  }
}

Missing authorization

Request

PUT /orders/{orderId}/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}/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/{non-existent_orderId}/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