Skip to main content

I’ve been working with Shippo, which offers a shipping API for creating labels, tracking, and address verification. I set it up a REST interface quite easily, and was able to get most standard operations working well. The problem I have is when it comes to multi-piece shipments which requires that I post an array of ‘parcels’. Let me explain.


Shippo has you create a To Address object, a From Address object, and a Parcel object (with dimensions & weight). Once created each is given an Object ID. To create the shipment you just supply all three object IDs and the shipment is created. Here is what it looks like basically.




Pretty simple. But if you want to send multi-piece shipments you have to supply an array of Parcel object IDs, formatted like this ‘object_id’, ‘object_id’]. No problem creating that string, but there is an issue with the JSON generated from Skuid.


Here is what is required.


{


"object\_purpose": "PURCHASE",

“address_from”: “4f406a13253945a8bc8deb0f8266b245”,


“address_to”: “4c7185d353764d0985a6a7825aed8ffb”


“parcel”: f“3b1e9b81ef92451c9e613a82128988d5”, “6a2f479f1b1c43dfb9d98234ed720e47”],


"async": false

}


But instead Skuid is adding extra Quotations around the parcel list. Which makes sense because it thinks it is sending a simple text field, like below…


{


"object\_purpose": "PURCHASE",

“address_from”: “4f406a13253945a8bc8deb0f8266b245”,


“address_to”: “4c7185d353764d0985a6a7825aed8ffb”


“parcel”: " 7“3b1e9b81ef92451c9e613a82128988d5”, “6a2f479f1b1c43dfb9d98234ed720e47”] ** "** ,


"async": false

}


This results in an error with the external data source, it isn’t expecting the extra quotes. So finally my question. Thanks if you made it this far.


Is there a way to prevent Skuid from adding the extra quotes around the ‘array’ of object IDs? Anyway to prevent it from treating it as a string and putting it in quotes at all? Or is there a way to custom specify the JSON post with a snippet?


Really appreciate any help with this. I’ve been following this community for some time now, just my first time posting.


Andy

In the Model, what is the field’s Display Type? Is the Display Type set to Text, or Array?


It is Text. I do not have Array as an option for display type. 


Okay, that makes sense - I think Array is not presented as an option unless the field is identified as an Array during initial parsing of the REST query’s sample response. If you View/Exit XML for the page, and find the corresponding Model Field’s XML node, you can change the “displaytype” to ARRAY. Try that and see if that changes how Skuid sends the data to the data source.


Hmm… tried that. I get an error…  ‘TypeError: invalid ‘in’ operand a’ 



Did this item get resolved? I believe I’m running into a similar issue. I’m working on a REST chatter POST, which requires multiple Arrays to be passed in and the nodes in the array not being wrapped in brackets:




The messageSegments and capabilities nodes should be presented as arrays. I have them setup in the model as such, but they aren’t wrapping correctly. When I do a query on the same model, the response is returned in the correct format, so this looks isolated to the post method.


Here’s the model definition:


    <model id="NewModel" query="true" createrowifnonefound="true" datasource="SalesforceRest" processonclient="true" type="readwrite" fieldtargetobjects="elements">
<fields>
<field id="capabilities.files.items.id" displaytype="TEXT"></field>
<field id="visibility" displaytype="TEXT"></field>
<field id="feedElementType" displaytype="TEXT"></field>
<field id="capabilities.files.items" displaytype="ARRAY"></field>
<field id="subjectId" displaytype="TEXT"></field>
<field id="body.messageSegments.type" displaytype="TEXT"></field>
<field id="body.messageSegments.text" displaytype="TEXT"></field>
<field id="body.messageSegments" displaytype="ARRAY"></field>
</fields>
<conditions></conditions>
<actions></actions>
<methods>
<method type="insert" verb="POST" endpoint="/chatter/feed-elements/" pathtocontent="elements" successif="requestsucceeds" sendchanges="asjsoninbody" insertresponse="recordinbody"></method>
<method type="query" verb="GET" endpoint="/chatter/feed-elements/?q=template" pathtocontent="elements" fieldtargetobjects="elements"></method>
</methods>
</model>

Reply