Resend invoice by email notification#

Use this service to resend invoices by email notification.

Service steps#

  1. Get a token from your credentials by calling the service Account/getToken;

  2. Resend notifications calling the service OutboundFinancialDocumentMaintenance/sendAdditionalNotifications;

Response structure from server#

When a request is well formed and the authentication data is correct the system responds with a message envelope as follows:

{
	"CorrelationId": "<GUID>", /* for correlation purposes */
	"IsValid": true,           /* false in case of erros */
	"Errors": [],              /* if empty is a good signal */
	"Data": "<Service Response Data>"   /* the data retuned ex: token, invoice status, dependent on the service called */
}

1. Get a token (Account/getToken)#

Credentials have be given to you, according to your registration at SANDBOX or Saphety Invoice Network:

  • For Test purposes, the user and password defined at SANDBOX registration
    or

  • For Production, the user and password defined at Saphety Invoice Network registration

Use those credentials to get a token at:

https://<ServerBaseAddress>/api/Account/getToken
# SANDBOX - Test Environment
server_base_adress = "dcn-solution.saphety.com/Dcn.Sandbox.WebApi"

# Saphety Invoice Network - Production Environment
#server_base_adress = "dcn-solution.saphety.com/Dcn.Business.WebApi"
import requests
import json

# SIN account service url
service_url = "https://" + server_base_adress + "/api/Account/getToken"

# the username and password you registerd in SIN
username = 'sin_api_documentation_user@saphety.com'
password = 'request_password'

# auhtentication data goes in payload as json
payload = {
      'Username': username,
      'Password': password
}
# payload goes in json, serialize the payloal object to json
request_data=json.dumps(payload)
# indicate in header that payload is json
headers = {
    'content-type': 'application/json'
    }
# POST request to get a token
response = requests.request("POST", service_url, data=request_data, headers=headers)

* Note: the credentials (user and password) in this documentation were created by Saphety and can only be used in the SANDBOX environment. For tests we recommend that you use the credentials you obtained when registering with the SANDBOX.

# formating the response to json for visualization purposes only
json_response = json.loads(response.text)
print(json.dumps(json_response, indent=4))
{
    "CorrelationId": "e7ca0763-9e22-4494-a270-953ef76261c5",
    "IsValid": true,
    "Errors": [],
    "Data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJzaW5fYXBpX2RvY3VtZW50YXRpb25fdXNlckBzYXBoZXR5LmNvbSIsInVuaXF1ZV9uYW1lIjoic2luX2FwaV9kb2N1bWVudGF0aW9uX3VzZXJAc2FwaGV0eS5jb20iLCJzeXN0ZW1fYWRtaW4iOiJGYWxzZSIsInNlc3Npb25faWQiOiI3ZDc0NGMwNi1kYmI5LTRjYzAtYTEzYS05YjM0NjI5OWY0ODYiLCJjcCI6InNpbl9hcGlfZG9jdW1lbnRhdGlvbl91c2VyQHNhcGhldHkuY29tIiwicmwiOiJEZXZlbG9wZXIiLCJuYmYiOjE2NzExNDI0MjcsImV4cCI6MTY3MTE3MTIyNywiaWF0IjoxNjcxMTQyMzY3LCJpc3MiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS8iLCJhdWQiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS9EY25TYW5kYm94In0.MuayEYK0l66ey3VFzL4BzbwgsLMZQKu3TyD4WkiWrMg"
}
# your token is at:
token = json_response["Data"];
print (token)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJzaW5fYXBpX2RvY3VtZW50YXRpb25fdXNlckBzYXBoZXR5LmNvbSIsInVuaXF1ZV9uYW1lIjoic2luX2FwaV9kb2N1bWVudGF0aW9uX3VzZXJAc2FwaGV0eS5jb20iLCJzeXN0ZW1fYWRtaW4iOiJGYWxzZSIsInNlc3Npb25faWQiOiI3ZDc0NGMwNi1kYmI5LTRjYzAtYTEzYS05YjM0NjI5OWY0ODYiLCJjcCI6InNpbl9hcGlfZG9jdW1lbnRhdGlvbl91c2VyQHNhcGhldHkuY29tIiwicmwiOiJEZXZlbG9wZXIiLCJuYmYiOjE2NzExNDI0MjcsImV4cCI6MTY3MTE3MTIyNywiaWF0IjoxNjcxMTQyMzY3LCJpc3MiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS8iLCJhdWQiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS9EY25TYW5kYm94In0.MuayEYK0l66ey3VFzL4BzbwgsLMZQKu3TyD4WkiWrMg

2. Resend PDF invoice notifications (OutboundFinancialDocumentMaintenance/sendAdditionalNotifications)#

Build the service endpoint url#

In the service url you don’t need to supply anything.

https://<ServerBaseUrl>/OutboundFinancialDocumentMaintenance/sendAdditionalNotifications
# SIN service ur
service_url = """{ServerBaseUrl}/api/OutboundFinancialDocumentMaintenance/sendAdditionalNotifications""".format(
    ServerBaseUrl=server_base_adress
)
service_url = "https://" + service_url
print (service_url)
https://dcn-solution.saphety.com/Dcn.Sandbox.WebApi/api/OutboundFinancialDocumentMaintenance/sendAdditionalNotifications

Build the service body#

In the service body you need to supply some data.

  • OutboundFinancialDocumentId
    Set the OutboundFinancialDocumentId to your document.

  • DestinationEmails

    • Email: Set the client/receiver email address to send the notification

    • SendAttachment: Set whether the PDF is sent as an attachment in the notification. Allowed values for this parameter: True, False.

    • LanguageCode: Set the notification language. Format is ISO 639-1 (ex: pt)

#headers
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'bearer ' + token
    }
# payload as json
payload = {
  'OutboundFinancialDocumentId': 'fc5e547d-8537-4e05-97d5-1159c62efd6f',
  'DestinationEmails': [{
    'Email': 'sin_api_documentation_user@saphety.com',
    'SendAttachment': True,
    'LanguageCode': 'PT'
  }]
}
request_data=json.dumps(payload)

* Note : in the Sandbox environment, the notifications are sent only for the user registration email, even if within the service payload are displayed other email addresses.

Call the service resend notifications#

You will call the service endpoint url

# Send the request (POST).
response = requests.request("POST", service_url, data=request_data, headers=headers)

# formating the response to json for visualization purposes only
json_response = json.loads(response.text)
print(json.dumps(json_response, indent=4))
{
    "CorrelationId": "50d02294-fe13-49d4-8e5b-77fd02f953f2",
    "IsValid": true,
    "Errors": [],
    "Data": [
        "sin_api_documentation_user@saphety.com"
    ]
}

Read the service response#

Now you need to read the service response and see the email send

# for loop to see all Data
formats = json_response["Data"];
print(json.dumps(formats, indent=4))
[
    "sin_api_documentation_user@saphety.com"
]