# Bulk\_create\_or\_update\_verbose returns "Unexpected error saving document." everytime

**URL:** <https://community.swiftype.com/t/bulk-create-or-update-verbose-returns-unexpected-error-saving-document-everytime/598>\
**Category:** Setup & Indexing\
**Tags:** api\
**Created:** [February 26, 2018, 12:34pm UTC](https://community.swiftype.com/t/bulk-create-or-update-verbose-returns-unexpected-error-saving-document-everytime/598 "2018-02-26T12:34:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@tim1](https://community.swiftype.com/u/tim1)\
**Post date:** [February 26, 2018, 12:34pm UTC](https://community.swiftype.com/t/bulk-create-or-update-verbose-returns-unexpected-error-saving-document-everytime/598/1 "2018-02-26T12:34:29Z")

</div>

We are using the API to add documents and when I use the end point **document\_types/products/documents.json** we manage to get success. However anytime I try to use **document\_types/pages/documents/bulk\_create\_or\_update\_verbose** I have not got anything other than the error given below:

> Unexpected error saving document. Contact [support@swiftype.com](mailto:support@swiftype.com) if the problem persists

I have contacted but we haven’t got anywhere (I would have thought there would a log of which could be looked at). All I have had come back was to use json\_encode() which was already being used (see the first option in the switch statement). Just to clarify, the request works fine for all calls other than this one, the data is formatted as per the documentation so I can’t see any reason why that would cause it. Has anyone else had this issue?

public function addPageDocument()  
{

```
$data = ["documents" =>
    [
        "external_id" => "1346",
        "fields" => [
            [
                "name" => "title",
                "value" => "Sample page",
                "type" => "string"
            ],[
                "name" => "url",
                "value" => "https://www.thespicery.com",
                "type" => "string"
            ]
        ]
    ]
];

return $this->curlWrap("document_types/pages/documents/bulk_create_or_update_verbose", $data, "POST");

```

}

```
  public function curlWrap($endPoint, $data, $action)
    {

        try {
            $credentials = $this->getSwiftypeCredentials();
            $endPoint = "https://api.swiftype.com/api/v1/engines/{$credentials["engine_slug"]}/{$endPoint}";

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, $endPoint);

            curl_setopt($ch, CURLOPT_USERPWD, $credentials["auth_token"]);
            curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
// See the JSON encode below
                    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
                    curl_setopt($ch, CURLOPT_POST, 1);

            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
            curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 10);
            $output = curl_exec($ch);

            if ($output == false) {
                throw new \Exception(curl_error($ch), curl_errno($ch));
            }
            curl_close($ch);
            $decoded = json_decode($output);

            return $decoded;
        } catch (\Exception $e) {
            $this->auditHelper->addLogToRollbar(
                \Rollbar\Payload\Level::ERROR,
                "Swiftype Curl Failed {$e->getCode()} {$e->getMessage()}");

            return false;
        }
    }

```
