Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing Query string parameters in batch #179

Closed
Jafferwaffer opened this issue Feb 2, 2017 · 7 comments
Closed

Passing Query string parameters in batch #179

Jafferwaffer opened this issue Feb 2, 2017 · 7 comments

Comments

@Jafferwaffer
Copy link

Hello! I am having some issue with passing query string parameters in batch operations.
I have tried the following for creating an Operation (where I add the Operation to list to pass to the Operations property in BatchRequest)

operations.Add(new Operation
{
    Method =  "GET",
    Path = $"/lists/{listId}/members",
    Params = new {
        status = Status.Unsubscribed,
        since_last_changed = "2017-01-31",
        offset = 0,
        count = 20
    }
})

The response I get back from MC is [].
I also tried creating the Params object using the properties of MemberRequest as the Key but this gave me back all members.

After looking through BatchLogic I figured I should use GetResponseAsync as it uses a QueryableBaseRequest , however, the request passed in is immediately overwritten.

public async Task<BatchResponse> GetResponseAsync(QueryableBaseRequest request = null)
{
    request = new QueryableBaseRequest
    {
        Limit = base._limit
    };

    using (var client = this.CreateMailClient("batches"))
    {
        var response =
            await
                client.GetAsync(request?.ToQueryString() ?? string.Empty)
                    .ConfigureAwait(false);
        await response.EnsureSuccessMailChimpAsync().ConfigureAwait(false);
        var batchResponse = await response.Content.ReadAsAsync<BatchResponse>().ConfigureAwait(false);
        return batchResponse;
    }
}

How can I preform a GET request with the following route?

/lists/{listID}/members?status=unsubscribed&since_last_changed={lastChangeDate}&offset=20&count=20

I have tested using Postman that this route works for my listID and returns data.

@brandonseydel
Copy link
Owner

brandonseydel commented Feb 15, 2017

request = request ?? new QueryableBaseRequest
    {
        Limit = base._limit
    };

I will put this fix in when I am back to a computer

@brandonseydel brandonseydel self-assigned this Feb 15, 2017
@Jafferwaffer
Copy link
Author

Jafferwaffer commented Feb 15, 2017

Thanks 👍
I was testing batches in postman and found that they aren't correctly running when you try to pass in parameters. I have spoken to Mailchimp support and am awaiting a response from their API team.

@brandonseydel
Copy link
Owner

OK let me know what they say. The fix I suggested still needs to be implemented so I will leave this as a bug.

@Jafferwaffer
Copy link
Author

Mailchimp never got back to me, but it looks like they did fix passing in parameters with batches. They expect this form:

{"operations":[ {
	"method": "GET",
	"path": "/lists/{listId}/members",
	"params" : {
		"status" : "unsubscribed",
                "since_last_changed" : "2017-01-31T00:00:00+00:00",
                "offset" : 0,
                "count" : 20
	  }
  }]
}

@brandonseydel
Copy link
Owner

Is this working currently then or no?

@Jafferwaffer
Copy link
Author

Jafferwaffer commented Mar 10, 2017

Yes it is working, thank you. For anyone else having trouble make sure that the operation's parameter values are values that mailchimp would expect if you posted batch directly. Like so:

operations.Add(new Operation
{
    Method =  "GET",
    Path = $"/lists/{listId}/members",
    Params = new {
        status = "unsubscribed",
        since_last_changed = "2017-01-31",
        offset = 0,
        count = 20
    }
})

@github-actions
Copy link

github-actions bot commented Nov 2, 2021

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants