Sample code for 30+ languages & platforms
Zig

Get Akeneo Token given Client ID and Secret

See more HTTP Misc Examples

Assumes you're starting with a client ID and secret obtained from your OAuth1 provider, such as OneLogin. Demonstrates how to get an akeneo token using your client id/secret in combination with your akeneo login/password.

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 requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

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

    // The HTTP Basic authentication for this request is the
    // OAuth client id and secret you've already obtained.
    http.setBasicAuth(true);
    http.setLogin("my_akeneo_client_id");
    http.setPassword("my_akeneo_secret");

    // Build this JSON:
    // {
    //   "grant_type": "password",
    //   "username": "yourusername",
    //   "password": "yourpassword"
    // }

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.updateString("grant_type", "password") catch {};
    json.updateString("username", "my_akeneo_username") catch {};
    json.updateString("password", "my_akeneo_password") catch {};

    // POST this JSON (with the Basic Authentication header)
    const url = "http://pim.my-akeneo-site.com/api/oauth/v1/token";
    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpJson("POST", url, json, "application/json", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Response status code: {d}\n", .{resp.getStatusCode()});
    std.debug.print("Response body: {s}\n", .{try resp.getBodyStr(alloc)});

    if (resp.getStatusCode() == 200) {
        // Success.
        // Parse the response, which looks like this:

        //         {
        //             "access_token": "MTE0NzNkNzI5YTk0ZTBlNmFlNTI5NmVkOWJhZjUxYWRkN2UzZWIwOWNkMTkwNzY5Mzk3NGViMDFmYzdlODJlMg",
        //             "expires_in": 3600,
        //             "token_type": "bearer",
        //             "scope": null,
        //             "refresh_token": "ZDkyMzA2NDhlZjQ2MGQyMDQ2MWRiMDBmOTdkZjQ5ODY5Mzc3MTEzMjVkNTkwZThmNWRlNWY0MzllYWMxZWQ5ZA"
        //         }

        json.load(try resp.getBodyStr(alloc)) catch {};
        const access_token = try json.stringOf(alloc, "access_token");
        _ = json.intOf("expires_in");
        _ = try json.stringOf(alloc, "token_type");
        _ = try json.stringOf(alloc, "scope");
        _ = try json.stringOf(alloc, "refresh_token");

        std.debug.print("Access Token: {s}\n", .{access_token});
    }
}