Difference between revisions of "Add Customer"

From MyMobileWorkers API
Jump to: navigation, search
(→‎JSON As Body)
 
(18 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
== Summary ==
 
== Summary ==
 +
 +
 +
The add customer action allows users to attach a customer to their company.
 +
This method accepts an array of customers to be added to the system.
 +
A customer can be created via two different methods - either as multi-part form data with a JSON file attached and the API key as a parameter, or as JSON content on it's own, with the API key supplied within the JSON.
 +
 +
==== Multi Part Form Data ====
 
{| border="1" class="wikitable"
 
{| border="1" class="wikitable"
  
Line 22: Line 29:
 
|}
 
|}
  
 +
==== JSON As Body ====
 +
{| border="1" class="wikitable"
 +
! Add Customer - JSON
 +
! colspan="2" |
 +
|-
 +
!  URL
 +
| colspan="2" | http://base_url/api_path/version/companies/company/customers/customer
 +
|-
 +
! Type
 +
| colspan="2" |POST
 +
|-
 +
!
 +
| JSON <br /> {key, validate_only(optional), update_existing(optional), customers[]}  ||| required   
 +
|-
 +
! Response
 +
| colspan="2" | JSON
 +
|}
  
−
5 contact_name
+
== JSON Contents ==
−
6 address_1
+
−
7 address_2
+
−
8 address_3
+
−
9 address_4
+
−
10 postcode
+
−
11 contact_number
+
−
 
+
−
The add customer action allows users to attach a customer to their company.
+
−
 
+
−
== JSON Parameters ==
+
  
 
{| border="1" class="wikitable"
 
{| border="1" class="wikitable"
Line 44: Line 58:
 
|-
 
|-
 
! contact_name
 
! contact_name
−
| varchar(45) <br /><span style="font-size:80%; font-weight:normal">* must be unique</span>|| &#10003;
+
| varchar(45) ||
 
|-
 
|-
 
! name
 
! name
−
| varchar(255) ||
+
| varchar(255) <br /><span style="font-size:80%; font-weight:normal">* must be unique</span>|| &#10003;
 
|-
 
|-
 +
! external_id
 +
| varchar(45) ||
 +
|-
 
! address_1
 
! address_1
 
| varchar(45) ||
 
| varchar(45) ||
Line 67: Line 84:
 
| varchar(45) ||  
 
| varchar(45) ||  
 
|-  
 
|-  
 +
! contact_email
 +
| varchar(255) ||
 +
|-
 +
! sic_code
 +
| int(11) ||
 +
|-
 
|}
 
|}
  
−
=== Example JSON ===
+
{| border="1" class="wikitable"
−
{
+
|+ Fields exclusive to JSON body format:
 +
! colspan="3" | Standard Fields
 +
|-
 +
! Field
 +
! Expected Data
 +
! Required
 +
|-
 +
! key
 +
| string - company api key || &#10003;
 +
|-
 +
! update_existing
 +
| boolean ||
 +
|-
 +
! validate_only
 +
| boolean ||
 +
|-
 +
|}
 +
 
 +
== Example Input ==
 +
 
 +
==== Multi Part Form Data ====
 +
 
 +
<source lang="java">
 
   "customers":[
 
   "customers":[
 
       {
 
       {
 
         "name":"LeeLand",
 
         "name":"LeeLand",
 +
        "external_id":"hello",
 +
        "contact_name":"Mark Moose",
 +
        "address_1":"1 the street",
 +
        "postcode":"WA12 0JQ",
 +
        "contact_number":"01942295900",
 +
        "sic_code":238495,
 +
        "contact_email":"stephen@mymobileworkers.com"
 +
      }
 +
  ]
 +
</source>
 +
 +
==== JSON As Body ====
 +
<source lang="java">
 +
{"key":"test", "validate_only":"true", "update_existing":"true", "customers":[
 +
      {
 +
        "name":"LeeLand",
 +
        "external_id":"hello",
 
         "contact_name":"Mark Moose",
 
         "contact_name":"Mark Moose",
 
         "address_1":"1 the street",
 
         "address_1":"1 the street",
 
         "postcode":"WA12 0JQ",
 
         "postcode":"WA12 0JQ",
 
         "contact_number":"01942295900"
 
         "contact_number":"01942295900"
 +
        "sic_code":238495,
 +
        "contact_email":"stephen@mymobileworkers.com"
 
       }
 
       }
 
   ]
 
   ]
 
}
 
}
 +
</source>
  
−
== Example curl request ==
+
== Example Curl Requests ==
−
curl -F validate_only=false -F update_existing=true -F api_key=YOURKEY -F file=@/Users/lee_orritt/Desktop/webAPICurling/create_customer.txt  http://test.mymobileworkers.com:8080/api/1/companies/company/customers/customer
+
 
 +
==== Multi Part Form Data ====
 +
 
 +
curl -F validate_only=false -F update_existing=true -F api_key=YOURKEY -F file=@/Users/lee_orritt/Desktop/webAPICurling/create_customer.txt  http://api.mymobileworkers.com:8080/api/1/companies/company/customers/customer
 +
 
 +
==== JSON As Body ====
 +
 
 +
curl -X POST -H "Content-Type: application/json" -d '{"key":"APIKEYGOESHERE", "validate_only":"true", "update_existing":"true", "customers":[{"name":"Above Average Construction Ltd.","external_id":"TestID234","contact_name":"Steve G","address_1":"123 The Street","postcode":"WA12 0JQ","contact_number":"01512143108","sic_code":238495,"contact_email":"stephen@mymobileworkers.com"}]}' http://api.mymobileworkers.com:8080/api/1/companies/company/customers/customer
  
 
== Responses ==
 
== Responses ==
 +
 
=== Example JSON ===
 
=== Example JSON ===
  
 
<source lang="java">
 
<source lang="java">
−
{"file":"tick.png","comment":"Transferred from API","created_at":"2013-05-20T14:42:37+00:00"}
+
{
 +
  "file":"tick.png",
 +
  "comment":"Transferred from API",
 +
  "created_at":"2013-05-20T14:42:37+00:00"
 +
}
 
</source>
 
</source>

Latest revision as of 12:48, 14 November 2016

Contents

[edit] Summary

The add customer action allows users to attach a customer to their company. This method accepts an array of customers to be added to the system. A customer can be created via two different methods - either as multi-part form data with a JSON file attached and the API key as a parameter, or as JSON content on it's own, with the API key supplied within the JSON.

[edit] Multi Part Form Data

Add Customer
URL http://base_url/api_path/version/companies/company/customers/customer
Type POST
Params: api_key required
file required
Response JSON

[edit] JSON As Body

Add Customer - JSON
URL http://base_url/api_path/version/companies/company/customers/customer
Type POST
JSON
{key, validate_only(optional), update_existing(optional), customers[]}
required
Response JSON

[edit] JSON Contents

The JSON file is passed in the post as the "file"
Standard Fields
Field Expected Data Required
contact_name varchar(45)
name varchar(255)
* must be unique
✓
external_id varchar(45)
address_1 varchar(45)
address_2 varchar(45)
address_3 varchar(45)
address_4 varchar(45)
postcode varchar(45)
contact_number varchar(45)
contact_email varchar(255)
sic_code int(11)
Fields exclusive to JSON body format:
Standard Fields
Field Expected Data Required
key string - company api key ✓
update_existing boolean
validate_only boolean

[edit] Example Input

[edit] Multi Part Form Data

   "customers":[
      {
         "name":"LeeLand",
         "external_id":"hello",
         "contact_name":"Mark Moose",
         "address_1":"1 the street",
         "postcode":"WA12 0JQ",
         "contact_number":"01942295900",
         "sic_code":238495,
         "contact_email":"stephen@mymobileworkers.com"
      }
   ]

[edit] JSON As Body

{"key":"test", "validate_only":"true", "update_existing":"true", "customers":[
      {
         "name":"LeeLand",
         "external_id":"hello",
         "contact_name":"Mark Moose",
         "address_1":"1 the street",
         "postcode":"WA12 0JQ",
         "contact_number":"01942295900"
         "sic_code":238495,
         "contact_email":"stephen@mymobileworkers.com"
      }
   ]
}

[edit] Example Curl Requests

[edit] Multi Part Form Data

curl -F validate_only=false -F update_existing=true -F api_key=YOURKEY -F file=@/Users/lee_orritt/Desktop/webAPICurling/create_customer.txt http://api.mymobileworkers.com:8080/api/1/companies/company/customers/customer

[edit] JSON As Body

curl -X POST -H "Content-Type: application/json" -d '{"key":"APIKEYGOESHERE", "validate_only":"true", "update_existing":"true", "customers":[{"name":"Above Average Construction Ltd.","external_id":"TestID234","contact_name":"Steve G","address_1":"123 The Street","postcode":"WA12 0JQ","contact_number":"01512143108","sic_code":238495,"contact_email":"stephen@mymobileworkers.com"}]}' http://api.mymobileworkers.com:8080/api/1/companies/company/customers/customer

[edit] Responses

[edit] Example JSON

{
   "file":"tick.png",
   "comment":"Transferred from API",
   "created_at":"2013-05-20T14:42:37+00:00"
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox