Skip to content

feat: Add JSON input support for contacts update#200

Closed
jrossi wants to merge 2 commits intoopenclaw:mainfrom
jrossi:feat/contacts-json-input
Closed

feat: Add JSON input support for contacts update#200
jrossi wants to merge 2 commits intoopenclaw:mainfrom
jrossi:feat/contacts-json-input

Conversation

@jrossi
Copy link
Copy Markdown
Contributor

@jrossi jrossi commented Feb 7, 2026

Summary

Adds --from-file flag to gog contacts update command, enabling contact updates from JSON files or stdin. This provides full access to all Google People API fields without requiring individual CLI flags.

Motivation

Currently, gog contacts update only supports a limited set of fields via CLI flags (--given, --family, --email, --phone). Many useful fields like URLs, notes/biographies, addresses, and birthdays are not accessible.

Instead of adding individual flags for every possible field, this PR implements a more flexible JSON-based approach.

Testing

Fully tested with real Google Contacts:

  • File mode: Successfully added Obsidian deep link URI
  • Stdin mode: Successfully added biography/note via pipe
  • Both modes verified working end-to-end

See full PR description at: #200


🤖 AI-Generated: Implemented with Claude Code, fully tested by contributor

Adds --from-file flag to 'gog contacts update' command, enabling updates
from JSON files or stdin. This provides full access to Google People API
fields (URLs, notes, addresses, birthdays, etc.) without requiring
individual CLI flags for each field.

Usage:
  gog contacts get people/c123 --json > contact.json
  # Edit contact.json to add/modify fields
  gog contacts update people/c123 --from-file=contact.json

  # Or pipe directly:
  gog contacts get people/c123 --json | \
    jq '.contact.urls += [{"value": "https://example.com"}]' | \
    gog contacts update people/c123 --from-file=-

Benefits:
- Supports all Google People API fields
- Future-proof (new fields work automatically)
- Scriptable with jq and other JSON tools
- Enables complex nested structure updates

---
🤖 This PR was generated with AI assistance (Claude Code).
The implementation was reviewed and tested by the contributor.
The read mask for 'contacts get' now includes additional fields that can
be updated via JSON input: urls, biographies, addresses, organizations.

This ensures fields written via --from-file are visible when reading
the contact back.

Tested:
- Added Obsidian URI via JSON file - verified in contact
- Added biography via stdin pipe - verified in contact
@jrossi
Copy link
Copy Markdown
Contributor Author

jrossi commented Feb 7, 2026

I completely understand that many of the pull requests are AI-generated. If you want me to pull this and remove it, no problem. It serves my purpose. It will lead to confirmed work and the outcomes I want. I don't want to flood you if you don't want this. No problem. I completely understand. Thank you. Great PR, great tool.

@steipete steipete self-assigned this Feb 14, 2026
@steipete steipete marked this pull request as ready for review February 14, 2026 13:56
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca9d8fe7f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +346 to +347
if len(person.EmailAddresses) > 0 {
updateFields = append(updateFields, "emailAddresses")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include empty list fields in JSON update masks

This branch only adds emailAddresses to updatePersonFields when the slice is non-empty, so a JSON edit that intentionally clears emails (for example setting "emailAddresses": [] after contacts get --json) will not be sent to the API as a clear operation. The same pattern is used for the other repeated fields, which makes --from-file unable to remove existing values and can lead to unexpected no-op updates.

Useful? React with 👍 / 👎.

return outfmt.WriteJSON(os.Stdout, map[string]any{"contact": updated})
}
u.Out().Printf("resource\t%s", updated.ResourceName)
u.Out().Println("✓ Updated from JSON")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep human-only success text off stdout

The new ✓ Updated from JSON line is emitted on stdout in plain mode, which changes contacts update from a single parseable key\tvalue record to mixed machine/human output. Scripts that consume stdout now need special-casing for --from-file; this status hint should go to stderr to preserve stable parseable stdout behavior.

Useful? React with 👍 / 👎.

steipete added a commit that referenced this pull request Feb 14, 2026
Supersedes #200.

- Add `contacts update --from-file <path|->` + `--ignore-etag`
- Update mask from JSON keys; clears via `[]`/`null`
- ETag safety + resourceName validation
- Docs/tests/README/CHANGELOG updates

Co-authored-by: Jeremy Rossi <jeremy@jeremyrossi.com>
@steipete
Copy link
Copy Markdown
Collaborator

Landed via #253 (squash merge).

What changed vs this PR:

  • Conflict resolution against current main
  • Correct People API semantics: update mask derived from JSON key presence; supports clears via []/null (ForceSendFields)
  • ETag safety + --ignore-etag
  • ResourceName validation
  • Unit tests + docs (docs/contacts-json-update.md) + README/spec/changelog updates

Thanks for the original implementation and live testing, @jrossi.

@steipete steipete closed this Feb 14, 2026
klodr pushed a commit to klodr/gogcli that referenced this pull request Apr 22, 2026
Supersedes openclaw#200.

- Add `contacts update --from-file <path|->` + `--ignore-etag`
- Update mask from JSON keys; clears via `[]`/`null`
- ETag safety + resourceName validation
- Docs/tests/README/CHANGELOG updates

Co-authored-by: Jeremy Rossi <jeremy@jeremyrossi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants