APIs - Bubble API Connector, Patching api requests

This is a hard thing to explain, but I will give it a shot (for my reference as well as others)

I don’t know if anyone has a better way of doing this, if so … please let me know.

When using the API connecter you setup variables for the data in the json request, and you can send blank values if you tick the box.
However in some instance’s where you are making a PATCH to update the data you often don’t want to resend all the data, just that which has been updated.

Sometime the API will require you to leave out the key value pair if you don’t want to override this… so how do you do this?

And how do you do this without creating a huge number of duplicates API connectors just for instances where you want to update one field…

Example old way.

  "metadata": {
    "client-org": "<metadata-clientOrg>",
    "client-account": "<metadata-clientAccount>",
    "client-user": "<metadata-clientUserCreate>",
    "assistantId": "<metadata-assistantId>",
    "createdOn": "<metadata-createdOn>",
    "updatedOn": "<metadata-updatedOn>",
    "client-user": "<metadata-clientUserUpdate>"
  }

You can see the key value pairs in the 'Metadata" node have values encapsulated like this .

So what I am doing for this is moving to the parent node, in this case “Metadata”

Word of warning using this method will require you to be a bit carful when dealing with json formatting and the order of things, if you leave out something important it will fail, if you put a space in somewhere, it will fail

Like this:

  "metadata": {
<metadata>
  }

Now with this you can see you have effectively removed all the json structure… so it where it gets a bit tricky if you mess it up, and that’s why i keep a copy like this for reference and I add these elements back to the variable value in the api connector AFTER i have tested it fully so I have the structure (i use the {{value}} as value identifiers for my own benefit).

“client-org”: “{{metadata-clientOrg}}”,
“client-account”: “{{metadata-clientAccount}}”,
“client-user”: “{{metadata-clientUserCreate}}”,
“assistantId”: “{{metadata-assistantId}}”,
“createdOn”: “{{metadata-createdOn}}”,
“updatedOn”: “{{metadata-updatedOn}}”,
“client-user”: “{{metadata-clientUserUpdate}}”

Then when sending a request you only add the key value pairs and the data necessary at this point:

1 Like