Sample code for 30+ languages & platforms
Zig

Yapily - Get Application Self

See more Yapily Examples

Get the information about the institutions configured in your application

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Implements the following CURL command:

    // curl -i -X GET \
    //   -u <username>:<password> \
    //   https://api.yapily.com/me

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    http.setLogin("<username>");
    http.setPassword("<password>");

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    http.quickGetSb("https://api.yapily.com/me", sb_response_body) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    const j_resp = try chilkat.JsonObject.init();
    defer j_resp.deinit();
    j_resp.loadSb(sb_response_body) catch {};
    j_resp.setEmitCompact(false);

    std.debug.print("Response Body:\n", .{});
    std.debug.print("{s}\n", .{try j_resp.emit(alloc)});

    const resp_status_code = http.getLastStatus();
    std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
    if (resp_status_code >= 400) {
        std.debug.print("Response Header:\n", .{});
        std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "uuid": "64949de6-6510-4d70-9500-d4aa094c506c",
    //   "name": "APPLICATION NAME",
    //   "active": true,
    //   "authCallbacks": [
    //     "https://display-parameters.com/"
    //   ],
    //   "institutions": [
    //     {
    //       "id": "modelo-sandbox",
    //       "name": "Modelo Sandbox",
    //       "fullName": "Modelo Sandbox",
    //       "countries": [
    //         {
    //           "displayName": "United Kingdom",
    //           "countryCode2": "GB"
    //         }
    //       ],
    //       "environmentType": "SANDBOX",
    //       "credentialsType": "OPEN_BANKING_UK_AUTO",
    //       "media": [
    //         {
    //           "source": "https://images.yapily.com/image/ce2bfdbf-1ae2-4919-ab7b-e8b3d5e93b36?size=0",
    //           "type": "icon"
    //         },
    //         {
    //           "source": "https://images.yapily.com/image/ca502f24-d6df-4785-b4b8-1034b100af77?size=0",
    //           "type": "logo"
    //         }
    //       ],
    //       "features": [
    //         "INITIATE_SINGLE_PAYMENT_SORTCODE",
    //         "CREATE_DOMESTIC_PERIODIC_PAYMENT",
    //         "ACCOUNT_REQUEST_DETAILS",
    //         "ACCOUNT_STATEMENT_FILE",
    //         "CREATE_SINGLE_PAYMENT_SORTCODE",
    //         "ACCOUNTS",
    //         "CREATE_DOMESTIC_SCHEDULED_PAYMENT",
    //         "ACCOUNT_PERIODIC_PAYMENTS",
    //         "CREATE_DOMESTIC_SINGLE_PAYMENT",
    //         "INITIATE_DOMESTIC_PERIODIC_PAYMENT",
    //         "EXISTING_PAYMENTS_DETAILS",
    //         "INITIATE_BULK_PAYMENT",
    //         "EXISTING_PAYMENT_INITIATION_DETAILS",
    //         "ACCOUNT_DIRECT_DEBITS",
    //         "ACCOUNT_TRANSACTIONS",
    //         "INITIATE_DOMESTIC_SINGLE_PAYMENT",
    //         "PERIODIC_PAYMENT_FREQUENCY_EXTENDED",
    //         "CREATE_INTERNATIONAL_SINGLE_PAYMENT",
    //         "ACCOUNT_SCHEDULED_PAYMENTS",
    //         "ACCOUNT",
    //         "ACCOUNT_STATEMENTS",
    //         "ACCOUNT_TRANSACTIONS_WITH_MERCHANT",
    //         "CREATE_BULK_PAYMENT",
    //         "ACCOUNT_BALANCES",
    //         "INITIATE_INTERNATIONAL_SINGLE_PAYMENT",
    //         "INITIATE_DOMESTIC_SCHEDULED_PAYMENT",
    //         "ACCOUNT_BENEFICIARIES",
    //         "IDENTITY",
    //         "ACCOUNT_STATEMENT",
    //         "INITIATE_ACCOUNT_REQUEST"
    //       ]
    //     }
    //   ],
    //   "media": [
    //   ],
    //   "created": "2020-11-09T10:05:29.897+0000",
    //   "updated": "2021-04-14T12:51:07.419+0000"
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var str_val: [:0]const u8 = "";
    var id: [:0]const u8 = "";
    var full_name: [:0]const u8 = "";
    var environment_type: [:0]const u8 = "";
    var credentials_type: [:0]const u8 = "";
    var j: i32 = 0;
    var count_j: i32 = 0;
    var display_name: [:0]const u8 = "";
    var country_code2: [:0]const u8 = "";
    var source: [:0]const u8 = "";
    var v_type: [:0]const u8 = "";

    _ = try j_resp.stringOf(alloc, "uuid");
    var name: [:0]const u8 = try j_resp.stringOf(alloc, "name");
    _ = j_resp.boolOf("active");
    _ = try j_resp.stringOf(alloc, "created");
    _ = try j_resp.stringOf(alloc, "updated");
    var i: i32 = 0;
    var count_i: i32 = j_resp.sizeOfArray("authCallbacks");
    while (i < count_i) {
        j_resp.setI(i);
        str_val = try j_resp.stringOf(alloc, "authCallbacks[i]");
        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("institutions");
    while (i < count_i) {
        j_resp.setI(i);
        id = try j_resp.stringOf(alloc, "institutions[i].id");
        name = try j_resp.stringOf(alloc, "institutions[i].name");
        full_name = try j_resp.stringOf(alloc, "institutions[i].fullName");
        environment_type = try j_resp.stringOf(alloc, "institutions[i].environmentType");
        credentials_type = try j_resp.stringOf(alloc, "institutions[i].credentialsType");
        j = 0;
        count_j = j_resp.sizeOfArray("institutions[i].countries");
        while (j < count_j) {
            j_resp.setJ(j);
            display_name = try j_resp.stringOf(alloc, "institutions[i].countries[j].displayName");
            country_code2 = try j_resp.stringOf(alloc, "institutions[i].countries[j].countryCode2");
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("institutions[i].media");
        while (j < count_j) {
            j_resp.setJ(j);
            source = try j_resp.stringOf(alloc, "institutions[i].media[j].source");
            v_type = try j_resp.stringOf(alloc, "institutions[i].media[j].type");
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("institutions[i].features");
        while (j < count_j) {
            j_resp.setJ(j);
            str_val = try j_resp.stringOf(alloc, "institutions[i].features[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = j_resp.sizeOfArray("media");
    while (i < count_i) {
        j_resp.setI(i);
        i = i + 1;
    }
}