API Response / Multi-dimensional arrays

Hi there

I am totally new to bubble, but I have some years in traditional programming under the belt. What I am struggling with is the handling of API responses.

I want the user to enter an URL and the query then FreeAPI from BuiltWith.com - it returns a multidimensional array with information about a website for instance “technologies used”.

Now in PHP I would take the API response object, iterate over the Object Items (or Array Lists) and write each of it into a table “Tech” and reference it to a table “Websites”.

This way I would get back something like

| UID | Website                 |
+-----+-------------------------+
|  1  | ibm.com                 |
+-----+-------------------------+

and

| Website UID       |  Tech            |
+-------------------+------------------+
| 1                 | Jquery           |
| 1                 | Analytics        |
| 1                 | Magento          |
+-------------------+------------------+

Now with bubble I seem to be lost already at the conceptual level. How do I iterate over the result objects list? Some like FOR EACH… Or how do I implement a conditional (if entry does not exist then…)

I spent the better part of last night reading the reference, documentation, searching the forum or watching videos - but still not sure I am looking in the right direction.

Hi steven4,

Nice to see a fellow user of BuiltWith.com, awesome platform!

I struggle with a similar issue as you: on how to handle an API response that contains an array of items. I’m integrating Bubble with some UPS-API’s.

Have you been able to find ways to achieve this?
I’ll keep trying and reply to this thread when I do find answers.

So I think I have found a solution, for my issue anyway. Maybe this helps you too, steven4, or perhaps other Bubble users that want to work with API responses that contain arrays of things. I’ll explain it briefly here and if anyone would need more explanation please reply.

So in my case I want to know what pricing options there are for a UPS-shipment by using their rates api. Their api responds with a JSON that contains multiple service codes with different pricing. So in order to do something useful with this array I have done this:

  • Setup an API connection through default bubble API-plugin (in my case a POST)
  • Initiate the call, and in my case I can see an array like so:
  • Create a data type ‘shipment’
  • Create fields for both the service code and rate, and make sure to select field type ‘text’ and select ‘this field is a list’
  • In my case I make a change to a thing (Shipment) and for the servicecode and rate I can now select a datafield from the nested array like so:
    rateresponse
  • Now in the data editor you see these kind of lists, which doesn’t look too useful:
    app data
  • But now we can use this data in a repeating group and even start workflows etc for each particular item in this group!
  • My settings for the repeating group look like this: first you set type of content to the nested array from your API:
  • The data source you keep empty for now
  • Put a field in the repeat group and point to current cell’s whatever you need in your case. for me it’s this:
  • And finally for me in the workflow editor I do this: I display a list in the repeating group and use the result of the previous API step as data source:

Now I can view the different responses from the API in the repeating group and do all sorts of cool things with each separate response :smiley:

I hope this helps you (or anyone else) with your issue. Otherwise let me know :smiley:

1 Like

Hey! Thanks for your post. I am having a similar problem. Could you post your API Connector body text to see how to format the list in en body?
I connected to my accounting platform and i am trying to make a call to create an invoice. I have a required field called ProductLines which is a list. And each productlines has some required fields, (Quantity, Amount, Description, Discount) But isimply cant find a guide to fill in those arrays. Can you help?
Kindly
Emil

Hi Emil,

Do you have API-docs for your accounting platform?
I’ve used examples from the UPS API docs to get to something like this:

Blockquote {
“RateRequest”: {
“Request”: {
“Subversion”: “1801”,
“TransactionReference”: {
“CustomerContext”: " "
}
},
“Shipment”: {
“DeliveryTimeInformation”:{
“PackageBillType”:“03”,
“Pickup”:{
“Date”:“”,
“Time”:“”
}
},
“Shipper”: {
“Name”: “<Shipper_Name>”,
“ShipperNumber”: " ",
“Address”: {
“AddressLine”: “<Shipper_AddressLine>”,
“City”: “<Shipper_City>”,
“StateProvinceCode”: “<Shipper_StateProvinceCode>”,
“PostalCode”: “<Shipper_PostalCode>”,
“CountryCode”: “<Shipper_CountryCode>”
}
},
“ShipTo”: {
“Name”: “<ShipTo_Name>”,
“Address”: {
“AddressLine”: “<ShipTo_AddressLine>”,
“City”: “<ShipTo_City>”,
“StateProvinceCode”: “<ShipTo_ProvinceCode>”,
“PostalCode”: “<ShipTo_PostalCode>”,
“CountryCode”: “<ShipTo_CountryCode>”
}
},
“ShipFrom”: {
“Name”: “<ShipFrom_Name>”,
“Address”: {
“AddressLine”: “<ShipFrom_AddressLine>”,
“City”: “<ShipFrom_City>”,
“StateProvinceCode”: “<ShipFrom_ProvinceCode>”,
“PostalCode”: “<ShipFrom_PostalCode>”,
“CountryCode”: “<ShipFrom_CountryCode>”
}
},
“Service”: {
“Code”: “<UPS_Service>”
},
“ShipmentTotalWeight”: {
“UnitOfMeasurement”: {
“Code”: “KGS”,
“Description”: “Kilograms”
},
“Weight”: “<Colli_weight>”
},
“Package”: {
“PackagingType”: {
“Code”: “<Package_Code>”
},
“Dimensions”: {
“UnitOfMeasurement”: {
“Code”: “CM”
},
“Length”: “<Colli_length>”,
“Width”: “<Colli_width>”,
“Height”: “<Colli_height>”
},
“PackageWeight”: {
“UnitOfMeasurement”: {
“Code”: “KGS”
},
“Weight”: “<Colli_weight>”
}
}
}
}
}

Is that of any use for you?
I’m happy to help you find your way with the API-connector!

Hi! Thanks for your reply.
Íf you want to check it out the documentation is right here:
https://api.dinero.dk/docs
https://api.dinero.dk/openapi/index.html#tag/Invoices/paths/~1v1~1{organizationId}~1invoices/post
Im trying to perform a POST call named Create Invoice. Should be pretty simple.
Authentication is giving me some issues also, since the token times out after a certain time. Ive read that it can be solved with use of Custom Token, but i can figure out how to set it up.
Note that i am pretty new to setting up these api call.

I performed a get call succesfully by first performing a “get token” call and then using the key returned to perform the get call.

Many thanks!
Emil

Hi Emil,

Yeah learning how the authentication stuff works can be pretty time consuming / frustrating!

So what I usually do is to first try my API-calls out in a tool called Postman. This way I am sure that I get the requests going with the least amount of effort. This can save you some headache.
Then when you get it to work in Postman, you try to recreate your requests in Bubble with the API plugin.

The docs you posted have a pretty clear example to create an invoice:

Blockquote
{
“Currency”: “DKK”,
“Language”: “en-GB”,
“ExternalReference”: “Fx. WebshopSpecialId: 42”,
“Description”: “Description of document type. Fx.: invoice, credit note or offer”,
“Comment”: “Very very important comment”,
“Date”: “2020-12-02”,
“ProductLines”: [
{
“ProductGuid”: “172d15a7-cb1a-4acd-bff4-0d34f8396ff0”,
“Description”: “Flowers”,
“Comments”: “Smells good”,
“Quantity”: 5,
“AccountNumber”: 1000,
“Unit”: “parts”,
“Discount”: 10,
“LineType”: “Product”,
“BaseAmountValue”: 20
}
],
“Address”: “Test Road 3 2100 Copenhagen Denmark”,
“ShowLinesInclVat”: false,
“InvoiceTemplateId”: “44f03117-ac37-48a3-a433-3c96413789e6”,
“ContactGuid”: “06a76c1e-3a07-462c-bf18-4cd7b8ddab65”,
“PaymentConditionNumberOfDays”: 8,
“PaymentConditionType”: “Netto”
}

https://api.dinero.dk/openapi/index.html#tag/Invoices/paths/~1v1~1{organizationId}~1invoices/post

This request would need the bearer token in the header as stated here:

Usage

After obtaining an access token, you append it on every request using the following header: Authorization: Bearer [access_token]

Where [access_token] should be replaced with the token you just received.

Core resources on the left show API and description of all available endpoints

Could you try such a request in Postman and see if it works? And if it doesn’t work report with the response with maybe the error message?

Hi Jelle!
Sorry I havent seen your reply until now!

Authentication is alright, i managed to get through, but im doing it with a GET call to get the token and then using the token manually in the header of the post call in create invoice.

Im receiving this error: {“type”:“https://tools.ietf.org/html/rfc7231#section-6.5.13”,“title”:“Unsupported Media Type”,“status”:415,“traceId”:“0HM54DF0VE4I0:00000038”}
So im guessing there is something wrong with the parameters im posting. Thats why i was looking for a sollution on how to set the variable parameters ( productlines) up

Did you try using Postman the test the call for creating the invoice? I’m not sure how to format the nested productlines in Bubble, so maybe it’s best to first try and create an invoice through Postman. If that works without errors you can try to recreate your call with Bubble.

Let me know if it works!