diff --git a/src/main.zig b/src/main.zig index 6dd5315..2bf12ca 100644 --- a/src/main.zig +++ b/src/main.zig @@ -132,9 +132,13 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co \\} ; + // Remove newlines for JSON payload + const query_clean = try std.mem.replaceOwned(u8, allocator, query, "\n", " "); + defer allocator.free(query_clean); + const body = try std.fmt.allocPrint(allocator, \\{{"query":"{s}","variables":{{"email":"{s}"}}}} - , .{ query, username }); + , .{ query_clean, username }); defer allocator.free(body); const uri = try std.Uri.parse(appsync_url); @@ -209,9 +213,20 @@ fn getRecirculationStatus(allocator: std.mem.Allocator, id_token: []const u8, se \\} ; + var query_clean_buf: [query.len]u8 = undefined; + // Remove newlines for JSON payload + const query_replacements = std.mem.replace( + u8, + query, + "\n", + " ", + query_clean_buf[0..], + ); + const query_clean = query_clean_buf[0 .. query.len - ("\n".len * query_replacements)]; + const body = try std.fmt.allocPrint(allocator, \\{{"query":"{s}","variables":{{"heater_serial_number":"{s}"}}}} - , .{ query, serial_number }); + , .{ query_clean, serial_number }); defer allocator.free(body); const uri = try std.Uri.parse(appsync_url);