I have a program that can connect to mailchimp via the API and download the data, I now need to be able to update certain email addresses and add new ones. Within the Mailchimp layout I have a custom Merge field called
MMMERGE6 which is a text field.
I need to be able to update this field with a new value.
I have tried building the request in the REST Debugger and although the rest debugger returns no errors the update does not seem to happen. I found an article somewhere on stackoverflow that said that there is an issue with mailchimp to do with where the post content needs to be and if its in the wrong place it fails.
I have code as follows but I am now very stuck.
unit mailud;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, REST.Types, Vcl.StdCtrls, REST.Client,
REST.Authenticator.Basic, Data.Bind.Components, Data.Bind.ObjectScope;
type
TForm1 = class(TForm)
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTResponse1: TRESTResponse;
HTTPBasicAuthenticator1: THTTPBasicAuthenticator;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
(* For Visibility
RESTRequest1.baseurl:='https://us10.api.mailchimp.com/3.0/lists/dc2af4377f/members/c266cac4b1560b2e88cc893a9a0a1d2c';
*)
(* Trying to Update the Content of Merge_Fields MMERGE6 which is a JSON OBJECT *)
(* Code from REST Debugger Returns No Errors but update fails *)
(* Note on Stackexchange mentions https://stackoverflow.com/questions/38388838/mailchimp-api-v3-add-member-to-list-with-merge-fields
*)
RESTRequest1.Method := TRestRequestMethod.rmPUT;
RESTRequest1.Params[0].Value:='{merge_fields: {"MMERGE6": "99999999"}}';
RESTRequest1.AddBody('{merge_fields: {"MMERGE6": "99999999"}}');
restrequest1.Execute;
end;
end.
Any help would be appreciated. THanks Phil