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

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.

Related

Not getting response from AWS after uploading image through ESP32

General context:
I am working on an IoT application where I upload images from an ESP32 connected to an SBC.
The uploading is done through an API provided by a third-party backend developer.
The upload API works through other mediums (such as Postman, python requests library, python http client library)
The ESP32 is connected to the SBC through UART.
I construct/generate the HTTP request on the SBC and send it as bytes. I have written a function on ESP32 that can send the bytes as a generic HTTP request, to the URL specified.
Then it sends the response string back to the SBC.
All of this works. For small requests, I am facing no issues. I am able to download images, etc.
However, when uploading an image, I don't get a response and I end up timing out after 30s. I checked without timeout FYI, but no response.
I checked from the server-side. It appears my request has succeeded and the server is sending me 200 with the URL of the image. Using that URL, I was able to verify that the image was uploaded successfully.
However, I do not receive this response on the microcontroller.
Not sure what the issue is. Any suggestions as to what I can do?
I can't give out the code but I'll send a general structure:
ESP32
-> Receives URL, port, length of request
-> Connects to server and reads the request from UART and writes to server
-> Wait for response after response is sent
Python raw http
POST (server path) HTTP/1.1
Host: (url)
correlation-id: test5
Content-Type: multipart/form-data; boundary=WebKitFormBoundary7MA4YWxkTrZu0gW
Authorization: Bearer (access token)
Content-Length: 268
--WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="portraits"; filename="name"
Content-Type: image/jpeg
(data)
--WebKitFormBoundary7MA4YWxkTrZu0gW--
Edit 1:
So, turns out it is not only "upload image", some other requests are also behaving similarly. Our server has many microservices. The services written in nodeJS which have more than 1 redirects are not working...?
I figured out what the issue is and hopefully, it will help anyone else facing the same issue. Also, some of my requests to the backend server which used a different authentication method worked
I had been generating the raw HTTP using postman code generation but it turns out Postman doesn't add a few headers which are needed for communicating with more complex servers.
What I mean is that if I host a local server, the above code will work. I had already tested it that way
What solved my problem is adding these headers:
POST (server path) HTTP/1.1
Host: (server URL)
User-Agent: ESP32
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
correlation-id: test
Authorization: Bearer (access_token)
Content-Length: 146360
Content-Type: multipart/form-data; boundary=af59ef02d60cd0efefb7bc03db1f4ffc
--af59ef02d60cd0efefb7bc03db1f4ffc
Content-Disposition: form-data; name="portraits"; filename="(name)"
Content-Type: image/jpeg
(data)
--af59ef02d60cd0efefb7bc03db1f4ffc--

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.

DocuSign invalid_grant error

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.

Node.js: Why does post request w/ png have content-length header value that is smaller than the actual file size?

I'm making a post request to a local node.js server. The post request contains a .png file that is 2.6 kB. The post request is issued using curl:
curl -v -X POST -H "Content-Type: image/png" -d #node.png http://localhost:3000
The request output of the curl command is:
POST / HTTP/1.1
User-Agent: curl/7.38.0
Host: localhost:3000
Accept: */*
Content-Type: image/png
Content-Length: 1328
Expect: 100-continue
Note that the Content-Length header is showing up as 1328 Bytes which is about half of the actual file size being posted. The content-length should be around 2.6 kB, correct? Thanks for your help!
It is actually request header for downloading a partial file.
please check out this from Wikipedia,
The server has received the request headers and the client should
proceed to send the request body (in the case of a request for which a
body needs to be sent; for example, a POST request). Sending a large
request body to a server after a request has been rejected for
inappropriate headers would be inefficient. To have a server check the
request's headers, a client must send Expect: 100-continue as a header
in its initial request and receive a 100 Continue status code in
response before sending the body. The response 417 Expectation Failed
indicates the request should not be continued.
Wiki Link

how to connect node js to quickbooks v3 REST API

I am trying to connect to Intuits v3 REST api, using node.js. I am using SuperAgent and superagent-oauth to make the requests. I generated the access tokens using Intuits Oauth playground. But I keep getting "ApplicationAuthenticationFailed; errorCode=003200; statusCode=401"
This is what I am using.
var OAuth = require('oauth')
,request = require('superagent');
require('superagent-oauth')(request);
var oauth = new OAuth.OAuth('','', consumerKey, consumerSecret, '1.0.A', null, 'HMAC-SHA1')
request.get("https://quickbooks.api.intuit.com/v3/company/672198300/customer/102")
.set('Content-Type', 'text/plain')
.accept('json')
.sign(oauth,accessToken,accessTokenSecret )
.end(function (err, res) {
console.log(res.text)
})
and here is the response
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse time="2014-06-14T18:33:49.228-07:00" xmlns="http://schema.intuit.com/finance/v3">
<Fault type="AUTHENTICATION">
<Error code="3200">
<Message>message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401</Message>
</Error>
</Fault>
Can anyone shed any light on what is happening?
You could use the node.js client library
Like most other clients, that would save you from manually building http requests. Just provide the application credentials and the individual user credentials and you can simply call methods on a Javascript object. All of the REST endpoints have corresponding methods on the QuickBooks object, which follows node.js convention and takes an optional callback as the last argument.
SOlVED!
I used Postman to create the request. And it worked. Then I checked the oAuth header Postman had generated against the one I was generating with node ( I used requestBin to see the header of my request ). I discovered that the only real difference was that I was using "1.0A" as the version. Changing that to "1.0" worked!
var oauth = new OAuth.OAuth('','', consumerKey, consumerSecret, '1.0', null, 'HMAC-SHA1')
I do not have anything for ou in node.js but can provide you with raw request and response for the calls. Compare your raw requests against this. The signature should be double encoded.
Get Request token call-
GET https://oauth.intuit.com/oauth/v1/get_request_token?oauth_callback=oob&oauth_nonce=34562646-ab97-46e1-9aa7-f814d83ef9d1&oauth_consumer_key=qyprd7I5WvVgWDFnPoiBh1ejZn&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1392306961&oauth_version=1.0&oauth_signature=0EtvSnzsuumeyib2fiEcnSyu8%3D HTTP/1.1
Host: oauth.intuit.com
HTTP/1.1 200 OK
Date: Thu, 13 Feb 2014 15:56:03 GMT
Server: Apache
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Length: 150
Connection: close
Content-Type: text/plain
oauth_token_secret=dXhHHMS1EfdrQ32UabOMscIRWt5bLJNX3ZKljjBc&oauth_callback_confirmed=true&oauth_token=qyprdbwXdWrAt0xM2NgkLlJ79yCp4I2SmDg7tahDBPjA6Wti
Get Access Token-
GET https://oauth.intuit.com/oauth/v1/get_access_token?oauth_verifier=b4skra3&oauth_token=qyprde5fvI7WNOQjTKYLDzTVxJ2dLPTgQEQSPlDVGxEy9wZX&oauth_nonce=f20a5a4b-3635-40a8-92cf-697dfdb07b9d&oauth_consumer_key=qyprd7I5WvVgJZUvWDFnPoiBh1ejZn&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1392397399&oauth_version=1.0&oauth_signature=gEVHttlM8IBAAkmi1dSNJgkKGsI%3D HTTP/1.1
Host: oauth.intuit.com
HTTP/1.1 200 OK
Date: Fri, 14 Feb 2014 17:03:20 GMT
Server: Apache
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Length: 120
Connection: close
Content-Type: text/plain
oauth_token_secret=474gtp6xsFzNJ1EhrrjiHrTH96xXieaRLinjPomA&oauth_token=qyprdNIpWn2oYPupMpeH8Byf9Bhun5rPpIZZtTbNsPyFtbT4

Resources