Trying to sort a list of addresses in an optimized pick up order using an external API integration

Okay so now we need to built that into an array.

So first use a Merge Values step, and merge the new Flightmap column you made that contains the objects. Merge them using a comma as the delimiter, and do not add any grouping column to the second set of settings. This will group all of the objects into a single cell.

Let’s assume that new column where the merge took place is called Flightmap Merged

You can then use either an API Enrichment step or an API Export step to make the request.

In that request body, you will define all the other fields that you want, and you will merge in the Visits array innards like this:

{
  "visits": [{Flightmap Merged}],
  "fleets": [
    {
      "id": "78277",
      "capacity": 10,
      "start_location": {
        "lat": 30.7188978,
        "lng": 76.8102981,
        "name": "CDCL, Madhya Marg, 28B, Sector 28B, Chandigarh, India"
      },
      "return_to_Start": false,
      "end_location": {
        "lat": 30.70549299999999,
        "lng": 76.8012561,
        "name": "Elante Mall, Purv Marg, Industrial Area Phase I, Chandigarh, India"
      },
      "shiftEnd": 2345
    },
    {
      "id": "78278",
      "capacity": 10,
      "start_location": {
        "lat": 30.7188978,
        "lng": 76.8102981,
        "name": "CDCL, Madhya Marg, 28B, Sector 28B, Chandigarh, India"
      },
      "return_to_Start": false,
      "end_location": {
        "lat": 30.70549299999999,
        "lng": 76.8012561,
        "name": "Elante Mall, Purv Marg, Industrial Area Phase I, Chandigarh, India"
      },
      "shiftEnd": 2345
    }
  ]
}

And you can set the fleet information to be whatever you need it to be!

The main difference with your two step options are that the Enrichment will run in your builder as you use it. So changes made upstream will re-send those requests, and the response will be added to your dataset. Whereas the Export will only run when you publish and run the flow, and will not show you the response data (besides errors and things like that).

Okay, I am actually trying to set it up with both enrichment and API export. I have edited the body text to only include one fleet because that is all I have, and I tried to export and enrich using this set up. I received an error saying the JSON is not valid.

Looks like you got the JSON issue resolved, which was some trailing commas. But now I think your API token is not being sent correctly. Trying to figure out how they want the token sent.

When they sent you the API Key, did it tell you what the name of the header should be?

I believe there is a new issue now. The error message reads: java.lang.Long cannot be cast to java.lang.String

The header is authorization

Hmm that is odd. That is an error coming back from their API, but I don’t think it’s an error they mean to send back to a request. Can you click the refresh icon in the top right of the API Enrichment to try the request again? Maybe just it was a passing error

I still get the same error. Strange.

That’s a bummer after all of this! Can you shoot them an email about the error? I will send you an email with some details about what you can tell them about the request

Just sent them an email. I will let you know what happens.

Thank you so much for all of your help, I really appreciate it.

Brian,

The customer support from Jungleworks emailed me back fairly quickly and we identified the error and fixed it. The build is now working perfectly and will help my business and me so much.

Thank you so much for helping me throughout many hours today, I really appreciate it.

4 Likes

Glad that you got this working!

1 Like