Difference between revisions of "Create Category"

From MyMobileWorkers API
Jump to: navigation, search
(→‎JSON As Body)
(→‎JSON Contents)
Line 84: Line 84:
 
| string - company api key || ✓
 
| string - company api key || ✓
 
|-
 
|-
−
! updating_existing
+
! update_existing
 
| boolean ||
 
| boolean ||
 
|-  
 
|-  
Line 91: Line 91:
 
|-  
 
|-  
 
|}
 
|}
−
 
  
 
== Example Input ==
 
== Example Input ==

Revision as of 12:13, 20 December 2013

Contents

Summary

The 'create category' method accepts an array of categories to be added to the system. A category 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.

If the 'update_existing' parameter is set, then any existing categories will be updated in the system. If set to false or not provided, then any category where the category name is not unique will be rejected.

If 'validate_only' is set, the items will only be validated but not actually inserted into the database. This can be used to check an entire dataset for errors before submitting.

Multi Part Form Data

Create Category
URL http://base_url/api_path/version/categories
Type POST
Params: api_key required
file required
update_existing optional (default = false)
validate_only optional (default = false)
Response JSON

JSON As Body

Create Job - JSON
URL http://base_url/api_path/version/categories
Type POST
JSON
{key, validate_only(optional), update_existing(optional), categories[]}
required
Response JSON

JSON Contents

The JSON file is passed in the post as the "file"
Standard Fields
Field Expected Data Required
external_id varchar(45)
name varchar(255)
* must be unique
✓
Fields exclusive to JSON body format:
Standard Fields
Field Expected Data Required
key string - company api key ✓
update_existing boolean
validate_only boolean

Example Input

Multi Part Form Data

{"categories":[{
"external_id":"ss304",
"name":"exampleCategory"
}]}

JSON As Body

{
   "key":"darrenwebapi",
   "validate_only":"false",
   "update_existing":true,
   "categories":[
      {
         "external_id":"ss304",
         "name":"exampleCategory"
      }
   ]
}


Example Curl Requests

Multi Part Form Data

curl -F validate_only=false -F update_existing=true -F api_key=darrenwebapi -F file=@/Users/darrenatherton/Desktop/webAPICurling/create_category.txt http://live.mymobileworkers.com:8080/api/1/categories

JSON As Body

curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":true,"categories":[{"external_id":"ss304","name":"exampleCategory"}]}' http://live.mymobileworkers.com:8080/api/1/categories

Responses

Example JSON

{
	"successful":
	[
		{"name":"testCategory1"},
		{"name":"testCategory2"}
	],
	"failed":
	[
		{
			"item_name":"testCategory3",
			"errors": 
			[
				{
					"error_code":"CVA012",
					"error_msg":"name cannot be null."
				}
			]
		}
	]
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox