Difference between revisions of "Create Assets"

From MyMobileWorkers API
Jump to: navigation, search
(→‎JSON As Body)
Line 9: Line 9:
  
 
If 'validate_only' is set, the assets will only be validated but not actually inserted into the database. This can be used to check an entire dataset for errors before submitting.
 
If 'validate_only' is set, the assets 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 ====
 
−
{| border="1" class="wikitable"
 
−
 
−
! Create Asset
 
−
! colspan="2" |
 
−
|-
 
−
!  URL
 
−
| colspan="2" | https://base_url/api_path/version/assets
 
−
|-
 
−
! Type
 
−
| colspan="2" |POST
 
−
|-
 
−
! Params:
 
−
| api_key || required
 
−
|-
 
−
!
 
−
| file || required
 
−
|-
 
−
!
 
−
| update_existing || optional (default = false)
 
−
|-
 
−
!
 
−
| validate_only || optional (default = false)
 
−
|-
 
−
! Response
 
−
| colspan="2" | JSON
 
−
|}
 
  
 
==== JSON As Body ====
 
==== JSON As Body ====
 
{| border="1" class="wikitable"
 
{| border="1" class="wikitable"
−
! Create Job - JSON
+
! Create Job Tracking Reference - JSON
 
! colspan="2" |  
 
! colspan="2" |  
 
|-
 
|-
 
!  URL
 
!  URL
−
| colspan="2" | https://base_url/api_path/version/assets
+
| colspan="2" | https://base_url/api_path/version/jobs/trackingref/update
 
|-
 
|-
 
! Type
 
! Type
Line 50: Line 22:
 
|-
 
|-
 
!  
 
!  
−
| JSON <br /> {key, validate_only(optional), update_existing(optional), assets[]}  ||| required     
+
| JSON <br /> {key, validate_only(optional), update_existing(optional), jobs_trackingrefs[]}  ||| required     
 
|-
 
|-
 
! Response
 
! Response
Line 66: Line 38:
 
! Required
 
! Required
 
|-
 
|-
−
! external_id
+
! jobId
−
| varchar(45) ||
+
| {"job_number":"<job_number>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| &#10003;
−
|-
+
−
! item_id
+
−
| {"name":"<itemName>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| &#10003;
+
−
|-
+
−
! serial_number
+
−
| varchar(45) <br /><span style="font-size:80%; font-weight:normal">* must be unique</span>|| &#10003;
+
−
|-
+
−
! description
+
−
| varchar(255) ||
+
−
|- 
+
−
! location
+
−
| varchar(45) ||
+
−
|-
+
−
! job_id
+
−
| {"job_number":"<jobNumber>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>||
+
−
|-
+
−
! customer_id
+
−
| {"name":"<customerName>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>||
+
−
|-
+
−
! status_id
+
−
| {"status":"<statusName>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| &#10003;
+
−
|-
+
−
! branch_id
+
−
| {"name":"<branchName>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>||
+
−
|-
+
−
! custom_fields
+
−
| JSON ||
+
 
|-  
 
|-  
 
|}
 
|}
Line 118: Line 63:
  
 
== Example Input ==
 
== Example Input ==
−
 
−
==== Multi Part Form Data ====
 
−
 
−
<source lang="java">
 
−
{
 
−
  "assets":[
 
−
      {
 
−
        "external_id":"sss32",
 
−
        "item_id":{
 
−
            "name":"Woo"
 
−
        },
 
−
        "serial_number":"serialNo456",
 
−
        "description":"describingwords",
 
−
        "location":"aPlace2",
 
−
        "job_id":{
 
−
            "job_number":"123"
 
−
        },
 
−
        "customer_id":{
 
−
            "name":"john"
 
−
        },
 
−
        "status_id":{
 
−
            "status":"test"
 
−
        },
 
−
        "branch_id":{
 
−
            "name":"DarrenDevTest"
 
−
        },
 
−
        "custom_fields":{
 
−
"testFieldName1":"testFieldValue1",
 
−
"testFieldName2":"testFieldValue2",
 
−
"testFieldName3":"testFieldValue3"
 
−
}
 
−
      }
 
−
  ]
 
−
}
 
−
</source>
 
−
 
  
 
==== JSON As Body ====
 
==== JSON As Body ====
Line 159: Line 68:
 
<source lang="java">
 
<source lang="java">
 
{
 
{
−
   "key":"darrenwebapi",
+
   "key":"api_key",
−
  "validate_only":"false",
+
 
   "update_existing":"true",
 
   "update_existing":"true",
−
   "assets":[
+
   "validate_only":"false",
 +
  "jobs_trackingrefs":[
 
       {
 
       {
−
         "external_id":"sss32",
+
         "jobId" : {
−
        "item_id":{
+
        "job_number":"test_number"
−
            "name":"Woo"
+
−
        },
+
−
        "serial_number":"serialNo456",
+
−
        "description":"describingwords",
+
−
        "location":"aPlace2",
+
−
        "job_id":{
+
−
            "job_number":"123"
+
−
        },
+
−
        "customer_id":{
+
−
            "name":"john"
+
−
        },
+
−
        "status_id":{
+
−
            "status":"test"
+
−
        },
+
−
        "branch_id":{
+
−
            "name":"DarrenDevTest"
+
−
        },
+
−
        "custom_fields":{
+
−
            "testFieldName1":"testFieldValue1",
+
−
            "testFieldName2":"testFieldValue2",
+
−
            "testFieldName3":"testFieldValue3"
+
 
         }
 
         }
 
       }
 
       }
Line 194: Line 82:
  
 
== Example Curl Requests ==
 
== Example Curl Requests ==
−
 
−
==== Multi Part Form Data ====
 
−
 
−
curl -F validate_only=false -F update_existing=true -F api_key=darren_web_api -F file=@/Users/user/Desktop/webAPICurling/create_asset.txt  https://api.mymobileworkers.com:8181/api/1/assets
 
  
 
==== JSON As Body ====
 
==== JSON As Body ====
  
−
curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi", "validate_only":"false", "update_existing":"true", "assets":[{"external_id":"sss32","item_id":{"name":"Woo"},"serial_number":"serialNo456","description":"describingwords","location":"aPlace2","job_id":{"job_number":"123"},"customer_id":{"name":"john"},"status_id":{"status":"test"},"branch_id":{"name":"DarrenDevTest"},"custom_fields":{"testFieldName1":"testFieldValue1","testFieldName2":"testFieldValue2","testFieldName3":"testFieldValue3"}}]}' http://api.mymobileworkers.com:8080/api/1/assets
+
curl -X POST -H "Content-Type: application/json" -d '{
 +
  "key":"api_key",
 +
      "update_existing":"true",
 +
      "validate_only":"false",
 +
      "jobs_trackingrefs":[
 +
        {
 +
            "jobId" : {
 +
            "job_number":"test_number"
 +
            }
 +
        }
 +
      ]
 +
}' https://api.mymobileworkers.com:8181/api/1/jobs/trackingref/update
  
 
== Responses ==
 
== Responses ==
Line 209: Line 104:
 
<source lang="java">
 
<source lang="java">
 
{
 
{
−
"successful":
+
    "failed": [],
−
[
+
    "successful": [
−
{"serial_number":"S0103"},
+
        {
−
{"serial_number":"S0245"}
+
            "job_number": "test_number",
−
],
+
            "tracking_ref": "test_tracking_ref"
−
"failed":
+
        }
−
[
+
    ]
−
{
+
−
"serial_number":"S0384",
+
−
"errors":  
+
−
[
+
−
{
+
−
"error_code":"ASV012",
+
−
"error_msg":"Status id cannot be null."
+
−
}
+
−
]
+
−
}
+
−
]
+
 
}
 
}
 
</source>
 
</source>

Revision as of 16:40, 5 April 2020

Contents

Summary

An asset 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.

The 'create asset' method accepts an array of assets to be added to the system. If the 'update_existing' parameter is set, then any existing assets will be updated in the system. If set to false or not provided, then any asset where the serial number is not unique will be rejected.

When an asset is created or updated, a new asset history entry is also created in the system to keep track of the asset over time.

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

JSON As Body

Create Job Tracking Reference - JSON
URL https://base_url/api_path/version/jobs/trackingref/update
Type POST
JSON
{key, validate_only(optional), update_existing(optional), jobs_trackingrefs[]}
required
Response JSON

JSON Contents

The JSON file is passed in the post as the "file"
Standard Fields
Field Expected Data Required
jobId {"job_number":"<job_number>"}
*nested JSON object
✓
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

JSON As Body

{
   "key":"api_key",
   "update_existing":"true",
   "validate_only":"false",
   "jobs_trackingrefs":[
      {
         "jobId" : {
         	"job_number":"test_number"
         }
      }
   ]
}

Example Curl Requests

JSON As Body

curl -X POST -H "Content-Type: application/json" -d '{

  "key":"api_key",
     "update_existing":"true",
     "validate_only":"false",
     "jobs_trackingrefs":[
        {
           "jobId" : {
           	"job_number":"test_number"
           }
        }
     ]

}' https://api.mymobileworkers.com:8181/api/1/jobs/trackingref/update

Responses

Example JSON

{
    "failed": [],
    "successful": [
        {
            "job_number": "test_number",
            "tracking_ref": "test_tracking_ref"
        }
    ]
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox