Search code examples
copyleaks-api

Why am I getting a "conflict" HTTP 409 response from CopyLeaks on export API calls?


I'm getting an HTTP 409 "Conflict" response while handling CopyLeaks' "Completion" webhook when sending my export request. I'm getting it every time I submit a test scan today, but I wasn't getting it a couple days ago when I last tested the code. I'm getting it for each new scan. The response has no body and no more information. Any idea what would cause this and how to resolve?

Here's some debugging info: Scan API request body:

{
    "base64": "IjEuIElzIGl0IG9rIHRvIGhhdmUgYSBkYXJrIHJvb20gZHVyaW5nIHRoZSBleGFtPw0KDQoobWluaW11bSBvbmUgcGFyYWdyYXBoIHJlc3BvbnNlIC0gIDUgc2VudGVuY2VzKSI6Ck9rIEknbSBnb2luZyB0byBzdGFydCB3cml0aW5nIG91dCBteSBhbnN3ZXJzLi4uIGxhbGFsYWxhbGFsYWxhLiBNWSBBTlNXRVJTIEFSRSBTVElMTCBIRVJFISBJIExPVkUgUEFDUklNCgoiMS4gYikgV2hlcmUgaXMgdGhlIG1vc3QgaW1wb3J0YW50IHBsYWNlIHRvIHNob3cgaW4gdGhlIHJvb20gc2Nhbj8NCihtaW5pbXVtIG9uZSBwYXJhZ3JhcGggcmVzcG9uc2UgLSAgNSBzZW50ZW5jZXMpIjoKU28gZmFzdC4gTm90aGluZyBpcyBzYXZlZCB5ZXQsIGl0IG9ubHkgZ2V0cyBzYXZlZCBldmVyeSBtaW51dGUuIEl0IGNvdWxkIGJlIGxvbmdlciwgaWYgeW91IHdhbnQuIE9yIHNob3J0ZXIuIEFsbGxsbGxsbCBnb29kLiBKdXN0IHdhdGNoIHRoZSByaWdodC1oYW5kIGNvcm5lciBvZiB0aGUgc2NyZWVuLiBNYWdpYyB3aWxsIGhhcHBlbi4KCiIyLiBJcyBpdCBvayB0byByZWFkIGZyb20geW91ciBwaG9uZSBkdXJpbmcgdGhlIGV4YW0/IA0KKG1pbmltdW0gMSBzZW50ZW5jZSBhbnN3ZXIuKSI6ClNvIG1hZ2ljLiB3YWl0IGZvciBpdC4gT2sgSSdsbCBmaW5pc2ggdXAuIFdhaXQgZm9yIHRoZSBhdXRvc2F2ZSBhZ2FpbiwganVzdCB0byBzaG93IGl0cyBzdGlsbCB3b3JraW5nLi4uLiBldmVudHVhbGx5Li4uIEkgdGhpbmsgaW4gYSBmZXcgc2Vjb25kcy4uLiBtYXliZS4uLi4NCkkgc3VwcG9zZSB5b3UgY2FuIGZhc3QgZm9yd2FyZCB0aGlzIGlmIHlvdSB3YW50LiBOb3QgbWUuIEknbSBzdHVjayBpbiBodW1hbiB0aW1lLiBPSCENCk9rIG5vdyBJJ2xsIHN1Ym1pdC4KCg==",
    "filename": "087.txt",
    "properties": {
        "developerPayload": "Submitted by Mike",
        "exclude": {
            "quotes": true,
            "titles": true
        },
        "sandbox": true,
        "webhooks": {
            "status": "https://dev.earlychildhoodeducator.com/copyleaks/webhook/completed/087"
        }
    }
}

Completed webhook received body:

{"scannedDocument":{"scanId":"087","totalWords":158,"totalExcluded":56,"credits":0,"expectedCredits":1,"creationTime":"2021-07-21T03:48:41.013271Z","metadata":{"filename":"uploaded.txt"}},"results":{"score":{"identicalWords":1,"minorChangedWords":0,"relatedMeaningWords":0,"aggregatedScore":1.0},"internet":[{"url":"http://example.com/","id":"2a1b402420","title":"Example Domain","introduction":"Example Domain This domain is for use in illustrative examples in documents. You may use this domain in literature without ...","matchedWords":1,"metadata":{"finalUrl":"http://example.com/","filename":"source"}}],"database":[],"batch":[],"repositories":[]},"notifications":{"alerts":[]},"status":0,"developerPayload":"Submitted by Mike"}

Export API body:

{
    "completionWebhook": "https://dev.earlychildhoodeducator.com/copyleaks/webhook/exported/87",
    "crawledVersion": {
        "endpoint": "https://dev.earlychildhoodeducator.com/copyleaks/webhook/crawled/87",
        "headers": [
            [
                "HTTP_PRECI",
                "PRECI uOaDeRrRVhRPhQhJgHNK"
            ]
        ],
        "verb": "POST"
    },
    "results": [
        {
            "endpoint": "https://dev.earlychildhoodeducator.com/copyleaks/webhook/result/87/2a1b402420",
            "headers": [
                [
                    "HTTP_PRECI",
                    "PRECI uOaDeRrRVhRPhQhJgHNK"
                ]
            ],
            "id": "2a1b402420",
            "verb": "POST"
        }
    ]
}

Export API response:

status: "Conflict"

Headers:

{'Date': 'Wed, 21 Jul 2021 03:49:26 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=2592000; includeSubDomains', 'CF-Cache-Status': 'DYNAMIC', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Report-To': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=WFnYOPnNkcR4D%2F1%2BCbmHopFZw9ZtYMtUAVjA8Vx3c8OLYZakWpL76ysOKJ03Yd%2Fo6eNUaO35T%2B0k2lZxaUB9g6VYnmur9JrAnhL0G6%2FeceKE%2BTXCJBeMdEQDgGnEOrHRvTON"}],"group":"cf-nel","max_age":604800}', 'NEL': '{"report_to":"cf-nel","max_age":604800}

and no response body.


Solution

  • Each Export task has their unique task id. Once you create a job with the requested id, you cannot create another export job with the same id.

    Having said that, if you are getting error 409, I assuming that you are trying to Export multiple tasks with the same job id.

    In order to submit a unique export Id, you have to change the URI to this form:

    https://api.copyleaks.com/v3/downloads/scanId/export/UNIQUE_JOB_ID
    

    and having a UNIQUE_JOB_ID each new export job you create.