Orders-orderId-account-products:POST

From Hostway API Documentation
(Difference between revisions)
Jump to: navigation, search
m (1 revision)
m (1 revision: Release 101)
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
= POST /orders/''{orderId}''/account/products =
 
= POST /orders/''{orderId}''/account/products =
Adds a new Product to the Account's Order.
+
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, 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).
Line 10: Line 10:
 
<code>POST /orders/''{orderId}''/account/products</code>
 
<code>POST /orders/''{orderId}''/account/products</code>
  
==== Request Parameters ====
+
=== Request Parameters ===
 
{{UriParameter-OrderId}}
 
{{UriParameter-OrderId}}
  
Line 23: Line 23:
  
 
=== Request Body ===
 
=== Request Body ===
 +
There are two possible formats.  To add a new product that does not already exist:
 
  <nowiki>
 
  <nowiki>
 
{
 
{
   "offering": "</nowiki>{{APIBaseURL}}<nowiki>/productSpecifications/{productSpecificationId}/offerings/{productOfferingId}"
+
   "offering": "</nowiki>{{APIBaseURL}}<nowiki>/productSpecifications/{productSpecificationId}/offerings/{productOfferingId}",
}
+
  "promoCode": "{promoCode}",
  </nowiki>
+
  "displayName": "My custom product name",
 +
  "partnerId": "PartnerId",
 +
}</nowiki>
 +
 
 +
OR
 +
 
 +
To specify an existing product, use the following:
 +
  <nowiki>
 +
{
 +
  "existingProductUrl": "</nowiki>{{APIBaseURL}}<nowiki>/accounts/{accountId}/products/{productId}"
 +
}</nowiki>
  
 
==== Parameters ====
 
==== Parameters ====
 
; offering - ''string''
 
; offering - ''string''
: Link to the [[Products|product catalog offering]] specifying the new product.
+
: Link to the [[Products#Product_Offerings|product catalog offering]] specifying the new product.
 +
; promoCode - ''string'' (optional)
 +
: A promotion code for the new product [[Orders#Promotion_Codes|promotion codes]].
 +
; displayName - ''string'' (optional)
 +
: A custom display name for the product.
 +
; partnerId - ''string'' (optional)
 +
: Partner id.
 +
; existingProductUrl - ''string''
 +
: Link to [[Account#Products_Management|an existing product]].  Only required when adding an existing product to the order.
 +
 
 +
=== Validation Rules ===
 +
:# The product specification URL ( ''{{APIBaseURL}}/productSpecifications/{productSpecificationId}'' ) should point to an existing product.
 +
:# The product offering currency should match the account currency or if no account is specified should be allowed for the franchise.
 +
:# The product offering URL ( ''{{APIBaseURL}}/productSpecifications/{productSpecificationId}/offerings/{productOfferingId}'' ) should point to an existing product offering.
 +
:# The product use type (public, internal, internal view only, etc.) should be allowed for the current user.
 +
:# The product offering should be valid according to the back-end.
 +
:# The account product URL ( ''{APIBaseURL}}/accounts/{accountId}/products/{productId}'' ) should point to an existing product that is open and belongs to the account.
  
 
== Response ==
 
== Response ==
  
 
=== Status Code ===
 
=== Status Code ===
;201 Created
+
{| class="wikitable"
: The product was successfully added to the order.
+
! Status Code
 +
! Error Message
 +
! Description
 +
|-
 +
| 201 Created
 +
| -
 +
| The operation was successfully completed.
 +
|-
 +
| rowspan="12"| 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.
 +
|}
  
;400 Bad Request
+
=== Response Headers ===
: The request body contains invalid JSON or the values do not adhere to the restrictions set for them.
+
; Location
 +
: Returned with successful response. Contains the URI of the newly added product and the id of the product.
  
;401 Unauthorized
+
=== Response Body ===
: The ''OwnerId'' cookie was not specified or is incorrect.
+
==== Successful response ====
 +
<nowiki>
 +
201 Created
 +
{
 +
  "productId": "00000148842a5f6448a61ce6007f000000010001",
 +
  "url" : "</nowiki>{{APIBaseURL}}<nowiki>/orders/0000014884293798c68eafa5007f000000010001/account/products/00000148842a5f6448a61ce6007f000000010001/"
 +
}</nowiki>
 +
: '''''Note:''''' The product Id will change once the order is provisioned.
  
;403 Forbidden
+
==== Error responses ====
: The client does not have permissions to add products.
+
<nowiki>
 +
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": ""
 +
    }
 +
}
  
;404 Not Found
+
400 Bad Request - trying to add a product, which is internal view only, such products cannot be added via the Public API.
: An account has not been added to the given order or the order does not exist.
+
{
 +
    "computeFault": {
 +
        "guid": "3ee2bd37-81ee-4a57-bd63-dc84705b3985",
 +
        "message": "Trying to add Internal View Only product {product}",
 +
        "code": 400,
 +
        "details": ""
 +
    }
 +
}
  
=== Response Headers ===
+
400 Bad Request - trying to add a product without supplying the required attributes in the body.
; Location
+
{
: Returned with successful response. Contains the URI of the newly added product.
+
    "badRequest":{
 +
        "guid": "0f3e0435-21ac-43e5-acfd-ac33886fbe70",
 +
        "message": "POST data error",
 +
        "code": 400,
 +
        "details": {
 +
            "offering": "Required"
 +
        }
 +
    }
 +
}
  
=== Response Body ===
+
400 Bad Request - trying to add a product that does not exist.
None.
+
{
 +
    "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": ""
 +
    }
 +
}</nowiki>
 +
 
 +
<nowiki>
 +
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.</nowiki>
 +
 
 +
<nowiki>
 +
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": ""
 +
    }
 +
}</nowiki>
 +
 
 +
<nowiki>
 +
404 Not Found - the order does not exist
 +
{
 +
    "itemNotFound": {
 +
        "guid": "e1792d8a-5b0a-43ef-adf5-34a0710c8fc5",
 +
        "message": "Resource not found",
 +
        "code": 404,
 +
        "details": ""
 +
    }
 +
}</nowiki>
 +
 
 +
<nowiki>
 +
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"
 +
    }
 +
}</nowiki>
  
 
== See also ==
 
== See also ==

Latest revision as of 22:49, 16 December 2014

[edit] 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


[edit] Request

POST /orders/{orderId}/account/products

[edit] Request Parameters

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

[edit] URI Parameters

None.

[edit] 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.

[edit] 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}"
}

[edit] 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.

[edit] 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.

[edit] Response

[edit] 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.

[edit] Response Headers

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

[edit] Response Body

[edit] 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.

[edit] 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"
    }
}

[edit] See also


blog comments powered by Disqus

Personal tools
Namespaces
Variants
Actions
APIs
Navigation
Toolbox