DocuSign invalid_grant error - docusignapi

Code Received by Get URL below:
https://account-d.docusign.com/oauth/auth?response_type=code&scope=signature&client_id=1590cb04-f976-4b54-897d-157f5a711ed0&state=x39pm23rtf23&redirect_uri=https://dev.coplsaas.com.au/brokerdev/webservice/whservice/getdscode
then used received code in POST request to access token with below request
POST /oauth/token HTTP/1.1
HOST: account-d.docusign.com
authorization: Basic MTU5MGNiMDQtZjk3Ni00YjU0LTg5N2QtMTU3ZjVhNzExZWQwOmQxNmY4MWM0LTI5OTktNGMwOC04M2E0LTBiNWZkMGQ0NWFmMA==
content-type: application/x-www-form-urlencoded
cookie: __RequestVerificationToken=ARd6NkNlsuk_YG75ReDu9eQB0; __RequestVerificationToken_L01l0=AbHSxThtrkGESzjnwo0t1c4B0; mest=eyJ0eXAiOiJNVCIsImFsZyI6IkhTMjU2Iiwia2lkIjoiZWUyMDVlYjctYWJiMS00MmRiLTlmNjktZWFmMTg3ZThjZTczIn0.AQcAAAABAAIAAgDOEodJwVSyT4aBM16dnM1UDQAkAAAAYTFiODA4ZDktNGRhNi00ODM0LTgzOTItNGY0OWI2MDZmYTQ3FQABAAAAEgACAAAAAwAAAHRzdgsAAABpbnRlcmFjdGl2ZTAAgGs6FN6p1UgIAAAqazTgqdVI.XdbTt-fuOvAGJZ068I9T9GvA6YhmeW3Uv4RfhZPzoOA
content-length: 656
grant_type=authorization_code&code=eyJ0eXAiOiJNVCIsImFsZyI6IlJTMjU2Iiwia2lkIjoiNjgxODVmZjEtNGU1MS00Y2U5LWFmMWMtNjg5ODEyMjAzMzE3In0.AQkAAAABAAYABwCAcToxpqrVSAgAgP3AeKaq1UgCAM4Sh0nBVLJPhoEzXp2czVQVAAEAAAAYAAEAAAAFAAAADQAkAAAAMTU5MGNiMDQtZjk3Ni00YjU0LTg5N2QtMTU3ZjVhNzExZWQwMACAcToxpqrVSBIAAQAAAAsAAABpbnRlcmFjdGl2ZQ.KCF4tKuyh2AhA_H2FGh5ps89lT82go376xigC_lvtE6W20FonRRsiWM8CL6Bie8iS7miorenX9nVaAP-We4qKjmP1vBwp_yMujltr46Oq8Bt43l2acTgIh0Ne9yUf2C5ER1CF0nY1lusdS_UrgbEDoR_ZuDm2yuDtF2CPJtSMxjuZjEm9pgGOr7jQOCuTcwQLJA0OpmP1Dth7yzodkt50bh3Tfk3M4LxQ-xOMo_VnBTsxW_Ybu29R7ACV1nUdXMabrJQ-qtddRNULQXvXCD-ynpHu6GU0CwzRNeph6YhfRgbdB4ptWkb6XWcG3gkCpx8yaxn7glt58OjkQDi2v8Abw
but facing error below:
{
"error": "invalid_grant"
}
Please help. Thanks in advance.

Code returned by DocuSign after login is one time use and valid for 300 seconds. So I hope your callback URL - https://dev.coplsaas.com.au/brokerdev/webservice/whservice/getdscode is not using this code again and again. I was successfully able to generate AccessToken for my username with your code.

Related

Unspecified Error when sending document on Go Live

I have an active and functional Go Live account. When I use it in my development environment (localhost) I can retrieve the token and send the envelope to the recipients. When I try to use it in the production environment, I can recover the token but I cannot send the envelope. It returns the error to me:
POST https://na2.docusign.net:8822/restapi/v2.1/accounts/xxXXXxxXXxx/envelopes
TraceToken: 03e22f1f-0454-42a5-9e71-337ebf1dd39f
Timestamp: 2020-02-07T19:28:16.4891717Z
Content-Length: 0
Content-Type: application/json
Accept: application/json
Authorization: Bearer [omitted]
Host: na2.docusign.net
User-Agent: Swagger-Codegen/2.0.1/php
Content-Transfer-Encoding: base64
X-DocuSign-SDK: PHP
X-SecurityProtocol-Version: TLSv1.2
X-SecurityProtocol-CipherSuite: ECDHE-RSA-AES256-GCM-SHA384
x-forwarded-for: 34.73.119.92
400 BadRequest
Content-Type: application/json; charset=utf-8
Content-Length: 82
X-DocuSign-TraceToken: 03e22f1f-0454-42a5-9e71-337ebf1dd39f
{"errorCode":"UNSPECIFIED_ERROR","message":"Non-static method requires a target."}
I don't think it's a coding problem because it works well in the development environment
If this is the entire API log, the issue is that your API call does not have a body. Since you're using an SDK, this means that an empty or otherwise invalid EnvelopeDefinition was passed into your CreateEnvelope method.

Receiving HTML code in response to my token request

Using this info:
https://account-d.docusign.com/restapi/v2/oauth/token
Content-Type: application/application/x-www-form-urlencoded
Authorization: Basic xxxx
Note: (xxxx is my integrator_id:secret_key base 64 encoded, i didnt want to post the value publicly)
I do a post call using the following params in the body:
grant_type: 'authorization_code',
code: '{The code returned from the /oauth/auth call}'
Instead of getting a json response, I get an HTML response that I can't seem to post in this message, because its too large.
I am completely stuck and can't finish my project because of this problem.
I think you are using wrong host in calling the /oauth/token, you need to call
https://account-d.docusign.com/oauth/token for Demo and
https://account.docusign.com/oauth/token for PROD
You should not call demo.docusign.net or www.docusign.com, these hosts are for rest of the API calls but not for OAUTH.

Authenticate via POST request in Node.js

I'm trying to authenticate with a site through node by sending my username and password through a POST request, as that's how the login form seems to be doing it. When trying it out with Postman it works just fine and I'm redirected to the my dashboard.
Username and password fields are unfortunately not labeled as username and password, but as j_username and j_password.
This is the data Postman shows me (for reference):
POST /path/for/auth/request HTTP/1.1
Host: site.com
Cache-Control: no-cache
Postman-Token: b6656210-caeb-2b62-d6b6-e10e642b200b
Content-Type: application/x-www-form-urlencoded
j_username=myusername&j_password=mypassword
So I try this in node:
var request = require('request');
request.post({
headers: {'content-type' : 'application/x-www-form-urlencoded'},
url: 'https://site.com/path/for/auth/request',
body: "j_username=myusername&j_password=mypassword"
}, function(err, res, body){
console.log(body);
});
But unfortunately it's coming back empty and err is set to null.
What could be going wrong here? Or is there a better way of authenticating with this resource? As far as I can tell Basic Auth through a header isn't possible here.
Thanks.
The site is probably sending you an HTTP 302 redirect, so that's considered success, which is why there's no error, but there's also no response body, which is why it's "empty". You'll want to look at the statusCode as well as the Location header in the response.

POST /projects/123/star.json returning 400 Bad Request

Brought over from Git
Trying to add the new API URLs to the PHP Basecamp Client. Get stars and delete stars works fine, but POSTing throws a 400.
Request
POST /1804401/api/v1/projects/234118/star.json HTTP/1.1
Response
400 BAD REQUEST
Looks like it will work if I send the project_id as an argument in the payload.
Request
POST /1804401/api/v1/projects/234118/star.json HTTP/1.1
Request Body
{"project_id":234118}
Response
HTTP/1.1 201 Created
I checked our logs and I see your requests going through successfully. Could you try your POST again, with an empty request body?
Update: Aha! I see your requests receiving a 400 response - it's happening before they hit Basecamp. That could be due to a malformed request of some kind. Could you try to reproduce using curl so we can troubleshoot exactly what's occurring? Hard to tell from URL alone.

DocuSignAPI REST - Why won't my OAuth request go through?

I'm attempting to use the DocuSign REST API and create an OAuth request to execute Send of Behalf of (SOBO). Although I can't complete the first task, it's giving me back a Bad Request. What am I doing wrong?
Request with Headers:
POST https://demo.docusign.net/restapi/v2/oauth2/token
Accept: application/xml
Content-Type: application/xml
Content-Length: {length of body}
Request Body
<OAuthTokenRequest>
<grant_type>password</grant_type>
<client_id>{IntegratorKey}</client_id>
<username>test#email.com</username>
<password>{Password}</password>
<scope>api</scope>
</OAuthTokenRequest>
Response with Error:
400 Bad Request
<oauthErr xmlns="http://www.docusign.com/restapi" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<error>invalid_request</error>
<error_description>An OAuth2 error occurred:</error_description>
</oauthErr>
Although most of the DocuSign REST API accepts XML formatting, OAuth requests must be made in x-www-form-urlencoded.
Change your request to the following:
Request with Headers:
POST https://demo.docusign.net/restapi/v2/oauth2/token
Accept: application/xml
Content-Type: application/x-www-form-urlencoded
Content-Length: {length of body}
Request Body:
grant_type=password&client_id={IntegratorKey}&username=test#email.com&password={Password}&scope=api
Sample Response:
200 OK
<oauthAccess xmlns="http://www.docusign.com/restapi" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<access_token>{Access Token}</access_token>
<scope>api</scope>
<token_type>bearer</token_type>
</oauthAccess>
More information can be obtained in this documentation.

Resources