Skip to content

DrNoLife/IpwBridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

IpwBridge

C# wrapper for the IPW Metazo API

How to use

Use the extension method AddIpwBridge().

builder.Services.AddIpwBridge(options =>
{
    options.IpwUrl = "https://your-domain.dk/metazo/api/v1/";
    options.IpwUser = "USERNAME";
    options.IpwPassword = "PASSWORD";
    options.ChecksumSecret = "CHECKSUM-SECRET";
});

Which will setup DI for the IMetazoApiClient service.

Example:

public class Worker(IMetazoApiClient metazoApiClient) : BackgroundService
{
    private readonly IMetazoApiClient _metazoApiClient = metazoApiClient;
}

Client methods

The IMetazoApiClient interface exposes a few methods to use:

Task<JsonElement> GetDatatypesAsync();
Task<JsonElement> GetExplanationAsync(string datatype);
Task<JsonElement> GetListAsync(ListRequest dataRequest);
Task<JsonElement> GetItemAsync(int objectId);
Task<JsonElement> SendModelAsync(IpwCrudRequest crudModel);
Task<JsonElement> UploadBinfileAsync(BinfileUploadRequest binfileUploadModel);

Note: Not every single endpoint from the API has been covered. The project is being updated with endpoints as I find a need for them.

GetDatatypesAsync()

var datatypes = await _metazoApiClient.GetDatatypesAsync()

GetExplanationAsync(string datatype)

string datatype = "form113622";
var explanation = await _metazoApiClient.GetExplanationAsync(datatype);

GetListAsync(ListRequest dataRequest)

// Find all entries in the form, that has an objectId greater than '2604436'.
// The entries we find, we also want to get their fields as specified in 'FieldsToGet'.
ListRequest request = new()
{
    DataType = "form121889",
    FieldsToGet = "f276474,f1628152,f2605112",
    SearchAfter = "2604436",
    SearchField = "objectid",
    SearchOperation = "GREATER"
};
wait _metazoApiClient.GetListAsync(request)

GetItemAsync(int objectId)

var item = await _metazoApiClient.GetItemAsync(2605115);

SendModelAsync(IpwCrudRequest crudModel)

Dictionary<string, string> jsonData = new()
{
    { "state", "2" },
};

var fullJson = JsonSerializer.Serialize(jsonData);

IpwCrudRequest crudRequest = new()
{
    Datatype = "form121889",
    Model = ModelOptions.Create,
    JsonData = fullJson
};

var crudResponse = await _metazoApiClient.SendModelAsync(crudRequest);

Note: You can also use ModelOptions.Update or ModelOptions.Delete, however these both require the ObjectId property to be set.

UploadBinfileAsync(BinfileUploadRequest binfileUploadModel)

using var fileStream = File.OpenRead("testimg.png");
BinfileUploadRequest uploadRequest = new()
{
    ParentId = 2605115,
    Files = new()
    {
        { "file_1", fileStream }
    }
};
WritePretty(await _metazoApiClient.UploadBinfileAsync(uploadRequest));

Note: While I haven't tested it, it should also be able to handle multiple files being uploaded at once.

About

C# wrapper for the IPW Metazo API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages