Changes

stoney core: Customers Resource - REST API

28,696 bytes added, 11:02, 27 July 2014
Also visit [[stoney core: Customers Resource Mapping (REST - LDAP)]].
 
= Overview =
The REST API describes the ('''Re'''presentational '''S'''tate '''T'''ransfer '''A'''pplication '''P'''rogramming '''I'''nterface) of the customers resource to be used by [[:Category:stoney core|stoney core]], [[:Category:stoney conductor|stoney conductor]] and other [[:Category:Self-Service Modules|Self-Service Modules]] or third party applications.
Basically, we want to be able to do the following things:
* Create a new customer ([[#Customer_creation_.28POST.29|POST]]).* Retrieve multiple customers in the form of a list ([[#Customer_collection_retrieval_.28GET.29|GET]]).* Retrieve a single customer ([[#Customer_element_retrieval_.28GET.29|GET]]).* Update an existing customer ([[#Customer_update_.28PUT.29|PUT]]).* Update one or more values of an existing customer ([[#Customer_partly_update_.28PATCH.29|PATCH]]).* Delete a single customer ([[#Customer_deletion_.28DELETE.29|DELETE]]).
To get an idea what happens behind the screens, have a look at the [[stoney core: Customers Resource Mapping (REST - LDAP)]] documentation located in the [[:Category:Mapping (REST - LDAP)|Mapping (REST - LDAP)]] category.
 
= Customers resource methods =
== Customer creation (POST) ==
To create a new customer the client needs to send a HTTP <code>POST</code> request on the customer collection resource URI <code>https://api.example.com/v1/customers</code> (also see [[Application_Programming_Interface_(API)#Base_URI|Base URI]]), including the associated customer information.
The service will generate a new customer and responds with a HTTP status code <code>201</code> (Created) on success. The newly created customer URI is returned within the HTTP location header, which can be used by the client to gather information about the new customer.
 
=== Customer creation request message ===
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP request part
! Content
! Example
 
|-
| Request lines
|<pre>
POST <Request-URI> HTTP 1.1
HOST: <Host>
</pre>
|<pre>
POST /v1/customers/ HTTP 1.1
HOST: api.example.com
</pre>
 
|-
| Request headers
| <pre>
Accept: <Type>/<Subtype>
Accept-Charset: <Charset>
Content-Type: <Type>/<Subtype>; charset=<Charset>
</pre>
| <pre>
Accept: application/json
Accept-Charset: UTF-8
Content-Type: application/json; charset=UTF-8
</pre>
 
|-
| [[#Customer_creation_request_message_body|Request body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
==== Customer creation request message body ====
{| class="wikitable sortable" style="width: 100%;" id="customer_object"
|-
|+ align="top" style="text-align:left;"|Customer Object
! Parameter name
! Data type
! Mandatory
! Description
! Valid content
![http://www.pcre.org/ PCRE]
! Default value
! Example
 
|-
|<code>isCompany</code>
|boolean
|yes
|<code>true</code> if the customer represents a company, <code>false</code> if it's an individual person.
|<code>true</code> or <code>false</code>
|
|
|<source lang="javascript">"isCompany": true</source>
 
|-
|<code>isActive</code>
|boolean
|yes
|
|<code>true</code> or <code>false</code>
|
|<code>true</code>
|<source lang="javascript">"isActive": true</source>
 
|-
|<code>customerName</code>
|string
|yes
|The customer's display name. Mostly the same as the <code>organizationName</code> or the <code>givenName</code> and <code>surname</code> out of the [[#billingAddress_object|billingAddress object]].
|UTF-8 {64}
|
|
|<source lang="javascript">"customerName": "Customer Ltd."</source>
 
|-
|[[#billingAddress_object|<code>billingAddress</code>]]
|object
|yes
|An object holding the billing address information for the given customer. Refer to the [[#billingAddress_object|billingAddress object table]] for more information.
|
|
|
|<source lang="javascript">
"billingAddress":
{
"organizationName": "Customer Ltd.",
"gender": 'm',
"givenName": "Name",
"surname": "Surname",
"postalAddress": "Street Number",
"countryCode": "CH",
"postalCode": "1234",
"localityName": "Locality",
"preferredLanguage": "en-GB",
"mail": "name.surname@example.com",
"telephoneNumber": "+41 00 000 00 00",
"mobileTelephoneNumber": "+41 00 000 00 00",
"websiteURL": "https://www.example.com/"
}
</source>
 
|-
|[[#shippingAddress_object|<code>shippingAddress</code>]]
|object
|no
|An object holding the shipping address information for the given customer. Refer to the [[#shippingAddress_object|shippingAddress object table]] for more information.
|
|
|
|<source lang="javascript">
"shippingAddress":
{
"organizationName": "Customer Ltd.",
"gender": 'm',
"givenName": "Name",
"surname": "Surname",
"postalAddress": "Street Number",
"countryCode": "CH",
"postalCode": "1234",
"localityName": "Locality",
"preferredLanguage": "en-GB",
"mail": "name.surname@example.com",
"telephoneNumber": "+41 00 000 00 00",
"mobileTelephoneNumber": "+41 00 000 00 00",
"websiteURL": "https://www.example.com/"
}
</source>
 
|-
|<code>externalID</code>
|string
|no
|An optional external ID the customer belongs to (is used for the mapping to external databases).
|
|@TODO add regex
|
|<source lang="javascript">"externalID": 12345</source>
 
|-
|<code>belongsToResellerID</code>
|integer
|yes
|The reseller identification number the customer resource must belong to.
|
|@TODO add regex
|
|<source lang="javascript">"belongsToResellerID": 4000000</source>
 
|}
 
{| class="wikitable sortable" style="width: 100%;" id="billingAddress_object"
|-
|+ align="top" style="text-align:left;"|billingAddress Object
!Parameter name
!Data type
!Mandatory
!Description
!Valid content
![http://www.pcre.org/ PCRE]
!Default value
!Example
 
|-
|<code>organizationName</code>
|string
|no
|The name of the organization.
|
|@TODO: Add regex
|
|<source lang="javascript">"organizationName": "Customer Ltd."</source>
 
|-
|<code>gender</code>
|string
|yes
|The gender of the address holder
|Either <code>f</code> for female, <code>m</code> for male or <code>n</code> for neutral.
|
|
|<source lang="javascript">"gender": "f"</source>
 
|-
|<code>givenName</code>
|string
|yes
|The given name (first name or forename) of the address holder.
|UTF-8 {64}
|@TODO: Add regex
|
|<source lang="javascript">"givenName": "Name"</source>
 
|-
|<code>surname</code>
|string
|yes
|The surname (last name or family name) of the address holder.
|UTF-8 {64}
|@TODO: Add regex
|
|<source lang="javascript">"surname": "Surname"</source>
 
|-
|<code>postalAddress</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"postalAddress": ""</source>
 
|-
|<code>countryCode</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"countryCode": ""</source>
 
|-
|<code>postalCode</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"postalCode": ""</source>
 
|-
|<code>localityName</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"localityName": ""</source>
 
|-
|<code>preferredLanguage</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"preferredLanguage": ""</source>
 
|-
|<code>mail</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"mail": ""</source>
 
|-
|<code>telephoneNumber</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"telephoneNumber": ""</source>
 
|-
|<code>mobileTelephoneNumber</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"mobileTelephoneNumber": ""</source>
 
|-
|<code>websiteURL</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"websiteURL": ""</source>
 
|}
 
{| class="wikitable sortable" style="width: 100%;" id="shippingAddress_object"
|-
|+ align="top" style="text-align:left;"|shippingAddress Object
!Parameter name
!Data type
!Mandatory
!Description
!Valid content
![http://www.pcre.org/ PCRE]
!Default value
!Example
 
|-
|<code>organizationName</code>
|string
|no
|The name of the organization.
|
|@TODO: Add regex
|
|<source lang="javascript">"organizationName": "Customer Ltd."</source>
 
|-
|<code>gender</code>
|string
|yes
|The gender of the address holder
|Either <code>f</code> for female, <code>m</code> for male or <code>n</code> for neutral.
|
|
|<source lang="javascript">"gender": "f"</source>
 
|-
|<code>givenName</code>
|string
|yes
|The given name (first name or forename) of the address holder.
|
|@TODO: Add regex
|
|<source lang="javascript">"givenName": "Name"</source>
 
|-
|<code>surname</code>
|string
|yes
|The surname (last name or family name) of the address holder.
|
|@TODO: Add regex
|
|<source lang="javascript">"surname": "Surname"</source>
 
|-
|<code>postalAddress</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"postalAddress": ""</source>
 
|-
|<code>countryCode</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"countryCode": ""</source>
 
|-
|<code>postalCode</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"postalCode": ""</source>
 
|-
|<code>localityName</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"localityName": ""</source>
 
|-
|<code>preferredLanguage</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"preferredLanguage": ""</source>
 
|-
|<code>mail</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"mail": ""</source>
 
|-
|<code>telephoneNumber</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"telephoneNumber": ""</source>
 
|-
|<code>mobileTelephoneNumber</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"mobileTelephoneNumber": ""</source>
 
|-
|<code>websiteURL</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"websiteURL": ""</source>
 
|}
 
=== Customer creation response message ===
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP response part
! Content
! Example
 
|-
| Status Line
| <pre>HTTP/1.1 <HTTP-Status-Code> <HTTP-Status-Message></pre>
| <pre>HTTP/1.1 201 Created</pre>
 
|-
| Response headers
|<pre>
Content-Type: <Type>/<Subtype>; charset=<Charset>
Location: <Location-URI>
</pre>
|<pre>
Content-Type: Content-Type: application/json; charset=UTF-8
Location: https://api.example.com/v1/customers/5000001
</pre>
 
|-
| [[#Customer_creation_response_message_body|Response body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
==== Customer creation response message body ====
{| class="wikitable sortable" style="width: 100%;" id="customer_creation_response_object"
|-
|+ align="top" style="text-align:left;"|Customer Creation Response Object
! Parameter name
! Data type
! Mandatory
! Description
! Valid content
![http://www.pcre.org/ PCRE]
! Default value
! Example
 
|-
|<code>id</code>
|integer
|yes
|The identification number of the newly created customer resource.
|
|@TODO add regex
|
|<source lang="javascript">"id": 5000001</source>
 
|-
|<code>location</code>
|string
|yes
|The location URI of the newly created customer resource, corresponds with the HTTP location header.
|@TODO add link to URI RFC
|
|
|<source lang="javascript">"location": "https://api.example.com/v1/customers/5000001"</source>
 
|-
|[[stoney_core:_REST_API#Error_codes_and_responses|<code>error</code>]]
|object
|no
|In case of a failure, an error object with the appropriate error messages will be returned. Refer to the [[stoney_core:_REST_API#Error_codes_and_responses|Error codes and response chapter]] for more information.
|
|
|
|<source lang="javascript">"error": { /* ... */ }</source>
 
|}
 
== Customer retrieval (GET) ==
=== Customer collection retrieval (GET) ===
To retrieve existing customers, the client needs to send a HTTP <code>GET</code> request on the customer's collection resource URI <code>https://api.example.com/v1/customers</code>.
The service responds with a HTTP status code 200 (OK) on success and returns the various customers.
 
Note that the service will only return a limited amount of objects at once and provides links for retrieving further objects. Refer to the [[stoney_core:_REST_API#Pagination|Pagination chapter]] for more information.
 
==== Sort ====
If you don't add a sort attribute, the collection will be sorted by '''id''' (ascending). If you would like a sorted collection answer, the query parameter sort must be added with the object's sort attribute(s) as the value: <code>https://api.example.com/v1/customers?sort=customerName,isActive</code>. For further information on filtering, sorting and searching, visit [[stoney_core:_REST_API#Filtering.2C_sorting_and_searching | stoney core: REST API]].
 
==== Search (fulltext) ====
To form a fulltext search (customers only), append the url query parameter '''q''' with the desired search text: <code>https://api.example.com/v1/customers?q=example</code>. The document [[stoney_core:_Search_Resource_-_REST_API#Customers_Search_.28GET.29 | stoney core: Search Resource - REST API]] describes the search in detail.
 
==== Search (with filter) ====
To form a specific search, append the url query attribute(s) name (for example '''customerName''') with the desired search text: <code>https://api.example.com/v1/customers?customerName=example</code>. You're allowed to search for all attributes that are returned in the [[#Customer_element_retrieval_response_message_body | Customer element retrieval response message body]].
 
==== Customer collection retrieval request message ====
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP request part
! Content
! Example
 
|-
| Request lines
|<pre>
GET <Request-URI> HTTP 1.1
HOST: <Host>
</pre>
|<pre>
GET /v1/customers/ HTTP 1.1
HOST: api.example.com
</pre>
 
|-
| Request headers
| <pre>
Accept: <Type>/<Subtype>
Accept-Charset: <Charset>
</pre>
| <pre>
Accept: application/json
Accept-Charset: UTF-8
</pre>
 
|-
| Request body
| <Empty>
| <pre></pre>
 
|}
 
==== Customer collection retrieval response message ====
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP response part
! Content
! Example
 
|-
| Status Line
| <pre>HTTP/1.1 <HTTP-Status-Code> <HTTP-Status-Message></pre>
| <pre>HTTP/1.1 200 OK</pre>
 
|-
| Response headers
|<pre>
Content-Type: <Type>/<Subtype>; charset=<Charset>
Location: <Location-URI>
Link:
X-Total-Count:
</pre>
|<pre>
Content-Type: Content-Type: application/json; charset=UTF-8
Link: <https://api.example.com/v1/customers?page=1&per_page=30>; rel="first",
<https://api.example.com/v1/customers?page=2&per_page=30>; rel="prev",
<https://api.example.com/v1/customers?page=4&per_page=30>; rel="next",
<https://api.example.com/v1/customers?page=10&per_page=30>; rel="last"
X-Total-Count: 295
</pre>
 
|-
| [[#customer_collection_retrieval_response_object|Response body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
====== Customer collection retrieval response message body ======
{| class="wikitable sortable" style="width: 100%;" id="customer_collection_retrieval_response_object"
|-
|+ align="top" style="text-align:left;"|Customer Collection Retrieval Response Object
! Parameter name
! Data type
! Mandatory
! Description
! Valid content
! [http://www.pcre.org/ PCRE]
! Default value
! Example
 
 
|-
|
|array
|no
|An array with one or more [[#customer_collection_array_element_object|customer collection objects]]
|
|
|
|<source lang="javascript">
[
{
"id": 5000000,
"location": "https://api.example.com/v1/customers/5000000",
"isCompany": true,
"isActive": true,
"customerName": "Customer Ltd."
"countryCode": "CH",
"postalCode": "3012",
"localityName": "Bern",
"belongsToResellerID": 4000000
},
{
/* ... */
}
]
</source>
 
|-
|[[stoney_core:_REST_API#Error_codes_and_responses|<code>error</code>]]
|object
|no
|In case of a failure, an error object with the appropriate error messages will be returned. Refer to the [[stoney_core:_REST_API#Error_codes_and_responses|Error codes and response chapter]] for more information.
|
|
|
|<source lang="javascript">error { /* ... */ }</source>
 
|}
 
 
 
{| class="wikitable sortable" style="width: 100%;" id="customer_collection_array_element_object"
|-
|+ align="top" style="text-align:left;"|Customer Collection Array Element Object
!Parameter name
!Data type
!Mandatory
!Description
!Valid content
![http://www.pcre.org/ PCRE]
!Default value
!Example
 
|-
|<code>id</code>
|integer
|yes
|The identification number of the customer.
|
|@TODO add regex
|
|<source lang="javascript">"id": 5000000</source>
 
|-
|<code>location</code>
|string
|yes
|The location URI of the customer resource.
|@TODO add link to URI RFC
|
|
|<source lang="javascript">"location": "https://api.example.com/v1/customers/5000000"</source>
 
|-
|<code>isCompany</code>
|boolean
|yes
|<code>true</code> if the customer represents a company, <code>false</code> if it's an individual person.
|<code>true</code> or <code>false</code>
|
|
|<source lang="javascript">"isCompany": true</source>
 
|-
|<code>isActive</code>
|boolean
|yes
|
|<code>true</code> or <code>false</code>
|
|<code>true</code>
|<source lang="javascript">"isActive": true</source>
 
|-
|<code>customerName</code>
|string
|yes
|The customer's display name. Mostly the same as the <code>organizationName</code> or the <code>givenName</code> and <code>surname</code> out of the [[#billingAddress_object|billingAddress object]].
|
|
|
|<source lang="javascript">"customerName": "Customer Ltd."</source>
 
|-
|<code>countryCode</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"countryCode": "CH"</source>
 
|-
|<code>postalCode</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"postalCode": "3012"</source>
 
|-
|<code>localityName</code>
|string
|yes
|
|
|@TODO: Add regex
|
|<source lang="javascript">"localityName": "Bern</source>
 
|-
|<code>belongsToResellerID</code>
|integer
|yes
|The reseller identification number the customer resource must belong to.
|
|@TODO add regex
|
|<source lang="javascript">"belongsToResellerID": 4000000</source>
 
|}
 
=== Customer element retrieval (GET) ===
To retrieve an existing customer and fetch the information associated with it, the client needs to send a HTTP <code>GET</code> request on the customer's element resource URI (such as <code>https://api.example.com/v1/customers/5000001</code>.
The service responds with a HTTP status code 200 (OK) on success and returns the associated customer information.
 
==== Customer element retrieval request message ====
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP request part
! Content
! Example
 
|-
| Request lines
|<pre>
GET <Request-URI> HTTP 1.1
HOST: <Host>
</pre>
|<pre>
GET /v1/customers/5000001 HTTP 1.1
HOST: api.example.com
</pre>
 
|-
| Request headers
| <pre>
Accept: <Type>/<Subtype>
Accept-Charset: <Charset>
</pre>
| <pre>
Accept: application/json
Accept-Charset: UTF-8
</pre>
 
|-
| Request body
| <Empty>
| <pre></pre>
 
|}
 
==== Customer element retrieval response message ====
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP response part
! Content
! Example
 
|-
| Status Line
| <pre>HTTP/1.1 <HTTP-Status-Code> <HTTP-Status-Message></pre>
| <pre>HTTP/1.1 200 OK</pre>
 
|-
| Response headers
|<pre>
Content-Type: <Type>/<Subtype>; charset=<Charset>
Location: <Location-URI>
</pre>
|<pre>
Content-Type: Content-Type: application/json; charset=UTF-8
Location: https://api.example.com/v1/customers/5000001
</pre>
 
|-
| [[#Customer_element_retrieval_response_message_body|Response body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
====== Customer element retrieval response message body ======
{| class="wikitable sortable" style="width: 100%;" id="customer_element_retrival_response_object"
|-
|+ align="top" style="text-align:left;"|Customer Element Retrieval Response Object
! Parameter name
! Data type
! Mandatory
! Description
! Valid content
! [http://www.pcre.org/ PCRE]
! Default value
! Example
 
|-
|<code>id</code>
|integer
|yes
|The identification number of the customer.
|
|@TODO add regex
|
|<source lang="javascript">"id": 5000001</source>
 
|-
|<code>isCompany</code>
|boolean
|yes
|<code>true</code> if the customer represents a company, <code>false</code> if it's an individual person.
|<code>true</code> or <code>false</code>
|
|
|<source lang="javascript">"isCompany": true</source>
 
|-
|<code>isActive</code>
|boolean
|yes
|
|<code>true</code> or <code>false</code>
|
|<code>true</code>
|<source lang="javascript">"isActive": true</source>
 
|-
|<code>customerName</code>
|string
|yes
|The customer's display name. Mostly the same as the <code>organizationName</code> or the <code>givenName</code> and <code>surname</code> out of the [[#billingAddress_object|billingAddress object]].
|
|
|
|<source lang="javascript">"customerName": "Customer Ltd."</source>
 
|-
|<code>externalID</code>
|string
|no
|An optional external ID the customer belongs to (is used for the mapping to external databases).
|
|@TODO add regex
|
|<source lang="javascript">"externalID": 12345</source>
 
|-
|<code>belongsToResellerID</code>
|integer
|yes
|The reseller identification number the customer resource must belong to.
|
|@TODO add regex
|
|<source lang="javascript">"belongsToResellerID": 4000000</source>
 
|-
|[[#billingAddress_object|<code>billingAddress</code>]]
|object
|yes
|An object holding the billing address information for the given customer. Refer to the [[#billingAddress_object|billingAddress object table]] for more information.
|
|
|
|<source lang="javascript">
"billingAddress":
{
"organizationName": "Customer Ltd.",
"gender": 'm',
"givenName": "Name",
"surname": "Surname",
"postalAddress": "Street Number",
"countryCode": "CH",
"postalCode": "1234",
"localityName": "Locality",
"preferredLanguage": "en-GB",
"mail": "name.surname@example.com",
"telephoneNumber": "+41 00 000 00 00",
"mobileTelephoneNumber": "+41 00 000 00 00",
"websiteURL": "https://www.example.com/"
}
</source>
 
|-
|[[#shippingAddress_object|<code>shippingAddress</code>]]
|object
|no
|An object holding the shipping address information for the given customer. Refer to the [[#shippingAddress_object|shippingAddress object table]] for more information.
|
|
|
|<source lang="javascript">
"shippingAddress":
{
"organizationName": "Customer Ltd.",
"gender": 'm',
"givenName": "Name",
"surname": "Surname",
"postalAddress": "Street Number",
"countryCode": "CH",
"postalCode": "1234",
"localityName": "Locality",
"preferredLanguage": "en-GB",
"mail": "name.surname@example.com",
"telephoneNumber": "+41 00 000 00 00",
"mobileTelephoneNumber": "+41 00 000 00 00",
"websiteURL": "https://www.example.com/"
}
</source>
 
|-
|<code>employees</code>
|string
|yes
|The location URI of the employees belonging to this customer resource.
|@TODO add link to URI RFC
|
|
|<source lang="javascript">"employees": "https://api.example.com/v1/customers/5000001/employees"</source>
 
|-
|<code>users</code>
|string
|yes
|The location URI of the users belonging to this customer resource.
|@TODO add link to URI RFC
|
|
|<source lang="javascript">"users": "https://api.example.com/v1/customers/5000001/users"</source>
 
|-
|[[stoney_core:_REST_API#Error_codes_and_responses|<code>error</code>]]
|object
|no
|In case of a failure, an error object with the appropriate error messages will be returned. Refer to the [[stoney_core:_REST_API#Error_codes_and_responses|Error codes and response chapter]] for more information.
|
|
|
|<source lang="javascript">"error": { /* ... */ }</source>
 
|}
 
== Customer update (PUT) ==
To updates an existing customer, the client needs to send a HTTP <code>PUT</code> request on the customer's element resource URI (such as, <code>https://api.example.com/v1/customers/5000001</code>).
The service responds with a HTTP status code 200 (OK) on success and returns an empty body.
 
The <code>PUT</code> method requires one to sent the complete record, thus the work-flow is normally as follows:
# A [[#Customer_element_retrieval_.28GET.29|GET]] request on the Customer element URI will be made to fetch the whole document.
# Update the fields which content has changed
# Send a <code>PUT</code> request with all the customer data
 
=== Customer update request message ===
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP request part
! Content
! Example
 
|-
| Request lines
|<pre>
PUT <Request-URI> HTTP 1.1
HOST: <Host>
</pre>
|<pre>
PUT /v1/customers/5000001 HTTP 1.1
HOST: api.example.com
</pre>
 
|-
| Request headers
| <pre>
Accept: <Type>/<Subtype>
Accept-Charset: <Charset>
Content-Type: <Type>/<Subtype>; charset=<Charset>
</pre>
| <pre>
Accept: application/json
Accept-Charset: UTF-8
Content-Type: application/json; charset=UTF-8
</pre>
 
|-
| [[#Customer_update_request_message_body|Request body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
==== Customer update request message body ====
See [[#customer_object|Customer object]].
 
=== Customer update response message ===
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP response part
! Content
! Example
 
|-
| Status Line
| <pre>HTTP/1.1 <HTTP-Status-Code> <HTTP-Status-Message></pre>
| <pre>HTTP/1.1 200 OK</pre>
 
|-
| Response headers
|<pre>
Content-Type: <Type>/<Subtype>; charset=<Charset>
</pre>
|<pre>
Content-Type: Content-Type: application/json; charset=UTF-8
</pre>
 
|-
| [[#Customer_update_response_message_body|Response body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
==== Customer update response message body ====
On success (<code>200</code>) an empty response message body will be returned, otherwise an [[stoney_core:_REST_API#Error_codes_and_responses|error object]] will provide further information about the failure.
 
== Customer partly update (PATCH) ==
To update fields of an existing customer, the client needs to send a HTTP <code>PATCH</code> request on the customer's element resource URI (such as, <code>https://api.example.com/v1/customers/5000001</code>).
The service responds with a HTTP status code 200 (OK) on success and returns an empty body.
 
In contrast to the [[#Customer_update_.28PUT.29|<code>PUT</code>]] method, only the changed fields are to be included in the request.
 
=== Customer partly update request message ===
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP request part
! Content
! Example
 
|-
| Request lines
|<pre>
PATCH <Request-URI> HTTP 1.1
HOST: <Host>
</pre>
|<pre>
PATCH /v1/customers/5000001 HTTP 1.1
HOST: api.example.com
</pre>
 
|-
| Request headers
| <pre>
Accept: <Type>/<Subtype>
Accept-Charset: <Charset>
Content-Type: <Type>/<Subtype>; charset=<Charset>
</pre>
| <pre>
Accept: application/json
Accept-Charset: UTF-8
Content-Type: application/json; charset=UTF-8
</pre>
 
|-
| [[#Customer_update_request_message_body|Request body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
==== Customer partly update request message body ====
The JSON message body consists out of one or more fields from the [[#customer_object|Customer object]].
@TODO: Add example.
 
=== Customer partly update response message ===
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP response part
! Content
! Example
 
|-
| Status Line
| <pre>HTTP/1.1 <HTTP-Status-Code> <HTTP-Status-Message></pre>
| <pre>HTTP/1.1 200 OK</pre>
 
|-
| Response headers
|<pre>
Content-Type: <Type>/<Subtype>; charset=<Charset>
</pre>
|<pre>
Content-Type: Content-Type: application/json; charset=UTF-8
</pre>
 
|-
| [[#Customer_partly_update_response_message_body|Response body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
==== Customer partly update response message body ====
On success (<code>200</code>) an empty response message body will be returned, otherwise an [[stoney_core:_REST_API#Error_codes_and_responses|error object]] will provide further information about the failure.
 
== Customer deletion (DELETE) ==
To delete an existing customer, the client needs to send a HTTP <code>DELETE</code> request, with an empty request body on the customer's element resource URI (such as, <code>https://api.example.com/v1/customers/5000001</code>). The service responds with a HTTP status code <code>200</code> (OK) on success and returns an empty body.
 
=== Customer deletion request message ===
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP request part
! Content
! Example
 
|-
| Request lines
|<pre>
DELETE <Request-URI> HTTP 1.1
HOST: <Host>
</pre>
|<pre>
DELETE /v1/customers/5000001 HTTP 1.1
HOST: api.example.com
</pre>
 
|-
| Request headers
| <pre>
Accept: <Type>/<Subtype>
Accept-Charset: <Charset>
</pre>
| <pre>
Accept: application/json
Accept-Charset: UTF-8
</pre>
 
|-
| Request body
| <Empty>
| <pre></pre>
 
|}
 
=== Customer deletion response message ===
{| class="wikitable sortable" style="width: 100%;"
|-
! HTTP response part
! Content
! Example
 
|-
| Status Line
| <pre>HTTP/1.1 <HTTP-Status-Code> <HTTP-Status-Message></pre>
| <pre>HTTP/1.1 200 OK</pre>
 
|-
| Response headers
|<pre>
Content-Type: <Type>/<Subtype>; charset=<Charset>
</pre>
|<pre>
Content-Type: Content-Type: application/json; charset=UTF-8
</pre>
 
|-
| [[#Customer_partly_update_response_message_body|Response body]]
| JSON object
| <source lang="javascript">{ ... }</source>
 
|}
 
==== Customer deletion response message body ====
On success (<code>200</code>) an empty response message body will be returned, otherwise an [[stoney_core:_REST_API#Error_codes_and_responses|error object]] will provide further information about the failure.
 
== Customer search ==
The customer search is a sub section of the [[stoney core: Search Resource - REST API]] and is described there in more detail.
 
= Links =
* [[stoney core: REST API]]
[[Category:REST API]][[Category:stoney core]]
SLB, editor, reviewer
3,368
edits