API is returning blank subject for A/B Test campaign
miroslaviskrenovlefterov opened this issue · 1 comments
Dear majljet-gem team, we are encountering the following issue.
Description:
What we actually want to acheive: we're sending out the newsletter on a weekly basis. Every week, nearly 500k users are receiving the newsletter. This is done via the Main API key in Mailjet UI. A person is creating the campaign and the template there. Once that's done and the newsletter is on its way to the customers, we need to ensure, that every new subscription is getting the latest newsletter. This is a little tricky, but we managed it like this: we are "star"ring (marked as "starred") the newsletter in the main API Key account. Along with that, he's creating a new transactional template in the "Transactional Mails" Sub account. We were told to use a different sub account in order to use a different public IP to send out transactional mails. What our code does at the moment: 1. fetching the "star"red campaign from the Main API account; 2. fetching the subject from the result; 3. finding the corresponding transactional one in the other transactional sub account; 4. triggering this transactional mail to the very new subscriber; Since last week, we're doing a/b tests and things started to be different. I fully understand, that we might have different subjects in version A and B. However, we need to find a way to send the latest newsletter (a.k.a the winning version of the last newsletter campaign) to new subscribers. How can we achieve this?
In our workflow we need to take parameters from the last starred campaign. Our last campaign was an A/B test, and when we try to locate it through the Ruby console, the API is returning result empty subject:
>> Mailjet::Campaignoverview.all(starred: true).last
=> #true, "clicked_count"=>3160, "delivered_count"=>269997, "edit_mode"=>"unknown", "edit_type"=>"unknown", "id"=>30993, "id_type"=>"AX", "opened_count"=>18763, "processed_count"=>487723, "send_time_start"=>1559914208, "starred"=>true, "status"=>4, "subject"=>"", "title"=>"KW201923"}>
Because of this, our subsequent mail-sending fails, because subject is required field.
Response from Majljet Support Team:
The fact that there is no subject populated from the /campaignoverview endpoint for the A/B tests is indeed an expected behaviour. The reason is that this resource is returning an overview of the whole A/B test and in it there are multiple campaigns that can have different subjects. That\'s why in the API response received the \"Subject\" field is always empty for this type of mails.
- make a GET request on /campaign with filter \"Sort=SendEndAt+DESC\" and \"FromType=2\" in order to get the last campaign on first place and get the ID after \"mj.nl\" from the \"CustomValue\" field;
- once you have this ID, you can retrieve the content of the mail by using the resource /campaigndraft/{draft_ID}/detailcontent:
https://dev.mailjet.com/reference/email/campaigns/drafts/#v3_get_campaigndraft_draft_ID_detailcontent
- you can then send this HTML-part as a transactional mail from the other sub-account.
Please take a look at the attached screenshot. The first result from the screenshot is the result finding the campaign with "FromType=2" and latest "send_end_at". How can I "get the ID after \"mj.nl\" from the \"CustomValue\" field", I cannot understand which fields should I looking for? The second result is the Campaigndraft (https://github.com/mailjet/mailjet-gem/blob/master/lib/mailjet/resources/campaigndraft.rb). It fails for every call I do with the details provided in the screenshot.
So currently we are not sure how to proceed to get the correct subject. The suggestion from Majljet Support Team is not giving a result because of the above issues. Please advise.
Note: Just for clarification, everything related to creating campaigns and A/B test is done by Mailjet UI. We do not create anything manually. We are just consuming the information using the API gem.
Please advise.
Fixed in v1.6.0