APP365提供的Open API是典型的RESTful API,讓你能非常容易地將自己的應用與APP365進行集成; 你可以在應用程序中按照自己的需要查詢或修改運單、車輛、車次、客戶、司機、出入庫信息、運輸過程信息、跟蹤信息、財務信息等; APP365 Open API采用JSON作為請求和響應的數據格式。
在你考慮自己創建與APP365集成的模塊時,請先檢查“插件工具”欄目中是否已經提供了相同的模塊,以免重復勞動。
當前的APP365 Open API 僅支持HTTP Basic access authentication認證方式;API調用連接必須通過安全的HTTPS連接;證書信息由一個有效的用戶名和其關聯的API Key組成; 請參見下節的“啟用 APP365 Open API”,以了解怎樣獲取一個API Key;在調用時,如果證書無效或者沒有提供,服務器會返回“401未經授權”的響應。
要授權一個用戶讓其可以調用API,請按照下列步驟操作:
在角色模塊中,配置指定角色能夠存取的資源和可以執行的動作,讓特定的角色只能訪問與自己相關的資源和動作,保證系統數據的安全。 在調用API時,采用同樣地策略來控制用戶的訪問權限,如果用戶無權訪問指定的資源,則會返回響應 “403 Forbidden”。
要調用APP365 API,你需要在執行請求時,設置Basic HTTP Authorization頭部:username:api_key.
如果使用cURL工具,你可以采用下面兩種方式之一請求登錄授權:
通過"--user"參數構造登錄授權的頭部curl --user apiUsername:api_key
通過"--header"參數直接設置登錄授權的頭部curl --header "Authorization: Basic YWRtaW46WW91ckFQSUtleUhlcmU="
APP365 Open API采用JSON作為請求和響應的數據格式,API分為三種類型,查詢數據、保存數據、刪除數據:
查詢數據
查找單條記錄URL:http://biz.app365.com/bizweb/services/bizobjects
/m56.Barcode /* 實體模型id */ /{id}?fields=station_name,barcodes /* 記錄id及其要查詢返回的字段列表*/查詢列表URL: http://biz.app365.com/bizweb/services/query
/ilms.LmsOrder.selectForList /* 要執行的SqlId */ /"o.name": 'lgh', "o.code": 'fff'/0,100 /* 查詢條件參數,查詢記錄的offset limit*/完整的請求舉例:
curl --request GET \ --header "Authorization: Basic YWRtaW46WW91ckFQSUtleUhlcmU=" \ http://biz.app365.com/bizweb/services/bizobjects/m56.Barcode/{id}?fields=station_name,barcodes curl --request GET \ --header "Authorization: Basic YWRtaW46WW91ckFQSUtleUhlcmU=" \ http://biz.app365.com/bizweb/services/query/ilms.LmsOrder.selectForList/ \ "o.name": 'lgh', "o.code": 'fff'/0,100保存數據
保存整個對象的URL: http://biz.app365.com/bizweb/services/bizobjects/m56.Barcode/,同時post一個json對象
更新幾個字段的URL:http://biz.app365.com/bizweb/services/bizobjects/m56.Barcode/{id},同時post一個json對象
完整的請求舉例:
curl http://biz.app365.com/bizweb/services/bizobjects/m56.Barcode/ -H "Content-Type: application/json" -d @barcode.json -H "Authorization: Basic YWRtaW46WW91ckFQSUtleUhlcmU="APP365 API根據請求的結果,返回相應的HTTP狀態代碼。根據HTTP的規定,響應按照下列狀態碼性質被分成幾大類。出錯的響應中也同時包含了一個錯誤消息在響應的body中,你可以根據這個消息判斷和解決問題。
Code | Definition | Purpose |
---|---|---|
200 | OK | For successful GET/PUT requests. |
201 | Created | For a successful POST request. |
202 | Accepted | For a request that resulted in a scheduled task being created to perform the actual request. |
204 |
No Content |
For a successful request that produced no response (such as DELETE requests). |
Code | Definition | Purpose |
---|---|---|
301 | Moved Permanently | When the API routes have changed (unlikely) or if the incoming request is not secure (http) then it will be redirect to the secure (https) version. |
302 |
Found |
When the resource was found at a different location. When a request to a deprecated version of the API is received, a 302 Found response will be issued to the current API version. |
304 |
Not Modified |
If an If-Modified-Since header is sent in the request and the resource has not been modified since the specified date, then this response will be sent. NB. See resource specific pages for support for the If-Modified-Since header. |
Code | Definition | Purpose |
---|---|---|
400 |
Bad Request |
Issued when a malformed request was sent. Such as due to invalid syntax or missing required data. |
401 |
Unauthorized |
This response is sent when either the clients credentials are not provided or are incorrect. |
403 |
Forbidden |
When the user doesn't have permission to perform a specific operation on a resource (eg. edit a product). Permissions can be set through the store control panel. |
404 | Not Found | When a particular resource doesn't exist or couldn't be found. |
405 |
Method Not Allowed |
The resource was found, but doesn't support the request method. Issued when either a specific method isn't yet implemented on a resource, or the resource doesn't support the method at all (eg. PUT on /orders is invalid, but PUT on /orders/{id} is valid). |
406 |
Not Acceptable |
When the client specifies a response content type in the Accept header that is not supported. |
409 | Conflict | A change requested by the client is being rejected due to a condition imposed by the server. The exact reasons response for this will vary from one resource to the next. Examples may include attempting to delete a Category which would result in Products being orphaned. Additional information about the conflict and how to resolve it may be available in the details section of the response. |
413 |
Request Entity Too Large |
When the client requests too many objects. eg. the limit parameter was above the maximum allowed. |
415 |
Unsupported Media Type |
When the client specifies a content type in the Content-Type header that is not supported by the API. |
Code | Definition | Purpose |
---|---|---|
500 | Internal Server Error | When an error has occurred within the API. |
501 | Not Implemented | When a request method is sent that is not supported by the API (eg. TRACE, PATCH). |
503 |
Service Unavailable |
When the store is marked as "Down for Maintenance" or the store is being upgraded to a new version. |
507 |
Insufficient Storage |
When the store has reached a limitation for the resource according to their BigCommerce plan (eg 500 product limit). |
509 |
Bandwidth Limit Exceeded |
When the requests-per-hour limitations for the API have been reached. |