my.networkRequest
Specification
The following table is a specification of this JSAPI:
JSAPI Name |
|
Description | This JSAPI serves as bridge, allowing merchants to call any APIs within the Mini Program solution |
Request
The following part describe about parameter of request in this JSAPI:
Request Parameter
The following table is a request parameter in this JSAPI:
Name | Type | Required | Condition | Remarks |
url | String | Mandatory | - | URL of requested API, with the format: |
headers | Object | Optional | - | Request headers, value always:
|
method | String | Optional | - | Method of requested API. The possible values are:
With the default value is |
data | Object | Optional | - | Request data for the API call. The value depends on the specific API being used |
timeout | Number | Optional | - | Timeout of requested API. The default values is |
dataType | String | Optional | - | The possible data types that can be returned in the response are:
|
Request Sample
The following part will be described samples of request in this JSAPI:
my.call('networkRequest', {
url: "https://xxxx", // Mandatory
headers: {'content-type': 'application/json'}
method: "POST",
data: {'data1': 'data1', 'data2': 'data2'}
timeout: 30000,
dataType: "JSON",
}, function(result) {
console.log(result);
})Response
The following part describe about parameter of response in this JSAPI:
Response Parameter
The following table is a response parameter in this JSAPI:
Name | Type | Required | Condition | Remarks |
success | Boolean | Mandatory | - | Callback function upon call success
|
data | Object | Optional | - | Returns the response data from the requested API |
httpStatus | Number | Conditional | Y:= Successfully called network/API | HTTP status code |
errorCode | Number | Conditional | Y:= success is | Refer to error code list |
errorMessage | String | Conditional | Y:= success is | Refer to error message list |
Response Sample
The following part will be described samples of response in this JSAPI.
Success
The following script is a response sample of this JSAPI for success scenario:
{
"success": true,
"data": {
"id": "merchant id" // success response from API
},
"httpStatus": 200
}Failed
The following script is a response sample of this JSAPI for failed scenario:
{
"success": false,
"data": {
"error": "error" // error response from API
},
"httpStatus": 400,
"errorCode": "J003",
"errorMessage": "Network error"
}Error Code Information
The following table shows the error codes and messages used in this JSAPI:
No. | Error Code | Error Message | Merchant Action |
1. | J001 | Incorrect parameter. Check whether the URL is in HTTPS format and all parameters are correct | Mark my.networkRequest JSAPI parameter success as |
2. | J002 | Access denied to the interface. This error may be caused by a non-whitelisted URL or server domain. Please Contact DANA team | Mark my.networkRequest JSAPI parameter success as |
3. | J003 | Network Error | Mark my.networkRequest JSAPI parameter success as |
4. | J004 | Timeout | Mark my.networkRequest JSAPI parameter success as |
5. | J005 | Decoding Failure | Mark my.networkRequest JSAPI parameter success as |
6. | J006 | HTTP error | Mark my.networkRequest JSAPI parameter success as |
7. | J007 | Request stopped/service end traffic limit. | Mark my.networkRequest JSAPI parameter success as |
Notes:
The error code of J005 might be returned in the following cases:
- When the value of dataType is JSON, the Mini Program framework firstly perform the JSON.parse operation on the returned results. If the parsing fails, the error code of
J005is returned. - When the value of dataType is
textand the returned content has a bad format, the error code ofJ005is returned.
To solve the error, check whether the dataType setting is incorrect firstly.
