|
| 1 | +// This file was auto-generated by Fern from our API Definition. |
| 2 | + |
| 3 | +package fieldmapping |
| 4 | + |
| 5 | +import ( |
| 6 | + context "context" |
| 7 | + fmt "fmt" |
| 8 | + accounting "github.com/merge-api/merge-go-client/accounting" |
| 9 | + core "github.com/merge-api/merge-go-client/core" |
| 10 | + http "net/http" |
| 11 | + url "net/url" |
| 12 | +) |
| 13 | + |
| 14 | +type Client struct { |
| 15 | + baseURL string |
| 16 | + caller *core.Caller |
| 17 | + header http.Header |
| 18 | +} |
| 19 | + |
| 20 | +func NewClient(opts ...core.ClientOption) *Client { |
| 21 | + options := core.NewClientOptions() |
| 22 | + for _, opt := range opts { |
| 23 | + opt(options) |
| 24 | + } |
| 25 | + return &Client{ |
| 26 | + baseURL: options.BaseURL, |
| 27 | + caller: core.NewCaller(options.HTTPClient), |
| 28 | + header: options.ToHeader(), |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +// Get all Field Mappings for this Linked Account. Field Mappings are mappings between third-party Remote Fields and user defined Merge fields. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). |
| 33 | +func (c *Client) FieldMappingsRetrieve(ctx context.Context) (*accounting.FieldMappingApiInstanceResponse, error) { |
| 34 | + baseURL := "https://api.merge.dev" |
| 35 | + if c.baseURL != "" { |
| 36 | + baseURL = c.baseURL |
| 37 | + } |
| 38 | + endpointURL := baseURL + "/" + "api/accounting/v1/field-mappings" |
| 39 | + |
| 40 | + var response *accounting.FieldMappingApiInstanceResponse |
| 41 | + if err := c.caller.Call( |
| 42 | + ctx, |
| 43 | + &core.CallParams{ |
| 44 | + URL: endpointURL, |
| 45 | + Method: http.MethodGet, |
| 46 | + Headers: c.header, |
| 47 | + Response: &response, |
| 48 | + }, |
| 49 | + ); err != nil { |
| 50 | + return nil, err |
| 51 | + } |
| 52 | + return response, nil |
| 53 | +} |
| 54 | + |
| 55 | +// Create new Field Mappings that will be available after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. |
| 56 | +func (c *Client) FieldMappingsCreate(ctx context.Context, request *accounting.CreateFieldMappingRequest) (*accounting.FieldMappingInstanceResponse, error) { |
| 57 | + baseURL := "https://api.merge.dev" |
| 58 | + if c.baseURL != "" { |
| 59 | + baseURL = c.baseURL |
| 60 | + } |
| 61 | + endpointURL := baseURL + "/" + "api/accounting/v1/field-mappings" |
| 62 | + |
| 63 | + var response *accounting.FieldMappingInstanceResponse |
| 64 | + if err := c.caller.Call( |
| 65 | + ctx, |
| 66 | + &core.CallParams{ |
| 67 | + URL: endpointURL, |
| 68 | + Method: http.MethodPost, |
| 69 | + Headers: c.header, |
| 70 | + Request: request, |
| 71 | + Response: &response, |
| 72 | + }, |
| 73 | + ); err != nil { |
| 74 | + return nil, err |
| 75 | + } |
| 76 | + return response, nil |
| 77 | +} |
| 78 | + |
| 79 | +// Deletes Field Mappings for a Linked Account. All data related to this Field Mapping will be deleted and these changes will be reflected after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. |
| 80 | +func (c *Client) FieldMappingsDestroy(ctx context.Context, fieldMappingId string) (*accounting.FieldMappingInstanceResponse, error) { |
| 81 | + baseURL := "https://api.merge.dev" |
| 82 | + if c.baseURL != "" { |
| 83 | + baseURL = c.baseURL |
| 84 | + } |
| 85 | + endpointURL := fmt.Sprintf(baseURL+"/"+"api/accounting/v1/field-mappings/%v", fieldMappingId) |
| 86 | + |
| 87 | + var response *accounting.FieldMappingInstanceResponse |
| 88 | + if err := c.caller.Call( |
| 89 | + ctx, |
| 90 | + &core.CallParams{ |
| 91 | + URL: endpointURL, |
| 92 | + Method: http.MethodDelete, |
| 93 | + Headers: c.header, |
| 94 | + Response: &response, |
| 95 | + }, |
| 96 | + ); err != nil { |
| 97 | + return nil, err |
| 98 | + } |
| 99 | + return response, nil |
| 100 | +} |
| 101 | + |
| 102 | +// Create or update existing Field Mappings for a Linked Account. Changes will be reflected after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. |
| 103 | +func (c *Client) FieldMappingsPartialUpdate(ctx context.Context, fieldMappingId string, request *accounting.PatchedEditFieldMappingRequest) (*accounting.FieldMappingInstanceResponse, error) { |
| 104 | + baseURL := "https://api.merge.dev" |
| 105 | + if c.baseURL != "" { |
| 106 | + baseURL = c.baseURL |
| 107 | + } |
| 108 | + endpointURL := fmt.Sprintf(baseURL+"/"+"api/accounting/v1/field-mappings/%v", fieldMappingId) |
| 109 | + |
| 110 | + var response *accounting.FieldMappingInstanceResponse |
| 111 | + if err := c.caller.Call( |
| 112 | + ctx, |
| 113 | + &core.CallParams{ |
| 114 | + URL: endpointURL, |
| 115 | + Method: http.MethodPatch, |
| 116 | + Headers: c.header, |
| 117 | + Request: request, |
| 118 | + Response: &response, |
| 119 | + }, |
| 120 | + ); err != nil { |
| 121 | + return nil, err |
| 122 | + } |
| 123 | + return response, nil |
| 124 | +} |
| 125 | + |
| 126 | +// Get all remote fields for a Linked Account. Remote fields are third-party fields that are accessible after initial sync if remote_data is enabled. You can use remote fields to override existing Merge fields or map a new Merge field. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). |
| 127 | +func (c *Client) RemoteFieldsRetrieve(ctx context.Context, request *accounting.RemoteFieldsRetrieveRequest) (*accounting.RemoteFieldApiResponse, error) { |
| 128 | + baseURL := "https://api.merge.dev" |
| 129 | + if c.baseURL != "" { |
| 130 | + baseURL = c.baseURL |
| 131 | + } |
| 132 | + endpointURL := baseURL + "/" + "api/accounting/v1/remote-fields" |
| 133 | + |
| 134 | + queryParams := make(url.Values) |
| 135 | + if request.CommonModels != nil { |
| 136 | + queryParams.Add("common_models", fmt.Sprintf("%v", *request.CommonModels)) |
| 137 | + } |
| 138 | + if request.IncludeExampleValues != nil { |
| 139 | + queryParams.Add("include_example_values", fmt.Sprintf("%v", *request.IncludeExampleValues)) |
| 140 | + } |
| 141 | + if len(queryParams) > 0 { |
| 142 | + endpointURL += "?" + queryParams.Encode() |
| 143 | + } |
| 144 | + |
| 145 | + var response *accounting.RemoteFieldApiResponse |
| 146 | + if err := c.caller.Call( |
| 147 | + ctx, |
| 148 | + &core.CallParams{ |
| 149 | + URL: endpointURL, |
| 150 | + Method: http.MethodGet, |
| 151 | + Headers: c.header, |
| 152 | + Response: &response, |
| 153 | + }, |
| 154 | + ); err != nil { |
| 155 | + return nil, err |
| 156 | + } |
| 157 | + return response, nil |
| 158 | +} |
| 159 | + |
| 160 | +// Get all organization-wide Target Fields, this will not include any Linked Account specific Target Fields. Organization-wide Target Fields are additional fields appended to the Merge Common Model for all Linked Accounts in a category. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/target-fields/). |
| 161 | +func (c *Client) TargetFieldsRetrieve(ctx context.Context) (*accounting.ExternalTargetFieldApiResponse, error) { |
| 162 | + baseURL := "https://api.merge.dev" |
| 163 | + if c.baseURL != "" { |
| 164 | + baseURL = c.baseURL |
| 165 | + } |
| 166 | + endpointURL := baseURL + "/" + "api/accounting/v1/target-fields" |
| 167 | + |
| 168 | + var response *accounting.ExternalTargetFieldApiResponse |
| 169 | + if err := c.caller.Call( |
| 170 | + ctx, |
| 171 | + &core.CallParams{ |
| 172 | + URL: endpointURL, |
| 173 | + Method: http.MethodGet, |
| 174 | + Headers: c.header, |
| 175 | + Response: &response, |
| 176 | + }, |
| 177 | + ); err != nil { |
| 178 | + return nil, err |
| 179 | + } |
| 180 | + return response, nil |
| 181 | +} |
0 commit comments