Get token#
This endpoint is used to obtain an authentication token required for accessing the Saphety Invoice Network API.
Tokens obtained through this endpoint must be included in subsequent API requests as an authorization header (Authorization: Bearer <access_token>).
Endpoint Server Base URL#
# 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"
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 endpoint 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
1.1 Request body structure#
{
"Username": "string",
"Password": "string"
}
Username#
Description: The username created for the user account.
Required: Yes
Type: string
Example: “sin_api_documentation_user@saphety.com”
Password#
Description: The password defined for the user account.
Required: Yes
Type: string
Example: “request_password”
1.2 Request example#
import requests
import json
# SIN account endpoint url
service_url = "https://" + server_base_adress + "/api/Account/getToken"
print ('Endpoint url: ' + service_url)
headers = {
'content-type': 'application/json'
}
payload = {
'Username': '[email protected]',
'Password': 'request_password'
}
Endpoint url: https://dcn-solution-int.saphety.com/Dcn.Sandbox.WebApi/api/Account/getToken
1.3 Call endpoint and get back the token#
# serialize the payload object to json
request_data=json.dumps(payload)
# 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))
# your token is at:
token = json_response["Data"];
{
"CorrelationId": "a123875e-247f-4fa2-a397-29a854aab182",
"IsValid": true,
"Errors": [],
"Data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJzaW5fYXBpX2RvY3VtZW50YXRpb25fdXNlckBzYXBoZXR5LmNvbSIsInVuaXF1ZV9uYW1lIjoic2luX2FwaV9kb2N1bWVudGF0aW9uX3VzZXJAc2FwaGV0eS5jb20iLCJzeXN0ZW1fYWRtaW4iOiJGYWxzZSIsInNlc3Npb25faWQiOiJjYmQ3YzE0NC05YmFjLTQ4YWYtYjRmNi0wNDY2YzI5MzhjMjAiLCJjcCI6InNpbl9hcGlfZG9jdW1lbnRhdGlvbl91c2VyQHNhcGhldHkuY29tIiwicmwiOiJEZXZlbG9wZXIiLCJuYmYiOjE3MDI0MDE5NDMsImV4cCI6MTcwODQwMTg4MywiaWF0IjoxNzAyNDAxODgzLCJpc3MiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS8iLCJhdWQiOiJodHRwczovL3d3dy5zYXBoZXR5LmNvbS9EY25TYW5kYm94In0.MVfQNgxNM6MiQ8ZwKQBkgI2eLTLsu9TRbuSFxZwWGnU"
}
* 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.