2

I am using the CustomValues Get API I would like to have the most recent entries listed first.

Is there a way that I can sort results in reverse when placing an API get?

For example, below I want to sort the values['217'] so that values['217']['10'] is the first. Here are the results I get:

{
"is_error": 0,
"version": 3,
"count": 1,
"id": 217,
"values": {
    "217": {
        "entity_id": "7088",
        "latest": "2016-11-01 00:00:00",
        "id": "217",
        "1": "2016-10-25 00:00:00",
        "2": "2016-10-18 00:00:00",
        "3": "2016-01-01 00:00:00",
        "4": "2016-01-01 00:00:00",
        "5": "2016-01-01 00:00:00",
        "6": "2016-10-27 00:00:00",
        "7": "2016-10-27 00:00:00",
        "8": "2016-10-27 00:00:00",
        "9": "2016-10-27 00:00:00",
        "10": "2016-10-27 00:00:00",
    }
}
}

Thanks!

3

Yes, you can, though it's not well-documented!

I recalled that there was some sort of "sort" option, which I confirmed by checked the Using the API documentation. However, the documentation is incomplete (I'll fix that in a minute).

Fortunately, I found the code that handles this, and saw that you can sort by various field options. See my screenshot below; I also confirmed that sorting by last_name desc also works. You should be able to sort by any field.

enter image description here

  • This is great. Thanks for finding this information. Unfortunately for my case the sorting needs to be for the results of a field that has multiple values. I don't think I can sort those values. I have updated my original question with the results that I currently get. – Sleewok Nov 1 '16 at 17:46
0

Per your comment, I see you want to know about reversing the order of multi-value custom fields. I don't think you can flip the return array directly. But if you're consuming it in PHP/JS/etc., you can iterate through the loop backwards. See https://stackoverflow.com/questions/10777597/reverse-order-of-foreach-list-items for a PHP example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.