Sample upload API reference
This document describes how to use the API to upload blacklist and whitelist samples to Fraud Detection. This process enables the centralized management and maintenance of your samples.
1. Before you begin
Create a Resource Access Management (RAM) user for your Alibaba Cloud account and use its AccessKey ID and AccessKey secret to call the API. This practice simplifies future management.
Log on to the RAM console.
Identity Management > Users > Create User
Click the username and create an AccessKey ID.
Add permissions. Search for AliyunYundunSAFFullAccess and add it to the user.
2. Integrate using a server-side SDK
Use the Alibaba Cloud Fraud Detection software development kit (SDK) to call the Fraud Detection service. The SDK handles complex tasks such as signature validation and body format construction. SDKs are available for Java, Python, PHP, C#, Go, Node.js, and Ruby.
Java Maven dependency:
<dependencies>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>safconsole20210112</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>Code example:
public class ApiTest {
public static void main(String[] a) throws Exception {
/**
* An AccessKey for an Alibaba Cloud account has full permissions for all APIs. Use a RAM user for API access or daily O&M.
* Do not hard-code your AccessKey ID and AccessKey secret into your project code. Hard-coding your credentials can lead to security risks.
* This example reads the AccessKey of a RAM user from environment variables to authenticate API access. Before you run this code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
*/
// The AccessKey ID of the RAM user.
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
// The AccessKey secret of the RAM user.
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Your AccessKey ID.
.setAccessKeyId(accessKeyId)
// Required. Your AccessKey secret.
.setAccessKeySecret(accessKeySecret);
config.endpoint = "safconsole.cn-shanghai.aliyuncs.com";
com.aliyun.safconsole20210112.Client client = new Client(config);
// Generate the access code. For information about the fields, see the parameter descriptions.
String dataType = "ip";
String dataValue = "[\"123.xxx.xxx.xxx\",\"123.xxx.xxx.xxx\"]";
String sampleType = "block";
String service = "account_abuse,coupon_abuse,account_takeover";
UploadSampleApiRequest request = new UploadSampleApiRequest();
request.setDataType(dataType);
request.setDataValue(dataValue);
request.setSampleType(sampleType);
request.setService(service);
UploadSampleApiResponse response = client.uploadSampleApi(request);
System.out.println("httpResponse:" + JSONObject.toJSONString(response));
// If the access fails, check the connection to the POP gateway.
if (response.statusCode != 200) {
// Error handling.
System.out.println("Gateway error");
return;
}
// Backend request error. Handle the error as described in the API reference.
if (!"200".equals(response.body.code) || !"true".equals(response.body.success)) {
System.out.println("Backend request error. Handle the error as described in the API reference.");
System.out.println(response.body.message);
return;
}
// Request successful.
System.out.println("Request successful");
return;
}
}3. Parameter descriptions
3.1 Request parameters
Parameter Name | Location | Type | Required | Description | Example |
SampleType | query | string | Yes | The type of the sample.
| block |
DataType | query | string | Yes | The data type of the sample.
| ip |
Service | query | string | Yes | A list of services where the sample takes effect. Separate multiple services with commas.
| account_abuse,coupon_abuse,account_takeover |
DataValue | query | string | Yes | The specific values of the samples, passed in JSON format. Do not exceed 1,000 entries per request. | ["123.xxx.xxx.xxx","123.xxx.xxx.xxx"] |
3.2 Response parameters
Parameter Name | Location | Type | Description | Value on success |
statusCode | response | int | The status of the gateway access. | 200 |
code | response.body | string | The code returned by the backend. | 200 |
success | response.body | string | Indicates whether the request was successful. | true |
msg | response.body | string | The error message. | Not returned on success. |
3.3 Return codes
For each API call, Alibaba Cloud returns common parameters regardless of whether the call is successful. The code parameter indicates the request status.
Error code | Error message | Description |
1101 | system error | System error. Contact Alibaba Cloud for troubleshooting. |
1002 | userId is not null | Cannot obtain a valid user ID. Check your AccessKey. |
Service parse to string list failed | Failed to parse the Service parameter. Check if the service format is correct. | |
Service not in enum list | The service is not in the enumeration list. Check if the service value is valid. | |
SampleType is not null | The SampleType parameter is empty. Check the value of SampleType. | |
SampleType not in enum list | The SampleType is not in the enumeration list. Check if the SampleType value is valid. | |
DataType is not null | The DataType parameter is empty. Check the value of DataType. | |
DataType not in enum list | The DataType is not in the enumeration list. Check if the DataType value is valid. | |
DataValue is not json string | The DataValue is not in JSON string format. Check the DataValue. | |
DataValue is empty | The DataValue is empty. Check the number of entries in DataValue. | |
DataValue size larger than 1000 | The number of entries in DataValue exceeds 1,000. Check the number of entries. |
Note: The number of queries per second (QPS) for the API cannot exceed 50.