Document Permalinks#
Use this service to get permalinks to download a document.
Service steps#
Get a token from your credentials by calling the service Account/getToken;
Get document permalinks calling the service OutboundFinancialDocument/getDocumentPermalinks/{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)#
For Test purposes, the user and password defined at Saphety Invoice Network - Quality environment
orFor Production, the user and password defined at Saphety Invoice Network - Production environment
Use those credentials to get a token at:
https://<ServerBaseAddress>/api/Account/getToken
# Saphety Invoice Network - Integration Environment
server_base_adress = "dcn-solution-qa.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 = 'DocUser2022@'
# 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)
# formating the response to json for visualization purposes only
json_response = json.loads(response.text)
print(json.dumps(json_response, indent=4))
{
"CorrelationId": "a2ab4c6b-14a0-48b2-8775-278d4e44f0f2",
"IsValid": true,
"Errors": [],
"Data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJhYjc4OWRkNy0wMzEzLTQyMjEtOWJmOS1jMmI3NzE3ODFjMjAiLCJ1bmlxdWVfbmFtZSI6InNpbl9hcGlfZG9jdW1lbnRhdGlvbl91c2VyQHNhcGhldHkuY29tIiwic3lzdGVtX2FkbWluIjoiRmFsc2UiLCJzZXNzaW9uX2lkIjoiZWY0NzExNzYtNjNlZC00NDNmLTljNDMtZDEyMTc5YWFiMzkwIiwidm8iOiJTYXBoZXR5IiwicmwiOlsiQ29tcGFueUFkbWluaXN0cmF0b3IiLCJDb21wYW55VXNlciJdLCJjcCI6IlBUNTA3OTU3NTQ3IiwibmJmIjoxNjY5NzI1ODk0LCJleHAiOjE2NzU3MjU4MzQsImlhdCI6MTY2OTcyNTgzNCwiaXNzIjoiaHR0cHM6Ly93d3cuc2FwaGV0eS5jb20vIiwiYXVkIjoiaHR0cHM6Ly93d3cuc2FwaGV0eS5jb20vRGNuU2VydmVyIn0._8Sm7GnoFWXUgHfLKXlTRMMA1igsSIZmDAeovkPIoTY"
}
# your token is at:
token = json_response["Data"];
print (token)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJhYjc4OWRkNy0wMzEzLTQyMjEtOWJmOS1jMmI3NzE3ODFjMjAiLCJ1bmlxdWVfbmFtZSI6InNpbl9hcGlfZG9jdW1lbnRhdGlvbl91c2VyQHNhcGhldHkuY29tIiwic3lzdGVtX2FkbWluIjoiRmFsc2UiLCJzZXNzaW9uX2lkIjoiZWY0NzExNzYtNjNlZC00NDNmLTljNDMtZDEyMTc5YWFiMzkwIiwidm8iOiJTYXBoZXR5IiwicmwiOlsiQ29tcGFueUFkbWluaXN0cmF0b3IiLCJDb21wYW55VXNlciJdLCJjcCI6IlBUNTA3OTU3NTQ3IiwibmJmIjoxNjY5NzI1ODk0LCJleHAiOjE2NzU3MjU4MzQsImlhdCI6MTY2OTcyNTgzNCwiaXNzIjoiaHR0cHM6Ly93d3cuc2FwaGV0eS5jb20vIiwiYXVkIjoiaHR0cHM6Ly93d3cuc2FwaGV0eS5jb20vRGNuU2VydmVyIn0._8Sm7GnoFWXUgHfLKXlTRMMA1igsSIZmDAeovkPIoTY
2. Get document permalinks calling the service OutboundFinancialDocument/getDocumentPermalinks/{documentId}#
Build the service endpoint url#
In the service url you need to supply the documentId to search
https://<ServerBaseUrl>/OutboundFinancialDocument/getDocumentPermalinks/<documentId>
# SIN service url for retrieving inforfation on invoice previously sent
service_url = """{ServerBaseUrl}/api/OutboundFinancialDocument/getDocumentPermalinks/{documentId}""".format(
ServerBaseUrl=server_base_adress,
documentId="e90e4213-7354-495c-bb60-cc08aff724f2"
)
service_url = "https://" + service_url
print (service_url)
https://dcn-solution-qa.saphety.com/Dcn.Business.WebApi/api/OutboundFinancialDocument/getDocumentPermalinks/e90e4213-7354-495c-bb60-cc08aff724f2
Call the service to get the document permalinks#
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": "e90e4213-7354-495c-bb60-cc08aff724f2",
"DocumentLink": "https://dcn-solution-qa.saphety.com/IN2.ContentStorage.WebApi/api/Content/false?token=48I6KL%2BWRL0kO07ENkKpPS%2FXL3d7ImN0SWQiOiJjMGNkNTFiZC00MjU3LTQwMjItOTc4ZC03OGY1MTBkZmE4MjEiLCJpRHQiOiIyMDIyLTExLTI5IiwiZUR0IjpudWxsLCJpQnkiOiJTYXBoZXR5IEFQSSBEZW1vIiwiaVRvIjoiU2FwaGV0eSBBUEkgRGVtbyIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D",
"Formats": [
{
"OutboundFinancialDocumentId": "e90e4213-7354-495c-bb60-cc08aff724f2",
"ContentType": "application/xml",
"DocumentLink": "https://dcn-solution-qa.saphety.com/IN2.ContentStorage.WebApi/api/Content/false?token=tKMUGJ6EcQP2wHJZmh9f1FX3YxV7ImN0SWQiOiJjNzAzN2ZkZC0zMzQ3LTQ2NTktOTI4Zi00NDdmYWE1NGU1ZGMiLCJpRHQiOiIyMDIyLTExLTI5IiwiZUR0IjpudWxsLCJpQnkiOiJTYXBoZXR5IEFQSSBEZW1vIiwiaVRvIjoiU2FwaGV0eSBBUEkgRGVtbyIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D"
},
{
"OutboundFinancialDocumentId": "e90e4213-7354-495c-bb60-cc08aff724f2",
"ContentType": "application/json",
"DocumentLink": "https://dcn-solution-qa.saphety.com/IN2.ContentStorage.WebApi/api/Content/false?token=OzmfHtRIl47kohIjFZNI1drsrz17ImN0SWQiOiJhNjBjMTdkZS1hN2UwLTQ1MWItOTkzMC03ZDE4ZmQzZGE3ZWIiLCJpRHQiOiIyMDIyLTExLTI5IiwiZUR0IjpudWxsLCJpQnkiOiJTYXBoZXR5IEFQSSBEZW1vIiwiaVRvIjoiU2FwaGV0eSBBUEkgRGVtbyIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D"
},
{
"OutboundFinancialDocumentId": "e90e4213-7354-495c-bb60-cc08aff724f2",
"ContentType": "application/xml",
"DocumentLink": "https://dcn-solution-qa.saphety.com/IN2.ContentStorage.WebApi/api/Content/false?token=PquoARk8tJFtp4Ss6JCspwj%2Bgh17ImN0SWQiOiJmYWY3ODdkZS0xMzdmLTQ3ODQtODJjMC04MTFmNWZlOTcxZmQiLCJpRHQiOiIyMDIyLTExLTI5IiwiZUR0IjpudWxsLCJpQnkiOiJTYXBoZXR5IEFQSSBEZW1vIiwiaVRvIjoiU2FwaGV0eSBBUEkgRGVtbyIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D"
},
{
"OutboundFinancialDocumentId": "e90e4213-7354-495c-bb60-cc08aff724f2",
"ContentType": "application/pdf",
"DocumentLink": "https://dcn-solution-qa.saphety.com/IN2.ContentStorage.WebApi/api/Content/false?token=SKHRdpBjAl0OnAc0lXYEtuBSpZZ7ImN0SWQiOiI1NjZiMjljNS03MTQwLTQ5ZGEtOTJhMC1kODBiMDkwOWQ1YTYiLCJpRHQiOiIyMDIyLTExLTI5IiwiZUR0IjpudWxsLCJpQnkiOiJTYXBoZXR5IEFQSSBEZW1vIiwiaVRvIjoiU2FwaGV0eSBBUEkgRGVtbyIsInMiOiJ3ZWIiLCJhYWgiOmZhbHNlfQ%3D%3D"
}
]
}