Get invoice PDF or UBL from archive#
Use this service to get all invoice formats from archive for your processed document.
Service steps#
Get a token from your credentials by calling the service Account/getToken;
Get all invoice formats calling the service OutboundFinancialDocument/documentFormats/{documentId};
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
orFor 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": "592e5681-251a-4440-a30d-85f909f97199",
"IsValid": true,
"Errors": [],
"Data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJzaW5fYXBpX2RvY3VtZW50YXRpb25fdXNlckBzYXBoZXR5LmNvbSIsInVuaXF1ZV9uYW1lIjoic2luX2FwaV9kb2N1bWVudGF0aW9uX3VzZXJAc2FwaGV0eS5jb20iLCJzeXN0ZW1fYWRtaW4iOiJGYWxzZSIsInNlc3Npb25faWQiOiIwYTRhYmI3Ni1jYWExLTQ2YzAtODQ5My04M2Q2MjlmOTJhZWQiLCJjcCI6InNpbl9hcGlfZG9jdW1lbnRhdGlvbl91c2VyQHNhcGhldHkuY29tIiwicmwiOiJEZXZlbG9wZXIiLCJuYmYiOjE2Njk4MTE1NzQsImV4cCI6MTY2OTg0MDM3NCwiaWF0IjoxNjY5ODExNTE0LCJpc3MiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS8iLCJhdWQiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS9EY25TYW5kYm94In0.J7RBLAPt220VBGg49cQgC0HgUmMxqhRhQYScBZ56s_c"
}
# your token is at:
token = json_response["Data"];
print (token)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJzaW5fYXBpX2RvY3VtZW50YXRpb25fdXNlckBzYXBoZXR5LmNvbSIsInVuaXF1ZV9uYW1lIjoic2luX2FwaV9kb2N1bWVudGF0aW9uX3VzZXJAc2FwaGV0eS5jb20iLCJzeXN0ZW1fYWRtaW4iOiJGYWxzZSIsInNlc3Npb25faWQiOiIwYTRhYmI3Ni1jYWExLTQ2YzAtODQ5My04M2Q2MjlmOTJhZWQiLCJjcCI6InNpbl9hcGlfZG9jdW1lbnRhdGlvbl91c2VyQHNhcGhldHkuY29tIiwicmwiOiJEZXZlbG9wZXIiLCJuYmYiOjE2Njk4MTE1NzQsImV4cCI6MTY2OTg0MDM3NCwiaWF0IjoxNjY5ODExNTE0LCJpc3MiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS8iLCJhdWQiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS9EY25TYW5kYm94In0.J7RBLAPt220VBGg49cQgC0HgUmMxqhRhQYScBZ56s_c
2. Get a List of Document Formats storage by DocumentId (OutboundFinancialDocument/documentFormats/{documentId})#
* Note: The number of formats returned and their type depends on several factors. In the case of this documentation, the formats are fixed, as you can see in the following example.
Build the service endpoint url#
In the service url you need to supply the outboundfinancialdocumentId received
https://<ServerBaseUrl>/OutboundFinancialDocument/documentFormats/<OutboundFinancialDocumentId>
# SIN service url for retrieving inforfation on invoice previously sent
service_url = """{ServerBaseUrl}/api/OutboundFinancialDocument/documentFormats/{OutboundFinancialDocumentId}""".format(
ServerBaseUrl=server_base_adress,
OutboundFinancialDocumentId="fc5e547d-8537-4e05-97d5-1159c62efd6f"
)
service_url = "https://" + service_url
print (service_url)
https://dcn-solution.saphety.com/Dcn.Sandbox.WebApi/api/OutboundFinancialDocument/documentFormats/fc5e547d-8537-4e05-97d5-1159c62efd6f
Call the service to get the formats#
You will call the service endpoint url
# build the request
headers = {
'Authorization': 'bearer ' + token
}
# POST request to send the invoice
response = requests.request("GET", service_url, headers=headers)
# formating the response to json for visualization purposes only
json_response = json.loads(response.text)
print(json.dumps(json_response["Data"], indent=4))
[
{
"OutboundFinancialDocumentId": "fc5e547d-8537-4e05-97d5-1159c62efd6f",
"FormatType": "pdf",
"ContentType": "application/pdf",
"SignatureProvider": "application/pdf",
"DocumentLink": "https://invoicenetwork.saphety.com/Dcn.Sandbox.WebApi/api/Content/stream?token=DkIleLbjFKXGOqJwJQ8Alolood97ImN0SWQiOiJlNzRiN2VkNS0zMzU4LTRiNGYtYjQzZi1lMTY0YmRjMDAwMDEiLCJpRHQiOiIyMDIyLTExLTMwIiwiZUR0IjoiMjAyMi0xMi0wMyIsImlCeSI6IlNJTiBBUEkgRE9DVU1FTlRBVElPTiIsImlUbyI6IlNJTiBBUEkgRE9DVU1FTlRBVElPTiIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D"
},
{
"OutboundFinancialDocumentId": "fc5e547d-8537-4e05-97d5-1159c62efd6f",
"FormatType": "ubl21",
"ContentType": "XadesBes",
"SignatureProvider": "application/xml",
"DocumentLink": "https://invoicenetwork.saphety.com/Dcn.Sandbox.WebApi/api/Content/stream?token=%2BdA%2FJ17tGd8sW6fJH0brwTqv21V7ImN0SWQiOiJlNzRiN2VkNS0zMzU4LTRiNGYtYjQzZi1lMTY0YmRjMDAwMDMiLCJpRHQiOiIyMDIyLTExLTMwIiwiZUR0IjoiMjAyMi0xMi0wMyIsImlCeSI6IlNJTiBBUEkgRE9DVU1FTlRBVElPTiIsImlUbyI6IlNJTiBBUEkgRE9DVU1FTlRBVElPTiIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D"
}
]
Read the service response#
Now you need to read the service response to format all document formats and get the end file
# for loop to see all Data
formats = json_response["Data"];
for format in formats:
if format["FormatType"] == "pdf":
print ("PDF: " + format["DocumentLink"] + "\n");
if format["FormatType"] == "final":
print ("Final: " + format["DocumentLink"] + "\n");
if format["FormatType"] == "ubl21":
print ("UBL: " + format["DocumentLink"] + "\n");
if format["FormatType"] == "signed":
print ("Signed: " + format["DocumentLink"] + "\n");
PDF: https://invoicenetwork.saphety.com/Dcn.Sandbox.WebApi/api/Content/stream?token=DkIleLbjFKXGOqJwJQ8Alolood97ImN0SWQiOiJlNzRiN2VkNS0zMzU4LTRiNGYtYjQzZi1lMTY0YmRjMDAwMDEiLCJpRHQiOiIyMDIyLTExLTMwIiwiZUR0IjoiMjAyMi0xMi0wMyIsImlCeSI6IlNJTiBBUEkgRE9DVU1FTlRBVElPTiIsImlUbyI6IlNJTiBBUEkgRE9DVU1FTlRBVElPTiIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D
UBL: https://invoicenetwork.saphety.com/Dcn.Sandbox.WebApi/api/Content/stream?token=%2BdA%2FJ17tGd8sW6fJH0brwTqv21V7ImN0SWQiOiJlNzRiN2VkNS0zMzU4LTRiNGYtYjQzZi1lMTY0YmRjMDAwMDMiLCJpRHQiOiIyMDIyLTExLTMwIiwiZUR0IjoiMjAyMi0xMi0wMyIsImlCeSI6IlNJTiBBUEkgRE9DVU1FTlRBVElPTiIsImlUbyI6IlNJTiBBUEkgRE9DVU1FTlRBVElPTiIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D