Jericho / CakeMail.RestClient

.NET wrapper for the CakeMail API
MIT License
9 stars 3 forks source link

Post Data for SetCategory is invalid. #40

Closed beriniwlew closed 7 years ago

beriniwlew commented 7 years ago

When updating a category, it produces the following post data.

{
"user_key": "f8sd90f890sadf621",
"category_id": "20322",
"default": "1",
"templates_copyable": "1",
"label": {
"label0": "Category2"
},
"client_id": "621261"
}`

but it should be this

{
"user_key": "f8sd90f890sadf621",
"category_id": "20322",
"default": "1",
"templates_copyable": "1",
"label": [{
"label0": "Category2"
}],
"client_id": "621261"
}

Note that the labels should be an array.

I'm having an issue updating the templates as well.

Jericho commented 7 years ago

hmmmmmm.

The posted data is FormUrl encoded so it should look something like this:

user_key=...dummy USER key...&
category_id=111&
default=1&
templates_copyable=1&
label[en_US]=My Category&
label[fr_FR]=Ma Catégorie

I'm guessing you converted it to JSON so it's easier to visualize?

But anyway, as far as I know label[<label>]=<value>&label[<label>]=<value> is the correct syntax. That's how we send all arrays to the CakeMail API.

What is the error you're getting?

Jericho commented 7 years ago

I just compared how we handle the labels when creating a category with how we handle them when updating a category and I immediately noticed a difference:

when creating a category, here's the data we post to CakeMail:

label[0][language]=en_US&
label[0][name]=My Category&
label[1][language]=fr_FR&
label[1][name]=Ma Catégorie

as you can see the "language" and the "name" are handled separately.

This leads me to conclude that the way we handle labels when updating a category is wrong.