通过CSV上传到api时,Salesforce的BULK API2.0不会更新记录

时间:2019-05-29 03:30:03

标签: php salesforce

我是Salesforce的新手。我试图将批量api 2.0集成到我们的内部php应用程序之一。我能够将csv文件上传到Salesforce并进行处理。但是它每次返回更新为0的记录。调试日志中没有故障或没有故障。有人可以告诉我我在做什么错吗?

我尝试调用api,将csv中的相同数据作为字符串传递,并且更新成功。只有当我上传csv本身时才有问题。

这是我的代码:

//code for creating the job id

$url = "$instance_url/services/data/v42.0/jobs/ingest";
    $content = json_encode(array("object" => 'Account', "externalIdFieldName" => "Id","contentType"=>'CSV',"operation" => 'update',"lineEnding" => "LF"));

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_HTTPHEADER,
            array("Authorization: OAuth $access_token",
                    "Content-type: application/json; charset=UTF-8",
                    "Accept: text/csv"
            ));
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");

            curl_setopt($curl, CURLOPT_POSTFIELDS, $content);           
            $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);


//code for uploading the csv for bulk update

     $url = "$instance_url/services/data/v42.0/jobs/ingest/7509D0000008eSuQAI/batches";

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_HTTPHEADER,
            array("Authorization: OAuth $access_token",
                    "Content-type: text/csv",
                    "Accept: application/json"

            ));

    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");

    $file = "test-3.csv";

curl_setopt($curl, CURLOPT_POSTFIELDS, $file);
    curl_exec($curl);

    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

1 个答案:

答案 0 :(得分:0)

好像您没有完成任务,SF认为您可能希望上传更多文件。通过此自学课程:https://trailhead.salesforce.com/en/content/learn/modules/api_basics/api_basics_bulk,尤其要检查state字段的更新吗?