Přímé volání Signi API
Pro volání Signi z Microsoft Power Automate se využijí operace HTTP a Webhook, pří volání z kódu objekty RestRequest(Method.POST) a podobně.
Před voláním API je třeba si vygenerovat v Signi aplikaci API Klíč pro pracovní prostor / workspace, do kterého budete dokumenty k podpisu předávat viz Generování API klíče. Volat pak můžete kterýkoliv z End Pointů Signi API.
...
Parametry operace HTTP pro vyvolání vzoru obdobně jako v Signi HELP > API Integrace > Příklad 3 - Předání podkladů pro vzor :
Požadavek typu POST
Adresa EndPointu je https://api.signi.com/api/v1/contract/?type=template
V HEAD pro autentizaci API klíč v poli s názvem x-api-key
Pro účely dema je na produkčním prostředí Signi https://api.signi.com je workspace "Demo API" a má API klíč = “71c4123d242bdd38047bee838d17e3367dc3ea6748d0975217ce501e834a224c83cab8afd35c9b0e6ade806b7987fae80f97f5c8253cfbb9089cf21f” , při svých voláních zaměňte tento API klíč za API klíč svého workspace, který získáte po objednání služby "Integrace API" a Generování API klíče.
V body je potřebný JSON se všemi parametry pro vytvoření dokumentu, url webhooku odpovídá webhooku vytvořeném dále, lze přidat po otestování tohoto flow.
E-mail demo+counterparty@signi.com si můžete změnit na svůj.
...
Příklad kódu v .NET
.NET je prostředí, framework Microsoftu pro vývoj aplikací.
...
Code Block |
---|
using Art.Gaia; using Art.IDocuments.Models; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Newtonsoft.Json; using RestSharp; using System; using System.Collections.Generic; using System.Text; using BE = Art.BusinessEntity; namespace Art.IDocuments.Logic { public class AnnotationLogic { public Base _base; public AnnotationLogic(Base myBase) { _base = myBase; } // Upload From File public string Upload(EntityReference dokumentReference) { try { BE.art_idokument dokument = _base.Service.Retrieve(BE.art_idokument.EntityLogicalName, dokumentReference.Id, new ColumnSet(BE.art_idokument.Attr.art_customerid.LogicalName, BE.art_idokument.Attr.art_name.LogicalName, BE.art_idokument.Attr.art_sablonaid.LogicalName)).ToEntity<BE.art_idokument>(); BE.art_idokumentsablona sablona = _base.Service.Retrieve(dokument.art_sablonaid.LogicalName, dokument.art_sablonaid.Id, new ColumnSet(BE.art_idokumentsablona.Attr.art_emailautor.LogicalName, BE.art_idokumentsablona.Attr.art_mistopodpisu.LogicalName, BE.art_idokumentsablona.Attr.art_spolecnost.LogicalName, BE.art_idokumentsablona.Attr.art_stranapospisu.LogicalName)).ToEntity<BE.art_idokumentsablona>(); BE.contact contact = _base.Service.Retrieve(BE.contact.EntityLogicalName, dokument.art_customerid.Id, new ColumnSet(BE.contact.Attr.firstname.LogicalName, BE.contact.Attr.lastname.LogicalName, BE.contact.Attr.emailaddress1.LogicalName, BE.contact.Attr.mobilephone.LogicalName, BE.contact.Attr.address1_line1.LogicalName, BE.contact.Attr.description.LogicalName)).ToEntity<BE.contact>(); QueryExpression queryAnno = new QueryExpression { EntityName = BE.annotation.EntityLogicalName, NoLock = true, TopCount = 1, ColumnSet = new ColumnSet(BE.annotation.Attr.filename.LogicalName, BE.annotation.Attr.mimetype.LogicalName, BE.annotation.Attr.documentbody.LogicalName), Criteria = new FilterExpression(LogicalOperator.And) { Conditions = { new ConditionExpression(BE.annotation.Attr.objectid.LogicalName,ConditionOperator.Equal,dokument.Id) } } }; List<BE.annotation> annotations = _base.Service.RetrieveMultiple<BE.annotation>(queryAnno); if (annotations.Count == 0) return "Žádné přílohy"; BE.annotation anno = annotations[0]; byte[] bytes = Convert.FromBase64String(anno.documentbody); if (anno.filename.Contains("html")) { byte[] data = Convert.FromBase64String(anno.documentbody); string decodedString = Encoding.UTF8.GetString(data); string newBodyText = decodedString.Replace("{data_z_dynamics1}", contact.description).Replace("{data_z_dynamics2}", contact.address1_line1); bytes = Encoding.UTF8.GetBytes(newBodyText); } // Dokument stažený z Dynamics 365 DB var client = new RestClient("https://api.signi.com/api/v1/contract/sign/provided") { Timeout = -1 }; //client.UseNewtonsoftJson(); var request = new RestRequest(Method.POST); //request.UseNewtonsoftJson(); request.AddHeader("x-api-key", "71c4123d242bdd38047bee838d17e3367dc3ea6748d0975217ce501e834a224c83cab8afd35c9b0e6ade806b7987fae80f97f5c8253cfbb9089cf21f"); request.AddHeader("Content-Type", "multipart/form-data"); request.AddParameter("email_author", sablona.art_emailautor); request.AddParameter("email_signer", contact.emailaddress1); request.AddParameter("phone_signer", contact.mobilephone); request.AddParameter("firstname_signer", contact.firstname); request.AddParameter("lastname_signer", contact.lastname); request.AddParameter("proposer_sign", "true"); request.AddParameter("negotiator_sign", "true"); request.AddParameter("contract_name", dokument.art_name); request.AddParameter("contract_number", dokument.art_cislodokumentu); request.AddParameter("sign_date", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); request.AddParameter("sign_place", sablona.art_mistopodpisu); request.AddParameter("last_document", "true"); request.AddParameter("person_type", "legal"); //request.AddParameter("date_of_birth", "1970-04-16"); //request.AddParameter("street", "5. května 67"); //request.AddParameter("city", "Libčice nad Vltavou"); //request.AddParameter("zip_code", "25266"); request.AddParameter("company_name", sablona.art_spolecnost); //request.AddParameter("ic", "28524322"); //request.AddParameter("dic", "CZ28524322"); //request.AddParameter("sign_proposer", "{\"position\": {\"x\": 15,\"y\": 84,\"page\": 0}}"); //request.AddParameter("sign_negotiator", "{\"position\": {\"x\": 78,\"y\": 84,\"page\": 0}}"); request.AddParameter("sign_proposer[position][x]", 8); request.AddParameter("sign_proposer[position][y]", 84); request.AddParameter("sign_proposer[position][page]", sablona.art_stranapospisu - 1); request.AddParameter("sign_negotiator[position][x]", 64); request.AddParameter("sign_negotiator[position][y]", 84); request.AddParameter("sign_negotiator[position][page]", sablona.art_stranapospisu - 1); request.AddParameter("webhooks[0][state]", "signed"); request.AddParameter("webhooks[0][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookSigned"); request.AddParameter("webhooks[1][state]", "rejected"); request.AddParameter("webhooks[1][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookRejected"); request.AddParameter("webhooks[2][state]", "expired"); request.AddParameter("webhooks[2][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookExpired"); request.AlwaysMultipartFormData = true; request.AddFileBytes("file", bytes, anno.filename, anno.mimetype); IRestResponse response = client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { BE.art_idokument iDokumentUpdate = new BE.art_idokument { Id = dokument.Id, art_id = JsonConvert.DeserializeObject<UploadDokumentResponseClass>(response.Content).ContractId, art_idokumentid = dokument.Id, statuscode = new OptionSetValue(BE.art_idokument.Attr.statuscode.Options.A_Odeslany_k_podpisu) }; _base.Trace = true; _base.Debug(iDokumentUpdate, "iDokumentUpdate"); iDokumentUpdate.Update(_base.Service); return response.Content; } return response.Content; } catch (Exception e) { _base.Error(e, "Art.IDocuments.Logic.AnnotationLogic.Upload"); return e.Message; } } // Upload From Template public string UploadTemplate(EntityReference dokumentReference) { try { BE.art_idokument dokument = _base.Service.Retrieve(BE.art_idokument.EntityLogicalName, dokumentReference.Id, new ColumnSet(BE.art_idokument.Attr.art_customerid.LogicalName, BE.art_idokument.Attr.art_name.LogicalName, BE.art_idokument.Attr.art_sablonaid.LogicalName)).ToEntity<BE.art_idokument>(); BE.art_idokumentsablona sablona = _base.Service.Retrieve(dokument.art_sablonaid.LogicalName, dokument.art_sablonaid.Id, new ColumnSet(BE.art_idokumentsablona.Attr.art_emailautor.LogicalName, BE.art_idokumentsablona.Attr.art_mistopodpisu.LogicalName, BE.art_idokumentsablona.Attr.art_spolecnost.LogicalName, BE.art_idokumentsablona.Attr.art_stranapospisu.LogicalName)).ToEntity<BE.art_idokumentsablona>(); BE.contact contact = _base.Service.Retrieve(BE.contact.EntityLogicalName, dokument.art_customerid.Id, new ColumnSet(BE.contact.Attr.firstname.LogicalName, BE.contact.Attr.lastname.LogicalName, BE.contact.Attr.emailaddress1.LogicalName, BE.contact.Attr.mobilephone.LogicalName, BE.contact.Attr.address1_line1.LogicalName, BE.contact.Attr.description.LogicalName)).ToEntity<BE.contact>(); QueryExpression queryAnno = new QueryExpression { EntityName = BE.annotation.EntityLogicalName, NoLock = true, TopCount = 1, ColumnSet = new ColumnSet(BE.annotation.Attr.filename.LogicalName, BE.annotation.Attr.mimetype.LogicalName, BE.annotation.Attr.documentbody.LogicalName), Criteria = new FilterExpression(LogicalOperator.And) { Conditions = { new ConditionExpression(BE.annotation.Attr.objectid.LogicalName,ConditionOperator.Equal,dokument.Id) } } }; List<BE.annotation> annotations = _base.Service.RetrieveMultiple<BE.annotation>(queryAnno); if (annotations.Count == 0) { var client1 = new RestClient("https://api.signi.com/api/v1/contract/sign/template") { Timeout = -1 }; //client.UseNewtonsoftJson(); var request1 = new RestRequest(Method.POST); //request.UseNewtonsoftJson(); request1.AddHeader("x-api-key", "71c4123d242bdd38047bee838d17e3367dc3ea6748d0975217ce501e834a224c83cab8afd35c9b0e6ade806b7987fae80f97f5c8253cfbb9089cf21f"); request1.AddHeader("Content-Type", "multipart/form-data"); request1.AddParameter("email_author", sablona.art_emailautor); request1.AddParameter("email_signer", contact.emailaddress1); request1.AddParameter("phone_signer", contact.mobilephone); request1.AddParameter("firstname_signer", contact.firstname); request1.AddParameter("lastname_signer", contact.lastname); request1.AddParameter("proposer_sign", "true"); request1.AddParameter("negotiator_sign", "true"); request1.AddParameter("contract_name", dokument.art_name); request1.AddParameter("contract_number", dokument.art_cislodokumentu); request1.AddParameter("sign_date", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); request1.AddParameter("sign_place", sablona.art_mistopodpisu); request1.AddParameter("last_document", "true"); request1.AddParameter("person_type", "legal"); //request.AddParameter("date_of_birth", "1970-04-16"); //request.AddParameter("street", "5. května 67"); //request.AddParameter("city", "Libčice nad Vltavou"); //request.AddParameter("zip_code", "25266"); request1.AddParameter("company_name", sablona.art_spolecnost); //request.AddParameter("ic", "28524322"); //request.AddParameter("dic", "CZ28524322"); //request.AddParameter("sign_proposer", "{\"position\": {\"x\": 15,\"y\": 84,\"page\": 0}}"); //request.AddParameter("sign_negotiator", "{\"position\": {\"x\": 78,\"y\": 84,\"page\": 0}}"); //request.AddParameter("sign_proposer[position][x]", 8); //request.AddParameter("sign_proposer[position][y]", 84); //request.AddParameter("sign_proposer[position][page]", sablona.art_stranapospisu - 1); //request.AddParameter("sign_negotiator[position][x]", 64); //request.AddParameter("sign_negotiator[position][y]", 84); //request.AddParameter("sign_negotiator[position][page]", sablona.art_stranapospisu - 1); request1.AddParameter("webhooks[0][state]", "signed"); request1.AddParameter("webhooks[0][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookSigned"); request1.AddParameter("webhooks[1][state]", "rejected"); request1.AddParameter("webhooks[1][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookRejected"); request1.AddParameter("webhooks[2][state]", "expired"); request1.AddParameter("webhooks[2][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookExpired"); request1.AddParameter("template_id", 170); request1.AddParameter("parameters", JsonConvert.SerializeObject( new[] { new { id = 411, value = contact.description } })); //request1.AddParameter("parameters[0][id]", 411); //request1.AddParameter("parameters[0][value]", contact.description); IRestResponse response1 = client1.Execute(request1); if (response1.StatusCode == System.Net.HttpStatusCode.OK) { BE.art_idokument iDokumentUpdate = new BE.art_idokument { Id = dokument.Id, art_id = JsonConvert.DeserializeObject<UploadDokumentResponseClass>(response1.Content).ContractId, art_idokumentid = dokument.Id, statuscode = new OptionSetValue(BE.art_idokument.Attr.statuscode.Options.A_Odeslany_k_podpisu) }; _base.Trace = true; _base.Debug(iDokumentUpdate, "iDokumentUpdate"); iDokumentUpdate.Update(_base.Service); return response1.Content; } return "Žádné přílohy"; } BE.annotation anno = annotations[0]; byte[] bytes = Convert.FromBase64String(anno.documentbody); //if (anno.filename.Contains("html")) //{ // byte[] data = Convert.FromBase64String(anno.documentbody); // string decodedString = Encoding.UTF8.GetString(data); // string newBodyText = decodedString.Replace("{data_z_dynamics1}", contact.description).Replace("{data_z_dynamics2}", contact.address1_line1); // bytes = Encoding.UTF8.GetBytes(newBodyText); //} // Dokument stažený z Dynamics 365 DB var client = new RestClient("https://api.signi.com/api/v1/contract/sign/provided") { Timeout = -1 }; //client.UseNewtonsoftJson(); var request = new RestRequest(Method.POST); //request.UseNewtonsoftJson(); request.AddHeader("x-api-key", "71c4123d242bdd38047bee838d17e3367dc3ea6748d0975217ce501e834a224c83cab8afd35c9b0e6ade806b7987fae80f97f5c8253cfbb9089cf21f"); request.AddHeader("Content-Type", "multipart/form-data"); request.AddParameter("email_author", sablona.art_emailautor); request.AddParameter("email_signer", contact.emailaddress1); request.AddParameter("phone_signer", contact.mobilephone); request.AddParameter("firstname_signer", contact.firstname); request.AddParameter("lastname_signer", contact.lastname); request.AddParameter("proposer_sign", "true"); request.AddParameter("negotiator_sign", "true"); request.AddParameter("contract_name", dokument.art_name); request.AddParameter("contract_number", dokument.art_cislodokumentu); request.AddParameter("sign_date", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); request.AddParameter("sign_place", sablona.art_mistopodpisu); request.AddParameter("last_document", "true"); request.AddParameter("person_type", "legal"); //request.AddParameter("date_of_birth", "1970-04-16"); //request.AddParameter("street", "5. května 67"); //request.AddParameter("city", "Libčice nad Vltavou"); //request.AddParameter("zip_code", "25266"); request.AddParameter("company_name", sablona.art_spolecnost); //request.AddParameter("ic", "28524322"); //request.AddParameter("dic", "CZ28524322"); //request.AddParameter("sign_proposer", "{\"position\": {\"x\": 15,\"y\": 84,\"page\": 0}}"); //request.AddParameter("sign_negotiator", "{\"position\": {\"x\": 78,\"y\": 84,\"page\": 0}}"); request.AddParameter("sign_proposer[position][x]", 8); request.AddParameter("sign_proposer[position][y]", 84); request.AddParameter("sign_proposer[position][page]", sablona.art_stranapospisu - 1); request.AddParameter("sign_negotiator[position][x]", 64); request.AddParameter("sign_negotiator[position][y]", 84); request.AddParameter("sign_negotiator[position][page]", sablona.art_stranapospisu - 1); request.AddParameter("webhooks[0][state]", "signed"); request.AddParameter("webhooks[0][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookSigned"); request.AddParameter("webhooks[1][state]", "rejected"); request.AddParameter("webhooks[1][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookRejected"); request.AddParameter("webhooks[2][state]", "expired"); request.AddParameter("webhooks[2][url]", "https://artidocumentswebapi.azurewebsites.net/IDocument/WebHookExpired"); request.AlwaysMultipartFormData = true; request.AddFileBytes("file", bytes, anno.filename, anno.mimetype); IRestResponse response = client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { BE.art_idokument iDokumentUpdate = new BE.art_idokument { Id = dokument.Id, art_id = JsonConvert.DeserializeObject<UploadDokumentResponseClass>(response.Content).ContractId, art_idokumentid = dokument.Id, statuscode = new OptionSetValue(BE.art_idokument.Attr.statuscode.Options.A_Odeslany_k_podpisu) }; _base.Trace = true; _base.Debug(iDokumentUpdate, "iDokumentUpdate"); iDokumentUpdate.Update(_base.Service); return response.Content; } return response.Content; } catch (Exception e) { _base.Error(e, "Art.IDocuments.Logic.AnnotationLogic.Upload"); return e.Message; } } // Download Document public void DownloadTest() { BE.annotation anno = (BE.annotation)_base.Service.Retrieve(BE.annotation.EntityLogicalName, new Guid("54DC0A3F-75A5-EA11-A812-000D3AB7AF7A"), new ColumnSet(true)); RestClient client = new RestClient("https://api.signi.com/api/v1/contract/2842/download"); client.AddDefaultHeader("x-api-key", "71c4123d242bdd38047bee838d17e3367dc3ea6748d0975217ce501e834a224c83cab8afd35c9b0e6ade806b7987fae80f97f5c8253cfbb9089cf21f"); client.AddDefaultHeader("Content-Type", "application/json"); IRestRequest request = new RestRequest { Method = Method.GET }; IRestResponse response = client.Get(request); string fileBase64 = Convert.ToBase64String(response.RawBytes); //fileBase64 - serializovaný soubr, který je možné uložit do DB } public string Download(EntityReference dokumentReference) { try { string output = "OK"; BE.art_idokument dokument = _base.Service.Retrieve(BE.art_idokument.EntityLogicalName, dokumentReference.Id, new ColumnSet(BE.art_idokument.Attr.art_customerid.LogicalName, BE.art_idokument.Attr.art_name.LogicalName, BE.art_idokument.Attr.art_sablonaid.LogicalName, BE.art_idokument.Attr.art_id.LogicalName)).ToEntity<BE.art_idokument>(); QueryExpression queryAnno = new QueryExpression { EntityName = BE.annotation.EntityLogicalName, NoLock = true, TopCount = 1, ColumnSet = new ColumnSet(BE.annotation.Attr.filename.LogicalName), Criteria = new FilterExpression(LogicalOperator.And) { Conditions = { new ConditionExpression(BE.annotation.Attr.objectid.LogicalName,ConditionOperator.Equal,dokument.Id) } } }; List<BE.annotation> annotations = _base.Service.RetrieveMultiple<BE.annotation>(queryAnno); if (annotations.Count == 0) return "Žádné přílohy"; BE.annotation anno = annotations[0]; RestClient client = new RestClient($"https://api.signi.com/api/v1/contract/{dokument.art_id}/download"); client.AddDefaultHeader("x-api-key", "71c4123d242bdd38047bee838d17e3367dc3ea6748d0975217ce501e834a224c83cab8afd35c9b0e6ade806b7987fae80f97f5c8253cfbb9089cf21f"); client.AddDefaultHeader("Content-Type", "application/json"); IRestRequest request = new RestRequest { Method = Method.GET }; IRestResponse response = client.Get(request); string fileBase64 = Convert.ToBase64String(response.RawBytes); BE.annotation annotation = new BE.annotation { objectid = dokumentReference, documentbody = fileBase64, subject = $"Podepsaný dokument: {dokument.art_name}", filename = $"{anno.filename}_podpis.pdf" }; annotation.Create(_base.Service); return output; } catch (Exception e) { _base.Error(e, "Art.IDocuments.Logic.AnnotationLogic.Download"); return e.Message; } } } } |
Příklad kódu v VBA
Visual Basic for Application je vývojový jazyk používaný v desktopových verzích Microsoft Office . Není již podporován v cloudovém prostředí Office 365.
...