Help

API - encoding sort URI with multiple sort fields / directions

Topic Labels: Extensions
902 0
cancel
Showing results for 
Search instead for 
Did you mean: 
kirkbross
5 - Automation Enthusiast
5 - Automation Enthusiast

I’m trying to build a sort URI with multiple sort fields and directions, but I don’t understand the syntax. Suppose I have this sort object with three fields/directions:

const sort = [
  { field: "title", direction: "asc" },
  { field: "value", direction: "desc" },
  { field: "category", direction: "asc" }
];

//I thought I could just daisy chain them like this, but it doesn't work.

let sortUri;

sort.forEach(sort => {
  console.log(sort.field, sort.direction);
  sortUri += `&sort%5B0%5D%5Bfield%5D=${encodeURIComponent(
    sort.field
  )}&sort%5B0%5D%5Bdirection%5D=${sort.direction}`;
});

const url = `&filterByFormula=AND(FIND(%221000%22%2C%20%7BLocation%7D)%20%3E%200%2CAND(%7BValue%7D%20%3C%2010000000))${sortUri}`;
0 Replies 0