rwfitzy rwfitzy - 1 month ago 5x
PHP Question

File not found with CURL POST not GET

I've done some API calls in my day, but having a problem with a new setup with Adobe Sign. I can do GET requests fine, but get HTTP 404 when trying any POST or PUT to their server. For instance, go here....

Minimum call results in Access token not found, of course, if you misspell that URL, you'll see code NOT FOUND, which is what I get when doing either a POST or PUT with CURL on PHP 7. Not sure if there is a permissions issue, I've followed their docs to get my tokens and use those same tokens for GET requests that work fine. I've gone over the perms and asked Adobe if they could see anything, but they won't extend help with PHP and point me to their Java SDK. I've verified in said SDK that I'm using the correct URL and doing similar POST requests. Here is my request script example response...

robert@media:/www/assets/adobe$ php agreement_send.php
* Trying
* Connected to ( port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=US; ST=California; L=San Jose; O=Adobe Systems Incorporated;
* start date: Apr 18 22:00:04 2016 GMT
* expire date: Dec 18 23:10:02 2017 GMT
* subjectAltName: matched
* issuer: C=BE; O=GlobalSign nv-sa; CN=GlobalSign Organization Validation CA - SHA256 - G2
* SSL certificate verify ok.
> POST /api/rest/v5/agreements HTTP/1.1
Accept: */*
Access-Token: <snip>verified access token</snip>
Content-Length: 485
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 485 out of 485 bytes
< HTTP/1.1 404 Not Found
< Date: Wed, 31 Aug 2016 17:25:36 GMT
< Server: Apache
< x-request-id: 6b0a6a93-4b2d-42da-a7e3-148c27f4541e
< Content-Length: 51
< Strict-Transport-Security: max-age=31536000;
< X-Robots-Tag: none
< Content-Type: application/json;charset=UTF-8
* Connection #0 to host left intact
HTTP Code: 404
{"documentCreationInfo":{"fileInfos":{"libraryDocumentName":"My Doc"},"name":"Please sign my doc","recipientSetInfos":{"recipientSetMemberInfos":{"email":""},"recipientSetRole":"SIGNER"},"signatureType":"ESIGN","signatureFlow":"SENDER_SIGNATURE_NOT_REQUIRED","externalID":{"id":"83807"},"mergeFieldInfo":{"defaultValue":"Robert","fieldName":"Name"},"message":"Please provide electronic signature to initiate your membership using EFT"}}
stdClass Object
[code] => NOT_FOUND
[message] => Resource not found

The last couple of lines above is JSON request body and response array. From the response, I am assuming nothing wrong with the content, not even reached it, rather that the URL is not correct or denied? I wanted to post this here before I get on the phone with Adobe to verify all my permissions are correct with my access token. I can post the entire script if necessary, but here is the actual CURL code I think is most relevant...

$url = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

And of course, $httpCode returns 404 as seen above. Is there something I'm doing wrong for POST?


Finally came across the issue and got it working. I am posting JSON but as you can see in my response, Curl using 'Content-Type: application/x-www-form-urlencoded'. I did not have the Content-Type in my headers. This change worked....

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Access-Token: <snip>',
    'x-api-user: email:<snip>',
    'Content-Type: application/json')