mailjet / api-documentation

Mailjet API Guides
https://dev.mailjet.com/guides
22 stars 25 forks source link

How to remove filter/ segmentation from campaign via API? #18

Open franz-josef-kaiser opened 6 years ago

franz-josef-kaiser commented 6 years ago

Task

House cleaning to not end up in an unmaintainable state with left overs all over the place:

  1. Add a new /contactfilter resource
  2. Add the new contactfilter to a /campaigndraft resource
  3. Delete the contact filter
  4. (Maybe:) Remove it from the campaigndraft first?

(Note: This is a follow up during the work on #15 while testing setups).

Steps to reproduce

1. Create the filter

2. Attach the filter to a /campaigndraft resource

– Create a file named campaign-create.sh with the following contents:

    #!/usr/bin/env bash
    # @example sh campaign-create.sh $(cat mjkey) campaign.json
    # @example sh campaign-create.sh $(cat mjkey) campaign.json | jq # or: json_pp for pretty/ human-readable JSON format
    curl -sX POST https://api.mailjet.com/v3/REST/campaigndraft \
        --user "${1}" \
        -H "Content-Type: application/json" \
        -d @${2}

– Create a file named campaign.json with the following contents and substitute ContactsListID with the ID of an existing contacts list and segmentation ID :

            {
                    "Locale"         : "en_US",
                    "Sender"         : "API Testuser",
                    "SenderEmail"    : "test@example.com",
                    "Subject"        : "Hello, nothing to see here",
                    "Title"          : "Draft to serve as testcase for an attached segmentation.",
                    "ContactsListID" : 20070,
                    "SegmentationID" : 365
            }

3. Attempt to delete the filter again

Other attempts

I tried to remove the segmentation from existing /campaigndraft resources by updating the resource:

curl -s -X PUT --user $(cat mjkey) https://api.mailjet.com/v3/REST/campaigndraft/15056 -H 'Content-Type: application/json' -d '{"SegmentationID": "0"}' |jq

The response was the following:

{
  "ErrorInfo": "",
  "ErrorMessage": "Newsletter segmentation must match AXTesting.Segmentation",
  "StatusCode": 400
}

I then updated the AXTesting value as well:

curl -s -X PUT --user $(cat mjkey) https://api.mailjet.com/v3/REST/campaigndraft/15056 -H 'Content-Type: application/json' -d '{"SegmentationID": 0, "AXTestingID":0}' |jq

The response was the following:

{
  "Count": 1,
  "Data": [
    {
      "AXFraction": 0,
      "AXFractionName": "",
      "AXTestingID": 0,
      "ContactsListID": 20070,
      "CreatedAt": "2018-08-23T15:53:25Z",
      "Current": 94213,
      "DeliveredAt": "",
      "EditMode": "tool2",
      "ID": 15056,
      "IsStarred": false,
      "IsTextPartIncluded": false,
      "Locale": "en_US",
      "ModifiedAt": "2018-08-23T15:54:25Z",
      "Preset": "{}",
      "SegmentationID": 0,
      "Sender": "",
      "SenderEmail": "test@example.com",
      "SenderName": "Testuser",
      "Status": 0,
      "Subject": "FooBar",
      "TemplateID": 513130,
      "Title": "Ungarn–Kampagne",
      "Url": "",
      "Used": false
    }
  ],
  "Total": 1
}

Finally I tried to update the /contactsfilter value Status to unused:

curl -s -X PUT --user $(cat mjkey) https://api.mailjet.com/v3/REST/contactfilter/365 -H 'Content-Type: application/json' -d '{"Status":"unused"}' |jq

The response was the following:

{
  "ErrorInfo": "",
  "ErrorMessage": "Cannot change status from used to unused",
  "StatusCode": 400
}

Expected Outcome / Behavior

I expected to be able to do one of the following:

Questions:

adamyanliev commented 6 years ago

Hey @franz-josef-kaiser, apologies for the delay.

At the moment it's not possible to delete or modify a segment that was used in a sent campaign - a used contactfilter object is basically locked. The main reason behind this is to have consistent information for sent campaigns.

However, we're working on optimizing the segmentation feature as we speak. One of the new functionalities we're working on is a soft-delete of a used contactfilter, which will basically mark it as archived and it won't appear in the list of available segments. I can't give you an exact timeframe, but development on this project has already started.

Hope that helps :)

Regards, Atanas

franz-josef-kaiser commented 5 years ago

Hi @adamyanliev , do you have any update on this as there passed some time? :) Best!

adamyanliev commented 5 years ago

Hi @franz-josef-kaiser , sorry, there wasn't much development on this project - it was delayed to free up bandwidth for other projects. As soon as there's additional info, I'll post it here.

Regards, Atanas