-
Notifications
You must be signed in to change notification settings - Fork 11
Add Webhooks API + slim README to docs.mifiel.com #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using MifielAPI.Objects; | ||
| using MifielAPI.Utils; | ||
| using System.Collections.Generic; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
|
|
||
| namespace MifielAPI.Dao | ||
| { | ||
| /// <summary> | ||
| /// CRUD + trigger helpers for account-level webhooks. | ||
| /// See https://docs.mifiel.com/en/#tag/Webhooks | ||
| /// </summary> | ||
| public class Webhooks : BaseObjectDAO<Webhook> | ||
| { | ||
| private string _webhooksPath = "webhooks"; | ||
|
|
||
| public Webhooks(ApiClient apiClient) : base(apiClient) { } | ||
|
|
||
| public override void Delete(string id) | ||
| { | ||
| ApiClient.Delete(_webhooksPath + "/" + id); | ||
| } | ||
|
|
||
| public override Webhook Find(string id) | ||
| { | ||
| HttpContent httpResponse = ApiClient.Get(_webhooksPath + "/" + id); | ||
| string response = httpResponse.ReadAsStringAsync().Result; | ||
| return MifielUtils.ConvertJsonToObject<Webhook>(response); | ||
| } | ||
|
|
||
| public override List<Webhook> FindAll() | ||
| { | ||
| HttpContent httpResponse = ApiClient.Get(_webhooksPath); | ||
| string response = httpResponse.ReadAsStringAsync().Result; | ||
| return MifielUtils.ConvertJsonToObject<List<Webhook>>(response); | ||
| } | ||
|
|
||
| public override Webhook Save(Webhook webhook) | ||
| { | ||
| string json = MifielUtils.ConvertObjectToJson(webhook); | ||
| HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json"); | ||
| HttpContent httpResponse = ApiClient.Post(_webhooksPath, httpContent); | ||
| string response = httpResponse.ReadAsStringAsync().Result; | ||
| return MifielUtils.ConvertJsonToObject<Webhook>(response); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Trigger delivery for a webhook. | ||
| /// </summary> | ||
| /// <param name="id">Webhook id</param> | ||
| /// <param name="resource">UUID of the related resource included in the callback payload</param> | ||
| /// <param name="instant">When true, deliver immediately once instead of enqueueing retries</param> | ||
| public string Trigger(string id, string resource, bool instant = false) | ||
| { | ||
| var body = new Dictionary<string, object> | ||
| { | ||
| { "resource", resource }, | ||
| { "instant", instant } | ||
| }; | ||
| string json = MifielUtils.ConvertObjectToJson(body); | ||
| HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json"); | ||
| HttpContent httpResponse = ApiClient.Post(_webhooksPath + "/" + id + "/trigger", httpContent); | ||
| return httpResponse.ReadAsStringAsync().Result; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace MifielAPI.Objects | ||
| { | ||
| /// <summary> | ||
| /// Account-level webhook subscription. | ||
| /// See https://docs.mifiel.com/en/#tag/Webhooks | ||
| /// </summary> | ||
| public class Webhook | ||
| { | ||
| [JsonProperty("id")] | ||
| public string Id { get; set; } | ||
|
|
||
| [JsonProperty("url")] | ||
| public string Url { get; set; } | ||
|
|
||
| [JsonProperty("callback_type")] | ||
| public string CallbackType { get; set; } | ||
|
|
||
| [JsonProperty("created_at")] | ||
| public string CreatedAt { get; set; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,15 @@ | ||||||||
| # csharp-api-client | ||||||||
| Mifiel API Client for C# | ||||||||
|
|
||||||||
| C# SDK for [Mifiel](https://www.mifiel.com) API. | ||||||||
| Please read our [documentation](http://docs.mifiel.com/) for instructions on how to start using the API. | ||||||||
| C# SDK for the [Mifiel](https://www.mifiel.com) API. | ||||||||
|
|
||||||||
| ## Documentation | ||||||||
|
|
||||||||
| API reference, guides, and examples: | ||||||||
|
|
||||||||
| - English: https://docs.mifiel.com/en/ | ||||||||
| - Español: https://docs.mifiel.com/es/ | ||||||||
|
|
||||||||
| This README covers installation and client setup only. | ||||||||
|
|
||||||||
| ## Installation | ||||||||
|
|
||||||||
|
|
@@ -18,207 +25,38 @@ Or from the Visual Studio Package Manager Console: | |||||||
| Install-Package MifielAPIClient | ||||||||
| ``` | ||||||||
|
|
||||||||
| ## Usage | ||||||||
|
|
||||||||
| For your convenience Mifiel offers a Sandbox environment where you can confidently test your code. | ||||||||
| ## Setup | ||||||||
|
|
||||||||
| To start using the API in the Sandbox environment you need to first create an account at [app-sandbox.mifiel.com](https://app-sandbox.mifiel.com). | ||||||||
|
|
||||||||
| Once you have an account you will need an APP_ID and an APP_SECRET which you can generate in [app-sandbox.mifiel.com/settings/access-tokens](https://app-sandbox.mifiel.com/settings/access-tokens). | ||||||||
|
|
||||||||
| Then you can configure the library with: | ||||||||
| 1. Create an account (production or [sandbox](https://app-sandbox.mifiel.com)). | ||||||||
| 2. Generate an `APP_ID` and `APP_SECRET` in [Access Tokens](https://app-sandbox.mifiel.com/settings/access-tokens). | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Use environment-specific access-token links. Step 1 supports production and sandbox accounts, but Step 2 always opens the sandbox access-token page. The production client defaults to Proposed fix-2. Generate an `APP_ID` and `APP_SECRET` in [Access Tokens](https://app-sandbox.mifiel.com/settings/access-tokens).
+2. Generate an `APP_ID` and `APP_SECRET` in [Access Tokens](https://app.mifiel.com/settings/access-tokens) or [Sandbox Access Tokens](https://app-sandbox.mifiel.com/settings/access-tokens).📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| 3. Configure the client: | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI; | ||||||||
| using MifielAPI; | ||||||||
|
|
||||||||
| ApiClient apiClient = new ApiClient(appId, appSecret); | ||||||||
| // if you want to use our sandbox environment use: | ||||||||
| apiClient.Url = "https://app-sandbox.mifiel.com"; | ||||||||
| ApiClient apiClient = new ApiClient(appId, appSecret); | ||||||||
| // Production is the default (https://app.mifiel.com). | ||||||||
| // For sandbox: | ||||||||
| apiClient.Url = "https://app-sandbox.mifiel.com"; | ||||||||
| ``` | ||||||||
|
|
||||||||
| By default the client talks to production (`https://app.mifiel.com`). | ||||||||
|
|
||||||||
| Document methods: | ||||||||
|
|
||||||||
| - Find: | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
|
|
||||||||
| Documents documents = new Documents(apiClient); | ||||||||
| Document document = documents.Find("id"); | ||||||||
| document.OriginalHash; | ||||||||
| document.File; | ||||||||
| document.FileSigned; | ||||||||
| // ... | ||||||||
| ``` | ||||||||
|
|
||||||||
| - Find all: | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
| using System.Collections.Generic; | ||||||||
|
|
||||||||
| Documents documents = new Documents(apiClient); | ||||||||
| List<Document> allDocuments = documents.FindAll(); | ||||||||
| ``` | ||||||||
|
|
||||||||
| - Create: | ||||||||
|
|
||||||||
| > Use only **original_hash** if you dont want us to have the file.<br> | ||||||||
| > Only **file** or **original_hash** must be provided. | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
| using MifielAPI.Utils; | ||||||||
| using System.Collections.Generic; | ||||||||
|
|
||||||||
| Documents documents = new Documents(_apiClient); | ||||||||
| Document document = new Document() | ||||||||
| { | ||||||||
| File = "path/to/my-file.pdf", | ||||||||
| Signatures = new List<Signature>() | ||||||||
| { | ||||||||
| new Signature() | ||||||||
| { | ||||||||
| SignatureStr = "Signer 1", | ||||||||
| Email = "signer1@email.com", | ||||||||
| TaxId = "AAA010101AAA" | ||||||||
| }, | ||||||||
| new Signature() | ||||||||
| { | ||||||||
| SignatureStr = "Signer 2", | ||||||||
| Email = "signer2@email.com", | ||||||||
| TaxId = "AAA010102AAA" | ||||||||
| } | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
| documents.Save(document); | ||||||||
|
|
||||||||
| // if you dont want us to have the PDF, you can just send us | ||||||||
| // the original_hash and the name of the document. Both are required | ||||||||
| Document document2 = new Document() | ||||||||
| { | ||||||||
| OriginalHash = MifielUtils.GetDocumentHash("path/to/my-file.pdf"), | ||||||||
| Signatures = ... | ||||||||
| } | ||||||||
|
|
||||||||
| documents.Save(document2); | ||||||||
| ``` | ||||||||
|
|
||||||||
| - Save Document related files | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
| using MifielAPI.Utils; | ||||||||
|
|
||||||||
| Documents documents = new Documents(apiClient); | ||||||||
| Document document = documents.Find("id"); | ||||||||
|
|
||||||||
| //save the original file | ||||||||
| documents.SaveFile(document.Id, "path/to/save/file.pdf"); | ||||||||
| //save the signed xml file | ||||||||
| documents.SaveXml(document.Id, "path/to/save/xml.xml"); | ||||||||
|
|
||||||||
| //append pdf base64 in original xml (when document was created using the hash) | ||||||||
| MifielUtils.AppendPDFBase64InOriginalXml("path/to/file.pdf", "path/to/originalXml", "path/to/newXml"); | ||||||||
| ``` | ||||||||
|
|
||||||||
| - Delete | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
|
|
||||||||
| Documents documents = new Documents(apiClient); | ||||||||
| documents.Delete("id"); | ||||||||
| ``` | ||||||||
|
|
||||||||
| Certificate methods: | ||||||||
|
|
||||||||
| - Find: | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
|
|
||||||||
| Certificates certificates = new Certificates(apiClient); | ||||||||
| Certificate certificate = certificates.Find("id"); | ||||||||
| certificate.CerHex; | ||||||||
| certificate.TypeOf; | ||||||||
| // ... | ||||||||
| ``` | ||||||||
|
|
||||||||
| - Find all: | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
| using System.Collections.Generic; | ||||||||
|
|
||||||||
| Certificates certificates = new Certificates(apiClient); | ||||||||
| List<Certificate> allCertificates = certificates.FindAll(); | ||||||||
| ``` | ||||||||
|
|
||||||||
| - Create | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
|
|
||||||||
| Certificates certificates = new Certificates(apiClient); | ||||||||
| Certificate certificate = new Certificate(); | ||||||||
| certificate.File = "path/to/my-certificate.cer"; | ||||||||
|
|
||||||||
| certificates.Save(certificate); | ||||||||
| ``` | ||||||||
|
|
||||||||
| - Delete | ||||||||
|
|
||||||||
| ```csharp | ||||||||
| using MifielAPI.Dao; | ||||||||
| using MifielAPI.Objects; | ||||||||
|
|
||||||||
| Certificates certificates = new Certificates(apiClient); | ||||||||
| certificates.Delete("id"); | ||||||||
| ``` | ||||||||
|
|
||||||||
| ## Releasing | ||||||||
|
|
||||||||
| This SDK ships as the NuGet package **MifielAPIClient** ([nuget.org/packages/MifielAPIClient](https://www.nuget.org/packages/MifielAPIClient)). It targets `net8.0` and is built with the .NET SDK (`dotnet pack` / `dotnet nuget push`). | ||||||||
|
|
||||||||
| 1. **Bump the version** in `MifielAPI/MifielAPI/MifielAPI.csproj` (`<Version>`) and add a heading in `CHANGELOG.md`. The `User-Agent` package version is read from that assembly attribute; do not hard-code it elsewhere. | ||||||||
| 1. **Bump the version** in `MifielAPI/MifielAPI/MifielAPI.csproj` (`<Version>`) and add a heading in `CHANGELOG.md`. | ||||||||
| 2. **Pack:** | ||||||||
|
|
||||||||
| ```shell | ||||||||
| dotnet pack MifielAPI/MifielAPI/MifielAPI.csproj -c Release -o artifacts | ||||||||
| ``` | ||||||||
|
|
||||||||
| The artifact is `artifacts/MifielAPIClient.<version>.nupkg`. | ||||||||
| 3. **Publish to nuget.org** with an API key from [nuget.org/account/apikeys](https://www.nuget.org/account/apikeys). Versions cannot be overwritten once pushed. | ||||||||
| 3. **Publish to nuget.org** with an API key from [nuget.org/account/apikeys](https://www.nuget.org/account/apikeys): | ||||||||
|
|
||||||||
| ```shell | ||||||||
| dotnet nuget push artifacts/MifielAPIClient.<version>.nupkg \ | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Make the package filename shell-safe.
Proposed fix+PACKAGE_VERSION="1.0.0"
-dotnet nuget push artifacts/MifielAPIClient.<version>.nupkg \
+dotnet nuget push "artifacts/MifielAPIClient.${PACKAGE_VERSION}.nupkg" \📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| --source https://api.nuget.org/v3/index.json \ | ||||||||
| --api-key "$NUGET_API_KEY" | ||||||||
| ``` | ||||||||
| 4. **Tag the git commit** and create a GitHub release: | ||||||||
|
|
||||||||
| ```shell | ||||||||
| git tag v<version> | ||||||||
| git push origin v<version> | ||||||||
| gh release create v<version> --title "v<version>" --notes-file CHANGELOG.md | ||||||||
| ``` | ||||||||
|
|
||||||||
| The listing usually appears on nuget.org within a few minutes. Confirm at `https://www.nuget.org/packages/MifielAPIClient/<version>`. | ||||||||
|
|
||||||||
| Smoke tests (optional) use the same SDK: | ||||||||
|
|
||||||||
| ```shell | ||||||||
| dotnet test MifielAPI/MifielAPI.sln --filter Category=Smoke | ||||||||
| ``` | ||||||||
| 4. **Tag the git commit** and create a GitHub release. | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 3277
🌐 Web query:
site:docs.mifiel.com webhooks GET /webhooks/{id} Mifiel API💡 Result:
The available Mifiel API documentation does not contain information regarding a GET /webhooks/{id} endpoint. While the official documentation is accessible at docs.mifiel.com, there is no publicly indexed reference to a specific endpoint for retrieving a single webhook by its ID using the GET method [1].
Citations:
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 4870
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 3220
🌐 Web query:
Mifiel API webhooks GET /webhooks/{id} official documentation💡 Result:
The official documentation for the Mifiel API is hosted at https://docs.mifiel.com/ [1][2]. While external integration resources confirm that Mifiel supports CRUD operations for webhooks (including Create, Delete, and List) [3], the specific endpoint GET /webhooks/{id} is part of the standard RESTful design used within the API framework. For the most accurate and up-to-date technical specifications, please consult the official documentation portal directly at https://docs.mifiel.com/ [1]. If you require specific details regarding authentication, request headers, or response schemas for a particular endpoint, you can navigate to the Webhooks section within the Redoc-powered documentation on that site [1]. If you are currently integrating Mifiel and cannot find the specific endpoint reference, ensure you are logged into your account or accessing the documentation while authenticated, as some API features and documentation views may be restricted based on your service level [2][4][5]. You can also contact Mifiel support via their website chat for direct assistance with API reference materials [4][5].
Citations:
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 306
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 4169
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 948
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 452
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 416
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 802
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 195
🏁 Script executed:
Repository: Mifiel/csharp-api-client
Length of output: 9454
Disable
Webhooks.Find; the API does not support the request.BaseObjectDAO<T>requires this override, so replace the request withthrow new System.NotSupportedException(...).ApiClient.GetconstructsGET /api/v1/webhooks/{id}, but the API specification defines onlyDELETEfor that path. The current call therefore raisesMifielExceptionwithNotFoundinstead of returning aWebhook.🤖 Prompt for AI Agents