mailjet / mailjet-apiv3-java

[API v3] Mailjet Java API Wrapper
https://dev.mailjet.com
MIT License
66 stars 36 forks source link

Monitoring the upload of multiple contacts: 404 Object not found #66

Closed GregoryEstienne closed 8 years ago

GregoryEstienne commented 8 years ago

Hi Guillaume!

I am trying to monitor the process of uploading contacts and their subscription to contact lists (I am managing contact lists of around a thousand of contacts), but the sample code (https://dev.mailjet.com/guides/?java#monitoring-the-upload-of-multiple-contacts) does not seem to work on my side.

The java code: I provide the "JobID", returned by the previous "post" request, as parameter like documented:

request = new MailjetRequest(ContactManagemanycontacts.resource, 'actionid');
response = client.get(request);

It seems the request in JSON does not put the "JobID" in the "Action ID" field!? Maybe I'm wrong. Maybe the sample code is incorrect... My request: {"Filters":"{}","Body":"{}","Resource":"contact","Action":"managemanycontacts","ID":4370704,"Action ID":0} The response: {StatusCode=404, ErrorInfo=, ErrorMessage=Object not found}

Thanks for your help!

WeshGuillaume commented 8 years ago

Hey ! That was a tricky one.

Usually, the Mailjet resources are formatted this way: /resource/id/action/actionID, This one is different, I assume the request that was sent in your case was /contact/actionid/managemanycontacts

Anyway, It should be fixed

Thanks for reporting this/these issue(s) :smile:

GregoryEstienne commented 8 years ago

Hi Guillaume,

Thanks!

The method works fine now!

I don't know if it is a side effect of your latest changes but now I get an error when I delete my contact lists. Before the latest update of the jar I didn't get this error: code: MailjetRequest request = new MailjetRequest(Contactslist.resource, aContactListId); MailjetResponse response = mailjetClient.delete(request); request JSON: {"Action":"","Filters":"{}","Action ID":0,"Resource":"contactslist","ID":10536,"Body":"{}"} error: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

On another subject, what is the best place to ask questions about the API? Like how to filter resources in my requests: I would like to get all newsletters that are not archived or deleted for instance? Do I need to get all the newsletter then sort them on their status myself? Is there a better way?

Thank you again for your help!

PS: I can close this issue now, but in order to allow you to respond I keep it opened. Just tell me if you want that I open another issue for my "delete error".

GregoryEstienne commented 8 years ago

I just realize a more serious problem: the service does not return any campaign at all now, while I can see five of them at https://app.mailjet.com/campaigns!

WeshGuillaume commented 8 years ago

Can you print what happen when you use the debugMode client.setDebug(MailjetClient.VERBOSE_DEBUG); ?

GregoryEstienne commented 8 years ago

For the "delete error":

=== HTTP Request === DELETE https://api.mailjet.com/v3/REST/contactslist/10659? Accept-Charset:UTF-8 Accept:application/json user-agent:mailjet-apiv3-java/v3.1.0 === HTTP Response === Receive url: https://api.mailjet.com/v3/REST/contactslist/10659? Status: 204 null:HTTP/1.1 204 No content Server:nginx Connection:keep-alive Date:Tue, 15 Mar 2016 18:47:40 GMT Content-Type:application/json Content:

2016-03-15 14:47:40.243 ERROR 860420 --- [ main] c.n.c.mailjet.MailjetClientService : A JSONObject text must begin with '{' at 1 [character 2 line 1]

org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] at org.json.JSONTokener.syntaxError(JSONTokener.java:433) ~[json-20140107.jar:na] at org.json.JSONObject.(JSONObject.java:194) ~[json-20140107.jar:na] at org.json.JSONObject.(JSONObject.java:321) ~[json-20140107.jar:na] at com.mailjet.client.MailjetClient.delete(MailjetClient.java:231) ~[client-3.0.0.jar:3.0.0]

Even if the operation is correctly interpreted: the status is 204.


For the "Get Campaigns" case:

=== HTTP Request === GET https://api.mailjet.com/v3/REST/campaign? Accept-Charset:UTF-8 Accept:application/json user-agent:mailjet-apiv3-java/v3.1.0 === HTTP Response === Receive url: https://api.mailjet.com/v3/REST/campaign? Status: 200 null:HTTP/1.1 200 OK Server:nginx Connection:keep-alive Content-Length:41 Date:Tue, 15 Mar 2016 18:44:11 GMT Content-Type:application/json Content: { "Count" : 0, "Data" : [], "Total" : 0 }

GregoryEstienne commented 8 years ago

I guess I was dreaming when I thought I could retrieve all campaigns in a get request! I guess it is impossible?

I found another way to get the data that interest me... Forget about the problem of the "Get All Campaigns"!

WeshGuillaume commented 8 years ago

Ok, so the API doesn't seem to respond with a content and the wrapper is expecting a JSON object here, so your contactlists is deleted right ?

I'm going to add a condition is there no content back on a delete

WeshGuillaume commented 8 years ago

I added the following to prevent empty response to throw exceptions: https://github.com/mailjet/mailjet-apiv3-java/blob/master/src/main/java/com/mailjet/client/MailjetClient.java#L229

Here is the result

screen shot 2016-03-16 at 11 29 13
GregoryEstienne commented 8 years ago

Thank you Guillaume!

Everything seems to be working fine now.