Repository navigation
feat(transactions): fix create mutation, add shouldUpdateBalance - #21
Conversation
|
I tried doing client, _ := monarch.NewClientWithToken(os.Getenv("MONARCH_TOKEN"))
shouldUpdateBalance := false
txn, err := client.Transactions.Create(context.Background(), &monarch.CreateTransactionParams{
Date: monarch.Date{Time: time.Now().UTC()},
AccountID: "a-real-account-id-from-Accounts.List",
Amount: -0.01,
Merchant: &monarch.Merchant{Name: "Codex PR21 Smoke Test"},
Notes: "Temporary PR #21 smoke test",
ShouldUpdateBalance: &shouldUpdateBalance,
})
fmt.Printf("txn=%#v err=%v\n", txn, err)Result: With a response-body capture on the HTTP client, Monarch returned: {"errors":[{"message":"Something went wrong while processing: None on request_id: None.","locations":[{"line":1,"column":43}]}]}I also tried the raw GraphQL mutation directly with operationName included, to rule out this Go client wrapper: curl https://api.monarch.com/graphql \
-H "Authorization: Token $MONARCH_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Client-Platform: web" \
-H "Origin: https://app.monarchmoney.com" \
--data '{
"operationName":"Common_CreateTransactionMutation",
"query":"mutation Common_CreateTransactionMutation($input: CreateTransactionMutationInput!) { createTransaction(input: $input) { transaction { id } errors { message code } } }",
"variables":{
"input":{
"date":"2026-05-20",
"accountId":"real-account-id",
"amount":-0.01,
"merchantName":"Codex PR21 Smoke Test",
"notes":"Temporary smoke test",
"shouldUpdateBalance":false
}
}
}'That produced the same HTTP 400 style error. I also tried updateBalance:false instead of shouldUpdateBalance:false. Do you have a working example I can try? |
|
The issue is that Your test and the curl example both omit To fix: pass a valid categories, _ := client.Transactions.Categories.List(context.Background())
// Find "Uncategorized" or use any valid category ID
shouldUpdateBalance := false
txn, err := client.Transactions.Create(context.Background(), &monarch.CreateTransactionParams{
Date: monarch.Date{Time: time.Now().UTC()},
AccountID: "a-real-account-id",
Amount: -0.01,
Merchant: &monarch.Merchant{Name: "Codex PR21 Smoke Test"},
CategoryID: uncategorizedID, // required by Monarch
Notes: "Temporary PR #21 smoke test",
ShouldUpdateBalance: &shouldUpdateBalance,
})I'll update the code to always send |
Let's make it required and error early if its empty |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (48.86%) is below the target coverage (70.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #21 +/- ##
==========================================
+ Coverage 48.35% 48.86% +0.51%
==========================================
Files 17 17
Lines 2031 2032 +1
==========================================
+ Hits 982 993 +11
+ Misses 959 953 -6
+ Partials 90 86 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
- Use merchantName field instead of merchant object (matches Monarch API) - Make categoryId optional (only send when non-empty) - Add ShouldUpdateBalance param for manual account balance control - Round amount to 2 decimal places before sending - Parse fieldErrors from mutation response for better error messages - Skip redundant getTransaction call after create (return ID directly) - Update create.graphql to match Monarch's actual mutation schema
- Test amount rounding to 2 decimal places - Test ShouldUpdateBalance parameter - Test create without merchant or categoryId (optional fields) - Test fieldErrors parsing in error response - Test null transaction response handling - Test GraphQL execution error propagation
Per maintainer feedback: CategoryID is required by the Monarch API. Create now validates upfront and returns a clear error instead of letting the API return a generic "Something went wrong" response.
9204269 to
2e393a3
Compare
Summary
merchantNamefield instead ofmerchantobject in create mutation (matches Monarch's actual API schema)categoryIdoptional — only send when non-emptyShouldUpdateBalanceparam for manual account balance controlfieldErrorsfrom mutation response for better error messagesgetTransactioncall after create — the previous implementation calleds.Get()after a successful create, which was failing with"Something went wrong while processing: ['getTransaction']". Now returns the ID directly from the create response.create.graphqlto match Monarch's actual mutation schema (Common_CreateTransactionMutation)Split from #19 per review feedback.
Test plan
go test ./...)ShouldUpdateBalance: falseprevents manual account balance changes