简体   繁体   English

Mailchimp API 使用 Delphi REST 放置或修补

[英]Mailchimp API Put or Patch using Delphi REST

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.我有一个程序可以通过 API 连接到 mailchimp 并下载数据,我现在需要能够更新某些 email 地址并添加新地址。 Within the Mailchimp layout I have a custom Merge field called在 Mailchimp 布局中,我有一个名为的自定义合并字段

MMMERGE6 which is a text field. MMMERGE6 这是一个文本字段。

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.我尝试在 REST 调试器中构建请求,尽管 rest 调试器没有返回错误,但更新似乎没有发生。 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.我在 stackoverflow 上的某处发现了一篇文章,该文章说 mailchimp 存在一个问题,与帖子内容需要在哪里以及如果它在错误的位置它失败有关。

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谢谢菲尔

I tried this again today and changed the request to a Put request.我今天又试了一次,并将请求更改为 Put 请求。

mystring:='{ "merge_fields": { "MMERGE6":  "39999999"  } }';




restrequest1.Body.Add(mystring);
restrequest1.Execute;

I also double quoted the variable names as well and it now works !我也双引号了变量名,它现在可以工作了!

I have not tried doing as a put as this achieves my desired result of allowing me to update a record and also insert a new one.我没有尝试做一个 put,因为这实现了我想要的结果,即允许我更新记录并插入新记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM