2

When I post a campaign on Mailchimp using RestSharp, it tells me my API key is missing, but when I click "Get Campaign", it successfully shows me all the campaign data.

Can anyone tell me where I'm going wrong? Here's my code:

public MailChimpPostModel PostCampaign(MailChimpPostModel post)
{
    var auth = _userBusinessObject.GetUserWebsiteAuthorizationByWebsite(_userId, 
                                                                   _websiteId,
                                                                   _linkvanaNetworkSiteId);
    ApiBaseUrl = <url> ;
    if (auth == null)
        throw new RestRequestResponseException { Error = RestErrorsEnum.NotAuthenticated };

    var request = new RestRequest(3.0/campaigns, Method.POST);
    request.AddParameter("access_token", <Token>);
    request.AddParameter("apikey", <Token> + "-" + <dc>);
    request.AddHeader("content-type", "application/json");
    request.AddBody(post);
    var response = Execute<MailChimpPostModel>(request);
    return response;
}
ekad
  • 14,436
  • 26
  • 44
  • 46
  • I've improved the grammar and formatting of this post a bit - hopefully it'll make it easier for others to answer you. – StackExchange What The Heck Feb 17 '16 at 17:33
  • Maybe there is a typo? change: request.AddParameter("apikey", + "-" + ); to: request.AddParameter("apikey", + "-" + ); – Daniel Feb 17 '16 at 18:14
  • Does AddParameter add to the querystring? If so, that's the problem. That's not a supported authentication method for POST. It's only enabled for GET to make debugging a little easier. You'll want to use HTTP basic auth. – TooMuchPete Feb 18 '16 at 14:22

1 Answers1

2
// replace usX to match the last 3 of your API
var client = new RestClient("https://usX.api.mailchimp.com/3.0/");
client.Authenticator = new HttpBasicAuthenticator("user", APIKey);
BillH
  • 46
  • 3