I am trying to integrate DocuSign using ABAP, I am able to generate access token,
with the generated access I am trying to access below API: 'https://demo.docusign.net/restapi/v2.1/accounts/' lv_account_id '/envelopes'
the above API is called immediately after the generated access token, I am not sure why I am getting error message,
I have to complete the POC ASAP since we are planning for go-live by month end if everything goes good.
Kindly help.
Best answer by imahmad4all
Hi Eric,
Thanks for your response,
For envelope creation, what is the recommend approach..
I am using SAP ABAP for calling REST API for generating token and envelope creation:
Logic for generating token:
DATA: lo_http_client TYPE REF TO if_http_client, lv_response TYPE string, lv_status_code TYPE i, lv_reason_phrase TYPE string.
CONSTANTS: lv_token_url TYPE string VALUE 'https://account-d.docusign.com/oauth/token', lv_client_id TYPE string VALUE '093fabd3-……….', lv_client_secret TYPE string VALUE '666ccb49-…...', lv_auth_code TYPE string VALUE 'Basic MDkzZ…...YTJkNg==', lv_grant_type TYPE string VALUE 'client_credentials', lv_scope TYPE string VALUE 'signature impersonation'.!--startfragment>
DATA lv_object_id TYPE string.
" Deserialize the JSON response to get the token TYPES: BEGIN OF t_entry, access_token TYPE string, token_type TYPE string, expires_in TYPE n LENGTH 8, scope TYPE string, jti TYPE string, END OF t_entry.
TYPES: t_entry_map TYPE SORTED TABLE OF t_entry WITH UNIQUE KEY access_token.
DATA: m_entries TYPE t_entry, lr_instance TYPE REF TO /ui5/cl_json_parser.
" Set request method and headers lo_http_client->request->set_method( if_http_request=>co_request_method_post ). " Use POST method for token request lo_http_client->request->set_header_field( name = 'Authorization' value = lv_auth_code ). lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/x-www-form-urlencoded' ).
Logic for calling create envelope API using the above generated access token:
DATA: lo_http_client TYPE REF TO if_http_client, lv_boundary TYPE string, lv_auth_header TYPE string, lv_json_payload TYPE string, lv_document TYPE xstring, lv_pdf_encoded TYPE string, lv_envelope_url TYPE string, lv_response TYPE string, lv_status_code TYPE i, lv_reason_phrase TYPE string,
lv_recipient_email TYPE string VALUE '123@gmail.com', lv_recipient_name TYPE string VALUE '123'.
DATA: lv_data TYPE STANDARD TABLE OF string WITH EMPTY KEY.
CONSTANTS lv_account_id TYPE string VALUE 'becac86b-...'.
CONCATENATE 'Bearer' iv_token INTO lv_auth_header SEPARATED BY space. CONCATENATE 'https://demo.docusign.net/restapi/v2.1/accounts/' lv_account_id '/envelopes' INTO lv_envelope_url.
" Define boundary for multipart request lv_boundary = 'multipart-boundary'.
" Construct JSON payload with placeholders CONCATENATE '{"emailSubject": "Please sign this document", "documents": [' lv_document_details '], "recipients": {"signers": [' lv_recipient ']}, "status": "sent"}' INTO lv_json_payload.
" Read PDF document as xstring (assume it's stored locally for this example) " You need to have the document read into lv_document as xstring SELECT SINGLE content FROM ztable INTO @DATA(lv_content) WHERE guid = '0214840D5F501EEF'.
" Set request method and headers lo_http_client->request->set_method( if_http_request=>co_request_method_post ). lo_http_client->request->set_header_field( name = 'Authorization' value = lv_auth_header ). lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/json' ). lo_http_client->request->set_header_field( name = 'Accept' value = 'application/json' ).
" Set the payload (JSON data) lo_http_client->request->set_cdata( lv_json_payload ).
Revoked token: You’ll need to grant consent again, either at the individual level or at the domain level. See Obtain and revoke consent for more information. You can also obtain a new token.
Malformed token: Confirm that the access token was not inadvertently truncated and that it didn’t include extraneous leading or trailing characters. Also confirm that the request header consists of Bearer followed by a space and then the token.
For envelope creation, what is the recommend approach..
I am using SAP ABAP for calling REST API for generating token and envelope creation:
Logic for generating token:
DATA: lo_http_client TYPE REF TO if_http_client, lv_response TYPE string, lv_status_code TYPE i, lv_reason_phrase TYPE string.
CONSTANTS: lv_token_url TYPE string VALUE 'https://account-d.docusign.com/oauth/token', lv_client_id TYPE string VALUE '093fabd3-……….', lv_client_secret TYPE string VALUE '666ccb49-…...', lv_auth_code TYPE string VALUE 'Basic MDkzZ…...YTJkNg==', lv_grant_type TYPE string VALUE 'client_credentials', lv_scope TYPE string VALUE 'signature impersonation'.!--startfragment>
DATA lv_object_id TYPE string.
" Deserialize the JSON response to get the token TYPES: BEGIN OF t_entry, access_token TYPE string, token_type TYPE string, expires_in TYPE n LENGTH 8, scope TYPE string, jti TYPE string, END OF t_entry.
TYPES: t_entry_map TYPE SORTED TABLE OF t_entry WITH UNIQUE KEY access_token.
DATA: m_entries TYPE t_entry, lr_instance TYPE REF TO /ui5/cl_json_parser.
" Set request method and headers lo_http_client->request->set_method( if_http_request=>co_request_method_post ). " Use POST method for token request lo_http_client->request->set_header_field( name = 'Authorization' value = lv_auth_code ). lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/x-www-form-urlencoded' ).
Logic for calling create envelope API using the above generated access token:
DATA: lo_http_client TYPE REF TO if_http_client, lv_boundary TYPE string, lv_auth_header TYPE string, lv_json_payload TYPE string, lv_document TYPE xstring, lv_pdf_encoded TYPE string, lv_envelope_url TYPE string, lv_response TYPE string, lv_status_code TYPE i, lv_reason_phrase TYPE string,
lv_recipient_email TYPE string VALUE '123@gmail.com', lv_recipient_name TYPE string VALUE '123'.
DATA: lv_data TYPE STANDARD TABLE OF string WITH EMPTY KEY.
CONSTANTS lv_account_id TYPE string VALUE 'becac86b-...'.
CONCATENATE 'Bearer' iv_token INTO lv_auth_header SEPARATED BY space. CONCATENATE 'https://demo.docusign.net/restapi/v2.1/accounts/' lv_account_id '/envelopes' INTO lv_envelope_url.
" Define boundary for multipart request lv_boundary = 'multipart-boundary'.
" Construct JSON payload with placeholders CONCATENATE '{"emailSubject": "Please sign this document", "documents": [' lv_document_details '], "recipients": {"signers": [' lv_recipient ']}, "status": "sent"}' INTO lv_json_payload.
" Read PDF document as xstring (assume it's stored locally for this example) " You need to have the document read into lv_document as xstring SELECT SINGLE content FROM ztable INTO @DATA(lv_content) WHERE guid = '0214840D5F501EEF'.
" Set request method and headers lo_http_client->request->set_method( if_http_request=>co_request_method_post ). lo_http_client->request->set_header_field( name = 'Authorization' value = lv_auth_header ). lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/json' ). lo_http_client->request->set_header_field( name = 'Accept' value = 'application/json' ).
" Set the payload (JSON data) lo_http_client->request->set_cdata( lv_json_payload ).
You can login or register as either a Docusign customer or developer. If you don’t already have a Docusign customer or developer account, you can create one for free when registering.
Join the Docusign Community by logging in with your Docusign developer or customer account credentials.
Don’t have an account? You can create a free one when registering.
Note: Partner-specific logins are not available yet. Partners should log in as either a customer or developer
Docusign Community
You can login or register as either a Docusign customer or developer. If you don’t already have a Docusign customer or developer account, you can create one for free when registering.