client.Labels
इस नेमस्पेस का हर मेथड: उसका सिग्नेचर, उसके पैरामीटर, वह क्या लौटाता है और एक उदाहरण।
मेथड
The labels a thread can carry.
Labels.List
List the workspace's labels, a page at a time
List(ctx context.Context, opts ...openemail.RequestOption) (*openemail.Page, error)Returns one page of the workspace's user labels, sorted by name and then by id. ListAll collects every page and Iterate walks them lazily. Each label carries its colour, threadCount (how many conversations carry it now) and createdAt and updatedAt, which is everything the Labels table in the app shows.
System labels such as INBOX, STARRED and UNREAD are not listed. A thread carries them and Threads.Update takes them, but they cannot be renamed, recoloured or deleted.
color is null on a label saved with no colour. Otherwise color.backgroundColor is a hex value or a gradient token such as gradient:sunset, and color.textColor is the ink the app draws on it, worked out on the server rather than stored.
पैरामीटर
openemail.WithLimitintPage size, from 1 to 100. The server defaults to 25.
openemail.WithCursorstringThe
NextCursorof the previous page, passed back as it came. Leave it out for the first page.openemail.WithAPIKeystringOverrides the client API key for this call only.
लौटाता है
A *openemail.Page with Items, HasMore and NextCursor. Each item has id, name, type, color, threadCount, aiInstructions, aiEnabled, createdAt and updatedAt.
उदाहरण
page, err := client.Labels.List(ctx, openemail.WithLimit(50))if err != nil { return err} for _, label := range page.Items { fmt.Println(label.String("name"), label.Int("threadCount"))} fmt.Println(page.HasMore, page.NextCursor)टिप्पणियाँ
Labels belong to the workspace, so a narrowed key still sees every label.
threadCountis the exception: it counts only conversations delivered to the addresses the key holds.An id is fixed when the label is created and survives a rename, so match on
idrather thannamein stored configuration.The sidebar order in the app is each person's own arrangement and is not exposed.
The cursor is opaque and holds where the last row sat in this order, so a row deleted or edited between pages never breaks the walk: the next page starts at the first row that sorts after it. A cursor this list did not hand out is a 400
invalid_cursor.
इनमें भी उपलब्ध
- API
GET /labels- TypeScript
labels.list()- Python
labels.list()- Ruby
labels.list- PHP
labels->list- Java
labels().list- C#
Labels.ListAsync- CLI
openemail labels list
Labels.ListAll
Collect every label into one slice
ListAll(ctx context.Context, opts ...openemail.RequestOption) ([]openemail.Object, error)Walks every page of List and returns with all labels, sorted by name and then by id. One request per page.
पैरामीटर
openemail.WithLimitintPage size for each request, from 1 to 100. The server defaults to 25.
openemail.WithCursorstringStarts the walk after this cursor instead of the first page.
openemail.WithAPIKeystringOverrides the client API key for every page of this walk.
लौटाता है
A []openemail.Object holding every label.
उदाहरण
labels, err := client.Labels.ListAll(ctx, openemail.WithLimit(100))if err != nil { return err} for _, label := range labels { fmt.Println(label.String("name"))}टिप्पणियाँ
If any page fails the call fails and the labels already fetched are discarded.
इनमें भी उपलब्ध
- API
GET /labels- TypeScript
labels.listAll()- Python
labels.list_all()- Ruby
labels.list_all- PHP
labels->listAll- Java
labels().listAll- C#
Labels.ListAllAsync
Labels.Iterate
Stream the labels one at a time
Iterate(ctx context.Context, opts ...openemail.RequestOption) *openemail.IteratorReturns an iterator that yields labels individually, sorted by name and then by id, and requests the next page only once the current one is drained. Nothing is fetched until you consume it, and breaking out of the loop stops the requests.
पैरामीटर
openemail.WithLimitintPage size for each request, from 1 to 100. The server defaults to 25.
openemail.WithCursorstringStarts the walk after this cursor instead of the first page.
openemail.WithAPIKeystringOverrides the client API key for every page of this walk.
लौटाता है
An *openemail.Iterator yielding one label per step.
उदाहरण
for label, err := range client.Labels.Iterate(ctx).All() { if err != nil { return err } fmt.Println(label.Int("threadCount"), label.String("name"))}टिप्पणियाँ
The iterator is lazy, so an abandoned loop costs only the pages you consumed.
इनमें भी उपलब्ध
- API
GET /labels- TypeScript
labels.iterate()- Python
labels.iterate()- Ruby
labels.iterate- PHP
labels->iterate- Java
labels().iterate- C#
Labels.IterateAsync
Labels.ListColors
List the colours the app offers for labels
ListColors(ctx context.Context, opts ...openemail.RequestOption) ([]openemail.Object, error)Returns the whole label palette as a plain slice: the fourteen solid colours and seven gradients the app offers when you make or edit a label, in the order it shows them. It is a fixed catalogue, so there is no paging. Fetch it once and keep it.
value is what to send as color.backgroundColor: a hex such as #3B82F6 for a solid, a token such as gradient:sunset for a gradient. textColor is the ink drawn on it. A gradient also carries from and to, drawn at 135 degrees, and solid, one hex for places a gradient cannot go.
A label may carry a colour outside this list. Any hex set through the API is kept as it is, and the app offers it back as its own swatch.
पैरामीटर
openemail.WithAPIKeystringOverrides the client API key for this call only.
लौटाता है
A []openemail.Object, each with kind, name, value, solid, from, to and textColor.
उदाहरण
colors, err := client.Labels.ListColors(ctx)if err != nil { return err} for _, color := range colors { fmt.Println(color.String("name"))}टिप्पणियाँ
kindissolidorgradient.fromandtoare null on a solid.
इनमें भी उपलब्ध
Labels.Get
Read one user label by id
Get(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Looks up a single user label and returns it in the same shape as a row of List, with its colour, threadCount, createdAt and updatedAt.
Only user labels are served. INBOX, TRASH and the other system ids are a 404 here even though threads carry them. Ids are matched exactly, so user_receipts does not find USER_RECEIPTS.
पैरामीटर
idstringआवश्यकLabel id such as
USER_RECEIPTS, matched case sensitively.openemail.WithAPIKeystringOverrides the client API key for this call only.
लौटाता है
An openemail.Object with id, name, type: 'user', color, threadCount, aiInstructions, aiEnabled, createdAt and updatedAt.
उदाहरण
label, err := client.Labels.Get(ctx, "USER_RECEIPTS")if err != nil { return err} fmt.Println(label.String("name"), label.Object("color").String("backgroundColor"), label.Int("threadCount"))टिप्पणियाँ
A missing label fails with an
*openemail.Errorthat matchesopenemail.ErrNotFoundand coderesource_not_found.
इनमें भी उपलब्ध
- API
GET /labels/{id}- TypeScript
labels.get()- Python
labels.get()- Ruby
labels.get- PHP
labels->get- Java
labels().get- C#
Labels.GetAsync- CLI
openemail labels get
Labels.Create
Create a user label
Create(ctx context.Context, body openemail.Body, opts ...openemail.RequestOption) (openemail.Object, error)Creates a label and returns with it as it is stored. name is trimmed and must then be 1 to 225 characters. The id is derived from the name as USER_ followed by the name upper cased, with each run of whitespace turned into _, so Big Clients becomes USER_BIG_CLIENTS, and it never changes afterwards.
A name another label already has, compared without case, is refused with 409 label_name_taken, and so is a name whose id another label holds because it was created under that name and renamed since. An existing label is never silently overwritten. A workspace holds at most 50 user labels, and the call past that is a 422 label_limit_reached on name.
color is optional. color.backgroundColor is a hex colour (#RGB, #RGBA, #RRGGBB or #RRGGBBAA, stored upper cased) or a gradient token such as gradient:sunset, and anything else is a 422 invalid_parameter on color.backgroundColor. ListColors returns the palette the app offers. textColor may be sent but is ignored: the ink is worked out from the background. Leaving color out stores no colour.
aiInstructions says what the label is for in plain words, such as invoices and receipts. With aiEnabled on, AI reads each arriving message against them and adds the label when it fits. It skips spam, the Bin, encrypted mail and muted threads, and it only labels: it never archives or moves anything. Turning aiEnabled on needs instructions and a paid plan, and a workspace may have 10 such labels. Without instructions it is a 422 invalid_parameter on aiInstructions, on the free plan a 403 plan_required, and past the tenth a 422 ai_label_limit_reached.
पैरामीटर
namestringआवश्यकDisplay name, trimmed, 1 to 225 characters. Also decides the id.
coloropenemail.BodyThe colour. Leave it out for a label with no colour.
color.backgroundColorstringA hex colour such as
#3B82F6or a gradient token such asgradient:sunset, at most 32 characters. Required oncecoloris given.color.textColorstringAccepted and ignored. The ink is worked out from
backgroundColor.aiInstructionsstring | nilWhat the label is for, in plain words, up to 500 characters, such as
invoices and receipts.aiEnabledboolHave AI apply the label to arriving mail that fits
aiInstructions. It needs instructions and a paid plan, and a workspace may have 10 such labels.openemail.WithAPIKeystringOverrides the client API key for this call only.
लौटाता है
An openemail.Object with the new id, the trimmed name, color, threadCount of 0, aiInstructions, aiEnabled, createdAt and updatedAt.
उदाहरण
label, err := client.Labels.Create(ctx, openemail.Body{ "name": "Big Clients", "color": openemail.Body{"backgroundColor": "gradient:aurora"},})if err != nil { return err} fmt.Println(label.String("id"), label.Object("color").String("textColor"))टिप्पणियाँ
The SDK does not retry a create after a network failure. If you retry by hand after a lost response, a 409
label_name_takenmeans the first attempt succeeded.The label is created before its AI settings are saved, so a create refused with
plan_required,ai_label_limit_reachedorinvalid_parameteronaiInstructionsleaves the label in place with no instructions andaiEnabledoff. Set them withUpdaterather than creating it again.Testruns the instructions over recent mail and shows what they would catch, without labelling anything.
इनमें भी उपलब्ध
- API
POST /labels- TypeScript
labels.create()- Python
labels.create()- Ruby
labels.create- PHP
labels->create- Java
labels().create- C#
Labels.CreateAsync- CLI
openemail labels create
Labels.Update
Rename or recolour a user label
Update(ctx context.Context, id string, patch openemail.Body, opts ...openemail.RequestOption) (openemail.Object, error)Renames a label, recolours it, or changes what AI does with it, and returns with it as it is stored. Send any of name, color, aiInstructions and aiEnabled: a field left out stays as it is, and a patch with none of them is a 422. color: null, or an empty backgroundColor, clears the colour.
The id never changes. A label created as Receipts keeps USER_RECEIPTS after a rename to Invoices, and every thread keeps the label. A new name another label already has, compared without case, is refused with 409 label_name_taken.
Colours follow the rules on Create: a hex value or a gradient token, and anything else is a 422 invalid_parameter. Only user labels can be changed, and a system label id is a 404.
With aiEnabled on, AI reads each arriving message against aiInstructions and adds the label when it fits. It skips spam, the Bin, encrypted mail and muted threads, and it only labels: it never archives or moves anything. Turning it on needs instructions and a paid plan, and a workspace may have 10 such labels. Without instructions it is a 422 invalid_parameter on aiInstructions, on the free plan a 403 plan_required, and past the tenth a 422 ai_label_limit_reached. aiInstructions: null clears the instructions, which also turns aiEnabled off.
पैरामीटर
idstringआवश्यकLabel id such as
USER_RECEIPTS.namestringNew display name, trimmed, 1 to 225 characters. Left out, the name stays.
coloropenemail.Body | nilNew colour.
nullclears it, and leaving it out keeps the stored colour.color.backgroundColorstringA hex colour or a gradient token, at most 32 characters. An empty string clears the colour.
color.textColorstringAccepted and ignored. The ink is worked out from
backgroundColor.aiInstructionsstring | nilWhat the label is for, in plain words, up to 500 characters.
nullclears it, which also turnsaiEnabledoff. Left out, it stays.aiEnabledboolWhether AI applies the label to arriving mail that fits
aiInstructions. Turning it on needs instructions and a paid plan, and a workspace may have 10 such labels. Left out, it stays.openemail.WithAPIKeystringOverrides the client API key for this call only.
लौटाता है
An openemail.Object with the unchanged id and the new name, color, aiInstructions and aiEnabled.
उदाहरण
saved, err := client.Labels.Update(ctx, "USER_RECEIPTS", openemail.Body{"color": openemail.Body{"backgroundColor": "#EA9602"}})if err != nil { return err} fmt.Println(saved.String("id"), saved.String("name"), saved.Object("color").String("backgroundColor"))टिप्पणियाँ
The SDK retries this call after a network failure, since the same patch sent twice leaves the same label.
Testruns instructions over recent mail and shows what they would catch, so you can try wording before you save it here.
इनमें भी उपलब्ध
- API
PATCH /labels/{id}- TypeScript
labels.update()- Python
labels.update()- Ruby
labels.update- PHP
labels->update- Java
labels().update- C#
Labels.UpdateAsync- CLI
openemail labels update
Labels.Test
Try a label on recent mail
Test(ctx context.Context, id string, body openemail.Body, opts ...openemail.RequestOption) (openemail.Object, error)Runs the AI over the newest 20 inbox threads and returns with the ones the label would catch, without labelling anything. Send aiInstructions to try wording you have not saved yet, or leave it out to try what the label holds.
It spends one AI action of the caller, which the labelling of arriving mail never does. A message that arrived encrypted is skipped, and a key limited to particular addresses reads only the threads delivered to them.
पैरामीटर
idstringआवश्यकLabel id such as
USER_RECEIPTS, asListreturns it.aiInstructionsstringWhat the label is for, in plain words, 1 to 500 characters. Left out, the instructions saved on the label are tried.
openemail.WithAPIKeystringOverrides the client API key for this call only.
लौटाता है
An openemail.Object with object set to label_test, labelId, examined and matched. examined is how many recent threads were read, and each match is a map with threadId, subject, sender and receivedOn, with sender the address the newest message is from and receivedOn when it arrived, as its Date header gives it, or null.
उदाहरण
result, err := client.Labels.Test(ctx, "USER_RECEIPTS", openemail.Body{"aiInstructions": "invoices and receipts"})if err != nil { return err} fmt.Println(result.Int("examined"))टिप्पणियाँ
Needs both
labels:writeandthreads:read. An unknown label id is a 404.With no instructions to try, neither in the call nor on the label, it is a 422
invalid_parameter. A spent AI allowance is a 429ai_quota_exceeded, and an install with no AI model set up a 409ai_not_configured.Nothing is saved: the label keeps the instructions it had. Save the wording with
Updateonce it catches what you want.The SDK does not retry it, because each call spends an AI action.
इनमें भी उपलब्ध
- API
POST /labels/{id}/test- TypeScript
labels.test()- Python
labels.test()- Ruby
labels.test- PHP
labels->test- Java
labels().test- C#
Labels.TestAsync- CLI
openemail labels test
Labels.Delete
Delete a user label and remove it from every thread
Delete(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Deletes a user label and, in the same transaction, takes it off every thread that carried it. The threads are otherwise untouched, so a thread that was only filed under this label stays in whatever folder it was in.
There is no undo. Creating a label with the same name again produces the same id, but the threads it was removed from do not get it back. Only user labels can be deleted, and a system label id is a 404.
पैरामीटर
idstringआवश्यकLabel id such as
USER_OLD_PROJECT.openemail.WithAPIKeystringOverrides the client API key for this call only.
लौटाता है
An openemail.Object with object set to label, id and deleted set to true.
उदाहरण
removed, err := client.Labels.Delete(ctx, "USER_OLD_PROJECT")if err != nil { return err} fmt.Println(removed.String("id"), removed.Bool("deleted"))टिप्पणियाँ
The SDK does not retry a delete. A 404 on your own second attempt after a lost response means the first one worked.
Getfirst if you want to say how many conversations will lose the label: itsthreadCountis that number.
इनमें भी उपलब्ध
- API
DELETE /labels/{id}- TypeScript
labels.delete()- Python
labels.delete()- Ruby
labels.delete- PHP
labels->delete- Java
labels().delete- C#
Labels.DeleteAsync- CLI
openemail labels delete