File not found with CURL POST not GET

时间:2016-08-31 17:47:12

标签: php api curl

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....

https://api.echosign.com/api/rest/v5/agreements

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 166.78.79.125...
* Connected to api.echosign.com (166.78.79.125) 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; CN=secure.echosign.com
*   start date: Apr 18 22:00:04 2016 GMT
*   expire date: Dec 18 23:10:02 2017 GMT
*   subjectAltName: api.echosign.com 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
Host: api.echosign.com
Accept: */*
Access-Token: <snip>verified access token</snip>
x-api-user: email:me@myplace.org
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;
< P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
< X-Robots-Tag: none
< Content-Type: application/json;charset=UTF-8
<
* Connection #0 to host api.echosign.com left intact
HTTP Code: 404
{"documentCreationInfo":{"fileInfos":{"libraryDocumentName":"My Doc"},"name":"Please sign my doc","recipientSetInfos":{"recipientSetMemberInfos":{"email":"my@myplace.com"},"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 = 'https://api.echosign.com/api/rest/v5/agreements';
$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);
curl_close($ch);

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

2 个答案:

答案 0 :(得分:0)

根据文档,我认为您对目标$ url做出了错误的选择。试试这个。 (区别在于&#34; na1&#34;和你的一样)

$url = 'https://api.na1.echosign.com:443/api/rest/v5/agreements'

有关详细信息,请参阅以下链接(在您的情况下,开放协议部分) https://secure.na1.echosign.com/public/docs/restapi/v5

答案 1 :(得分:0)

最后遇到了这个问题并让它发挥作用。我正在发布JSON,但正如您在我的回复中所看到的,Curl使用&#39; Content-Type:application / x-www-form-urlencoded&#39;。我的标题中没有Content-Type。这种变化奏效了......

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