Join to mailing list from iOS application using "Creating a Contact" api ERR_403_DEVELOPER_INACTIVE

SOLVED
Go to solution
iOSD
Regular Participant

Join to mailing list from iOS application using "Creating a Contact" api ERR_403_DEVELOPER_INACTIVE

Hello everyone. I want to integrate feature of "join mailing list". I check the API docs & found this api http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST

 

I am using this api in iOS application with below paramters

 

{
    "action_by" = "ACTION_BY_OWNER";
    "api_key" = <my_api_kay>;
    "email_addresses" =     (
                {
            "email_address" = "abcd@gmail.com";
        }
    );
    lists =     (
                {
            id = 1;
        }
    );
}

 

But evertime it gives me below error

 

{ status code: 403, headers {
    Connection = "keep-alive";
    "Content-Length" = 168;
    "Content-Type" = "application/json";
    Date = "Thu, 17 Oct 2013 08:12:16 GMT";
    Server = "Mashery Proxy";
    "X-Mashery-Error-Code" = "ERR_403_DEVELOPER_INACTIVE";
    "X-Mashery-Responder" = "prod-j-worker-us-east-1c-37.mashery.com";
} }, NSLocalizedDescription=Request failed: forbidden (403)}

But on my dashboard  api key status is active.

 

Also I found iOS library from GitHub for ConstantContract https://github.com/constantcontact/ios-sdk But this ask me login which I don't want . Can I use this library for joining the mailing list ?

 

Thanks

1 ACCEPTED SOLUTION

Your URL is incorrect.  Looks like the URL control parameters (?, &, =) are all being incorrectly encoded.  It should be:

 

https://api.constantcontact.com/v2/contacts?Fapi_key={API_KEY}&action_by=ACTION_BY_OWNER

 

The line that is doing this is:

 

query = [query urlEncodeUsingEncoding:NSASCIIStringEncoding];

 

The key/value pair content does need to be URL encoded, for example your API key, not the entire query string.  Otherwise, the contents are treated as part of the end of the URL. 

Dave Berard
Senior Product Manager, Constant Contact

View solution in original post

11 REPLIES 11
IOSD9
Participant

I am waiting for reply , any body from constant contact ? Why I am  getting "ERR_403_DEVELOPER_INACTIVE" continuously ?

Could you provide your API key via email or a private message?  It could be that your API key is in waiting status or needs to be updated.

Dave Berard
Senior Product Manager, Constant Contact
iOSD
Regular Participant

I just sent you a private message with details .

The API key is set up correctly.  Can you confirm that the URL that is making the request is formatted correctly when the request is going out in iOS?  Any typos or additional characters will cause this to fail.

Dave Berard
Senior Product Manager, Constant Contact
iOSD
Regular Participant

Thanks for reply & checking the api key.

Along with the json mentioned above , I am sending below paramters

URL: https://api.constantcontact.com/v2/contacts


Below values are set in the HTTP Header

 

Authorization: Bearer <my authorization token>
Content-Type:application/json

Is there anything that I am missing while making the request ?

I am getting below reply

 

Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: forbidden (403)" UserInfo=0x16e08c80 {NSErrorFailingURLKey=https://api.constantcontact.com/v2/contacts, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x16d60340> { URL: https://api.constantcontact.com/v2/contacts } { status code: 403, headers {
    Connection = "keep-alive";
    "Content-Length" = 168;
    "Content-Type" = "application/json";
    Date = "Fri, 25 Oct 2013 08:34:31 GMT";
    Server = "Mashery Proxy";
    "X-Mashery-Error-Code" = "ERR_403_DEVELOPER_INACTIVE";
    "X-Mashery-Responder" = "prod-j-worker-us-east-1c-37.mashery.com";
} }, NSLocalizedDescription=Request failed: forbidden (403)}

 

You do have to append your API key to the request URL in order to identify yourself on the request.  Here is our documentation on that piece:  http://developer.constantcontact.com/docs/developer-guides/general-considerations.html

 

Not sure from your response if you're doing that or not, but that would definitely result in a Mashery proxy error as you would be blocked out of hand for not having a valid API key on your request.  Can you check to make sure that is being appended?

Dave Berard
Senior Product Manager, Constant Contact
iOSD
Regular Participant

Thanks for pointing me to documentation. I am sending the api_key in every api request. Here is my code

-(void)joinMailingList
{
    NSDictionary *dictList = @{@"id": @"1"};
    NSArray *arrayList = @[dictList];
    NSDictionary *dictEmailAdd = @{@"email_address":@"abcd123@gmail.com"};
    NSArray *arrayEmailAdd = @[dictEmailAdd];
    
    NSDictionary *parameters = @{@"lists":arrayList,
                                 @"email_addresses":arrayEmailAdd
                                 };
 
    NSString *query = [NSString stringWithFormat:@"contacts?api_key=abcd1234&action_by=ACTION_BY_OWNER"];
    query = [query urlEncodeUsingEncoding:NSASCIIStringEncoding];
    
    [[MailListApiClient sharedAPIClient]POST:query  parameters:parameters
    success:^(NSURLSessionDataTask *task, id responseObject)
    {
        NSDictionary *response = [NSJSONSerialization JSONObjectWithData&colon;responseObject options:0 error:nil];
        NSLog(@"Success::MailingList response : %@", response);
    }
    failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"Error::MailingList response : %@", error);
    }];
}

#define kBASE_URL   @"https://api.constantcontact.com/v2/"

+ (MailListApiClient *)sharedAPIClient
{
    static MailListApiClient *sharedClient = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedClient = [[MailListApiClient alloc] initWithBaseURL:[NSURL URLWithString:kBASE_URL]];
    });
    return sharedClient;
}

- (id)initWithBaseURL:(NSURL *)url {
    
    self = [super initWithBaseURL:url];
    if (!self) {
        return nil;
    }
    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
    self.requestSerializer = [AFJSONRequestSerializer serializer];
    [self.requestSerializer setValue:@"Bearer <my token value>" forHTTPHeaderField:@"Authorization"];
    [self.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    return self;
}

 Here is the resposne that I am getting

 

Error::MailingList response : Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: forbidden (403)" UserInfo=0x14d4b220 {NSErrorFailingURLKey=https://api.constantcontact.com/v2/contacts%3Fapi_key%3Dabcd1234%26action_by%3DACTION_BY_OWNER, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x14e78290> { URL: https://api.constantcontact.com/v2/contacts%3Fapi_key%3Dabcd1234%26action_by%3DACTION_BY_OWNER } { status code: 403, headers {
    Connection = "keep-alive";
    "Content-Length" = 168;
    "Content-Type" = "application/json";
    Date = "Mon, 28 Oct 2013 05:10:12 GMT";
    Server = "Mashery Proxy";
    "X-Mashery-Error-Code" = "ERR_403_DEVELOPER_INACTIVE";
    "X-Mashery-Responder" = "prod-j-worker-us-east-1b-30.mashery.com";
} }, NSLocalizedDescription=Request failed: forbidden (403)}
2013-10-28 10:40:02.737 TestApp[3100:60b] 403 'https://api.constantcontact.com/v2/contacts%3Fapi_key%3Dabcd123%26action_by%3DACTION_BY_OWNER' [nan s]

 Not sure whats going wrong in above code. Is my below url correct ?

https://api.constantcontact.com/v2/contacts%3Fapi_key%3Dabcd1234%26action_by%3DACTION_BY_OWNER

As per docs api_key  & action_by are query type. So I send it in quesry parameters & remaining parameters in POST body.

 

Please let me know your feedback.
 Thanks.

Your URL is incorrect.  Looks like the URL control parameters (?, &, =) are all being incorrectly encoded.  It should be:

 

https://api.constantcontact.com/v2/contacts?Fapi_key={API_KEY}&action_by=ACTION_BY_OWNER

 

The line that is doing this is:

 

query = [query urlEncodeUsingEncoding:NSASCIIStringEncoding];

 

The key/value pair content does need to be URL encoded, for example your API key, not the entire query string.  Otherwise, the contents are treated as part of the end of the URL. 

Dave Berard
Senior Product Manager, Constant Contact

View solution in original post

iOSD
Regular Participant

As per your instruction , I made changes in my code. Now I am encoding the url parameter values only & not the whole url.
Now I am getting the expected result & given email address is successfully added in my list.
Thanks a ton for your kind support & help that you provided . :) :) :)

Just a quick question , do I need to encode the action_by paramter value as well ? Is it necessary ?

Also in your last reply , I can see the api_key. Can you replace it with dummy api_key as no one will misuse it . I forgot to change it while adding comment. I made changes in my comment but I can not modify your comment.

Updating my comment now, good catch!  Usually I'm the one who has to catch those.  Glad things are working for you.

 

Technically, any query parameter key/value pair should be encoded.  However, since action_by is just a string of characters and never contains any reserved characters you won't need to waste the processing on it.  It's really a six in one, half dozen in the other scenario though since the processing cost is so low.

Dave Berard
Senior Product Manager, Constant Contact
iOSD
Regular Participant

Thanks for updating your comment. I really appreciate your help in this issue. Thank you very much. :)

Developer Portal

View API documentation, code samples, get your API key.

Visit Page