You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用SureDone API返回Identifier is invalid错误排查求助

Fixing "Identifier is invalid" Error in SureDone API Call

First, let's look at the error you're encountering:

{ "result":"failure", "message":"Identifier is invalid", "time":"2018-05-25 15:34:13", "type":"items" } CompletedOK

This error usually boils down to two core issues: either the API can't properly parse your identifier parameters due to formatting mistakes, or the value you're using for the identifier doesn't match SureDone's expected format or type. Let's break down the problems in your code and fix them step by step.

Key Issues in Your Current Code

1. Manual Multipart Form-Data Construction is Broken

You're manually building the multipart payload with an undefined boundary, and your formatting has extra newlines (\r\n\r\n instead of \r\n after each field value). This messes up the structure of your request, making the API unable to correctly read your identifier and guid parameters—this is almost certainly the main cause of the error.

2. Potential Mismatch Between Identifier Type and Value

You set identifier="guid" but pass your SKU as the guid value. If SureDone expects guid to be a valid UUID (like 123e4567-e89b-12d3-a456-426614174000) and your SKU doesn't follow that format, this will also trigger the "Identifier is invalid" error.

Corrected Code Implementation

Here's a revised version of your code that uses RestSharp's built-in tools to handle multipart form-data correctly, eliminating formatting errors:

private void btnLoad_Click(object sender, EventArgs e)
{
    string PathConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtChooseFile.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
    OleDbConnection conn = new OleDbConnection(PathConn);
    OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + txtLoad.Text + "$]", conn);
    DataTable dt = new DataTable();
    da.Fill(dt);
    dataGridView.DataSource = dt;

    // REST request setup
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    var client = new RestClient("https://api.suredone.com/v1/editor/items/add");
    var request = new RestRequest(Method.POST);

    // Auth headers
    request.AddHeader("x-auth-token", "{token}");
    request.AddHeader("x-auth-user", "{username}");

    // Loop through rows and add form-data parameters (RestSharp handles multipart automatically)
    foreach(DataRow row in dt.Rows)
    {
        // Important: Verify if "guid" is the correct identifier type for your use case
        // If your SKU isn't a UUID, change identifier to "sku" (check SureDone API docs for valid types)
        request.AddParameter("identifier", "guid");
        request.AddParameter("guid", row["sku"].ToString());
        request.AddParameter("price", row["price"].ToString());
        request.AddParameter("title", row["title"].ToString());
        request.AddParameter("action", row["action"].ToString());
        request.AddParameter("stock", row["stock"].ToString());
        request.AddParameter("msrp", row["msrp"].ToString());
        request.AddParameter("longDescription", row["longdescription"].ToString());
        request.AddParameter("condition", row["condition"].ToString());
        request.AddParameter("brand", row["brand"].ToString());
        request.AddParameter("notes", row["notes"].ToString());
    }

    // Execute request and get response
    IRestResponse response = client.Execute(request);
    txtResponse.Text = $"{response.Content}\n{response.ErrorMessage}\n{response.ResponseStatus}\n{response.StatusCode}";
}

Critical Fixes Explained

  • Removed manual payload building: RestSharp automatically handles multipart form-data formatting, including generating a valid boundary and correct line endings. This ensures the API can parse all your parameters properly.
  • Simplified parameter addition: Using request.AddParameter for each field is cleaner and far less error-prone than manual string concatenation.
  • Identifier type check: Double-check SureDone's API documentation to confirm if guid is the right identifier type for your scenario. If you're using SKUs that aren't UUIDs, switch to identifier="sku" instead (assuming SureDone supports this type).

Additional Troubleshooting Steps

  1. Validate identifier value: If you stick with guid as the identifier type, confirm that your SKU values are valid UUIDs. If not, generate proper UUIDs for your items or switch to a compatible identifier type.
  2. Test with a single item: To isolate the issue, send a request with just one item first. This helps you confirm if the problem is with a specific row in your Excel file or the overall request format.
  3. Check API documentation: Refer to SureDone's official API docs for the /editor/items/add endpoint to verify required parameters, valid identifier types, and expected formats.

内容的提问来源于stack exchange,提问作者Steph

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:53:21