Orders-orderId-account-products:POST

From Hostway API Documentation
Jump to: navigation, search

POST /orders/{orderId}/account/products

Adds a new or existing Product to the Account's Order.

If, at the time the product is created, there is not yet an Account in the order, then this call will implicitly add a very rudimentary Account (containing only a default language & the currency of this product).

If there is already an Account in the order at the time this call is made, the currency of the specified product offering *must* match the currency of the Account.

Contents


Request

POST /orders/{orderId}/account/products

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

There are two possible formats. To add a new product that does not already exist:

{
  "offering": "https://api.hostway.com/productSpecifications/{productSpecificationId}/offerings/{productOfferingId}",
  "promoCode": "{promoCode}",
  "displayName": "My custom product name",
  "partnerId": "PartnerId",
}

OR

To specify an existing product, use the following:

{
  "existingProductUrl": "https://api.hostway.com/accounts/{accountId}/products/{productId}"
}

Parameters

offering - string
Link to the product catalog offering specifying the new product.
promoCode - string (optional)
A promotion code for the new product promotion codes.
displayName - string (optional)
A custom display name for the product.
partnerId - string (optional)
Partner id.
existingProductUrl - string
Link to an existing product. Only required when adding an existing product to the order.

Validation Rules

  1. The product specification URL ( https://api.hostway.com/productSpecifications/{productSpecificationId} ) should point to an existing product.
  2. The product offering currency should match the account currency or if no account is specified should be allowed for the franchise.
  3. The product offering URL ( https://api.hostway.com/productSpecifications/{productSpecificationId}/offerings/{productOfferingId} ) should point to an existing product offering.
  4. The product use type (public, internal, internal view only, etc.) should be allowed for the current user.
  5. The product offering should be valid according to the back-end.
  6. The account product URL ( {APIBaseURL}}/accounts/{accountId}/products/{productId} ) should point to an existing product that is open and belongs to the account.

Response

Status Code

Status Code Error Message Description
201 Created - The operation was successfully completed.
400 Bad Request POST data error Trying to create a product with invalid body.
Cannot add non-existent product \"fake\" Trying to create a product by passing fake offering.
Invalid offering URI Trying to create a product by passing invalid offering (missing currency, monthly cycle or productSpecifications)
The requested offering is invalid Trying to create a product with invalid monthly cycle (eg: 100)
Trying to add inconsistent currency: product {product} with FAKE while account uses USD Trying to create a product with currency, which does not match the account's currency
Currency FAKE not allowed for this franchise Trying to add a product with invalid for the franchise currency to an order for which no account has been set.
Trying to add Internal product {product} without authorization Trying to add product, which is internal, without the proper credentials.
Trying to add Internal View Only product {product} Trying to add product, which is internal view only, without the proper credentials.
Invalid product URI Tried to add an existing product with wrong existingProductUrl
The account of the order and the account of the product doesn't match Tried to add an existing product with account, which is different from the account of the order.
Product doesn't exist. Tried to add an existing product which does not exist
Cannot add a product that is not open. Tried to add an existing product that is not open.
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. The OwnerId cookie was not specified or is incorrect.
403 Forbidden Unauthorized: Products failed permission check The client does not have permissions to add products.
404 Not Found Resource not found The client is trying to add a product to non existing order.
502 Bad Gateway - Unexpected backend response.

Response Headers

Location
Returned with successful response. Contains the URI of the newly added product and the id of the product.

Response Body

Successful response

201 Created
{
  "productId": "00000148842a5f6448a61ce6007f000000010001",
  "url" : "https://api.hostway.com/orders/0000014884293798c68eafa5007f000000010001/account/products/00000148842a5f6448a61ce6007f000000010001/"
}
Note: The product Id will change once the order is provisioned.

Error responses

400 Bad Request - trying to order product, which is internal, without the proper authorization.
{
    "computeFault": {
        "guid": "c940c886-5343-4a49-b728-0b94cbb1a3e9",
        "message": "Trying to add Internal product {product} without authorization",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add a product, which is internal view only, such products cannot be added via the Public API.
{
    "computeFault": {
        "guid": "3ee2bd37-81ee-4a57-bd63-dc84705b3985",
        "message": "Trying to add Internal View Only product {product}",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add a product without supplying the required attributes in the body.
{
    "badRequest":{
        "guid": "0f3e0435-21ac-43e5-acfd-ac33886fbe70",
        "message": "POST data error",
        "code": 400,
        "details": {
            "offering": "Required"
        }
    }
}

400 Bad Request - trying to add a product that does not exist.
{
    "computeFault":{
        "guid": "12cf7a72-3261-4c57-a82e-1f2f1c124d50",
        "message": "Cannot add non-existent product \"fake\"",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add a product by supplying invalid offering URI (eg:  "offering": "http://coreapi01.ote.chicago.hostway:8092/productSpecifications/core.plangroup.dedserver.plan4/offerings/")
{
    "computeFault": {
        "guid": "0ced627e-c9fc-4835-92da-1a4256165607",
        "message": "Invalid offering URI",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add a product with invalid currency (case when account is set and the currency provided does not match the account's currency)
{
    "computeFault": {
        "guid": "742e193a-4667-47fd-a5ff-ec1f7788d459",
        "message": "Trying to add inconsistent currency: product {product} with FAKE while account uses USD",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add a product with invalid for the franchise currency (case when an account is not set so the currency it is determined by the first added product, but the currency is not allowed for the franchise)
{
    "computeFault": {
        "guid": "3ee2bd37-81ee-4a57-bd63-dc84705b3985",
        "message": "Currency FAKE not allowed for this franchise",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add a product with invalid month cycle (eg: 100)
{
    "computeFault": {
        "guid": "8165a0b2-80f5-436f-ab47-075d824144d9",
        "message": "The requested offering is invalid",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add an existing product with invalid existingProductUrl
{
    "computeFault": {
        "guid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "message": "Invalid product URI",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add an existing product that belongs to account different from the account of the order.
{
    "computeFault": {
        "guid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "message": "The account of the order and the account of the product doesn't match",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add an existing product that does not exist
{
    "computeFault": {
        "guid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "message": "Product doesn't exist.",
        "code": 400,
        "details": ""
    }
}

400 Bad Request - trying to add an existing product that is not open
{
    "computeFault": {
        "guid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "message": "Cannot add a product that is not open.",
        "code": 400,
        "details": ""
    }
}
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.
403 Forbidden - the client does not have permission to add products.
{
    "forbidden": {
        "guid": "d336dd8e-bc52-44f3-b672-9aa2fac7fbf4",
        "message": "Unauthorized: Products failed permission check",
        "code": 403,
        "details": ""
    }
}
404 Not Found - the order does not exist
{
    "itemNotFound": {
        "guid": "e1792d8a-5b0a-43ef-adf5-34a0710c8fc5",
        "message": "Resource not found",
        "code": 404,
        "details": ""
    }
}
502 Bad Gateway - unexpected error from the backend.
{
    "computeFault": {
        "guid": "8ced5fe7-f6a9-4e8f-8700-cfc9fa15e6ce",
        "timestamp": "2014-09-10 20:59:50",
        "code": 502,
        "errorRefId": "8ced5fe7-f6a9-4e8f-8700-cfc9fa15e6ce"
    }
}

See also


blog comments powered by Disqus

Personal tools
Namespaces
Variants
Actions
APIs
Navigation
Toolbox