-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontactNoteAdd.go
More file actions
105 lines (94 loc) · 3.4 KB
/
Copy pathcontactNoteAdd.go
File metadata and controls
105 lines (94 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package axcelerate
import (
"encoding/json"
"fmt"
)
// NoteResponse represents the response from adding a note to a contact.
// This type handles both success and error response formats from the Axcelerate API.
//
// Success Response Example:
//
// {
// "NOTEID": 128830815,
// "MESSAGE": "Note was added to Contact: 11300044.",
// "STATUS": "success"
// }
//
// Error Response Example:
//
// {
// "DATA": "",
// "ERROR": true,
// "MESSAGES": "Invalid NoteTypeID!",
// "CODE": "412",
// "DETAILS": "NoteTypeID: 27938x was not found in this account."
// }
//
// All fields are optional pointers to accommodate the different response structures.
// Check the ERROR field to determine if the response indicates an error condition.
type NoteResponse struct {
// Success response fields
NOTEID *int `json:"NOTEID,omitempty"` // The unique identifier of the created note
MESSAGE *string `json:"MESSAGE,omitempty"` // Success message describing the operation result
STATUS *string `json:"STATUS,omitempty"` // Status indicator (typically "success" for successful operations)
// Error response fields
DATA *string `json:"DATA,omitempty"` // Additional data field (often empty in error responses)
ERROR *bool `json:"ERROR,omitempty"` // Boolean flag indicating if an error occurred
MESSAGES *string `json:"MESSAGES,omitempty"` // Error message describing what went wrong
CODE *string `json:"CODE,omitempty"` // HTTP or application error code
DETAILS *string `json:"DETAILS,omitempty"` // Detailed error information for debugging
}
// NoteAdd adds a note against a specific Contact.
//
// This function creates a new note for the specified contact in the Axcelerate system.
//
// Parameters:
// - contactID: The ContactID to add the note to (required)
// - params: A map of additional parameters including:
// - "contactNote": The note content to add to the Contact (required)
// - "noteTypeID": The type of note to add to the Contact (optional, defaults to 88 - System Note)
// - "emailNote": A comma-separated list of ContactIDs to email the note to (optional)
//
// Returns:
// - NoteResponse: Contains either success data (NOTEID, MESSAGE, STATUS) or error information
// - *Response: HTTP response details
// - error: Any error that occurred during the request
//
// Example Usage:
//
// params := map[string]string{
// "contactNote": "This is a test note",
// "noteTypeID": "88",
// "emailNote": "12345,67890",
// }
// response, httpResp, err := contactService.NoteAdd(12345, params)
// if err != nil {
// // Handle error
// }
// if response.ERROR != nil && *response.ERROR {
// // Handle API error response
// fmt.Printf("Error: %s", *response.MESSAGES)
// } else {
// // Success
// fmt.Printf("Note ID: %d", *response.NOTEID)
// }
func (s *ContactService) NoteAdd(contactID int, params map[string]string) (NoteResponse, *Response, error) {
var obj NoteResponse
parms := map[string]string{
"contactID": fmt.Sprintf("%d", contactID),
}
// Add all parameters from the provided map
for key, value := range params {
parms[key] = value
}
// Set default noteTypeID if not provided
if _, exists := parms["noteTypeID"]; !exists {
parms["noteTypeID"] = "88"
}
resp, err := do(s.client, "POST", Params{parms: parms, u: "/contact/note/"}, obj)
if err != nil {
return obj, resp, err
}
err = json.Unmarshal([]byte(resp.Body), &obj)
return obj, resp, err
}