How to pass complete body data from prior HTTP GET request into HTTP PUT request (with some minor changes)?

Trying to think through the best way to do this…

Basically, I need to make a PUT request to an endpoint with one or two minor changes. The rest of the data will remain the same as it originally exists just a moment before. Since the data will vary depending on the endpoint and what currently exists, my thoughts for the best way to accomplish this are as follows (just not sure how to translate into my Scenario completely).

  1. HTTP GET
  2. Text aggregator (or similar) to extract the entire body response json {xxxx}
  3. Output of this entire body as w/ ability to remap only particular parts of the body that I assign, let’s say adding a new “variable_4_value” = “new_input” for example, along with changing “variable_3_value” = “updated_value”.
  4. HTTP PUT with new body json (old + whatever variables I changed).

The key is for it to be dynamic (+my variable changes), since some fields may be added/removed later, so it should always use whatever comes from the initial GET request to ensure accuracy and that no data gets left out during PUT update.

However, I’m stuck on basically everything from 2-4. I know I can map the json manually, but there are hundreds of lines in the body, and again, it will change from time to time, so I definitely don’t want to go that route. And if I can extract the body text, that solves the first problem, but then how do redefine a variable value, or add a new one then merge that change into the existing body for the PUT request?

Thanks in advance for your input! (No scenario because it’s not built yet, but I’ve attached the sample output bundle from the GET request, and a sample input bundle that I want to use for my PUT request. In this specific example, the only variable I need to change is adding a “jobId” which I’m mapping from a prior step.

PUT_Input.json (2.4 KB)
GET_Output.json (7.3 KB)

Welcome to the Make community!

This might not be necessary, since the HTTP module does not parse response by default, so you already have access to the JSON string.

You’ll need to provide example original JSON and example sample of the changed JSON.

Please provide the input and output bundles of the modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.
Screenshot_2023-10-06_141025

A.

Save each bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading them here will look like this:

module-1-input-bundle.txt (12.3 KB)
module-1-output-bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

This will allow others to better assist you. Thanks!

1 Like

Just updated post with input/output bundles.

Still searching for a solution @samliew if you have any advice

I have already provided the advice above.

In your HTTP module settings “Parse response” field, select “NO” (it is “No” by default)

This will allow you to map the response collection properties (variables) in subsequent modules.

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

So I know I can map the entire response, but that’s not the problem. The problem is how do I inject a few new variables into this code to re-submit as a skimmed down and modified PUT request? As is, the only way I can think to do this is a search and replace for existing fields. But I’m still not sure how to provide the new values appropriately and inject them into the new request.

Actually, I may have an idea. If I can split based one field that will always be present, then I can manually type out and then assign/map newly inserted variables, and merge three parts into one request at the end. Split 1/2, new json code w/ variables, split 2/2. And for existing changes I can use Regex search and replace to update w/ mapped change.

I’ll share my response if I get this working!

Ok so I was able to accomplish my split and combination using the method I stated. However, now the question is… how do I get this data back into proper JSON format without the escaped characters from the raw string so I can send this as the entire JSON formatted body? (Without mapping every single field manually)? Below is an example of what I’m working with.

{\"links\":{\"self\":{\"href\":\"https:\\/\\/tave.io\\/v2\\/event\\/abcd1234efgh5678ijkl\",\"managerHref\":\"https:\\/\\/tave.app\\/jobs\\/schedule\\/abcdefgh\"},\"jobId\":{\"href\":\"https:\\/\\/tave.io\\/v2\\/job\\/ijkl9012mnop3456qrst\",\"managerHref\":\"https:\\/\\/tave.app\\/jobs\\/view\\/ijklmnop\"},\"timezoneId\":{\"href\":\"https:\\/\\/tave.io\\/v2\\/timezone\\/mnop1234qrst5678uvwx\"},\"typeId\":{\"href\":\"https:\\/\\/tave.io\\/v2\\/event-type\\/qrst5678uvwx9012yzab\",\"managerHref\":\"https:\\/\\/tave.app\\/settings\\/calendar\\/google\\/mnopqrst1234uvwx5678\\/view\"}},\"id\":\"abcd1234efgh5678ijkl\",\"created\":\"2024-06-27T20:06:58+00:00\",\"modified\":\"2024-07-04T17:02:00+00:00\",\"hidden\":false,\"externalMappings\":[],\"allDay\":false,\"confirmed\":true,\"descriptionHtml\":\"<p>Event Name: Ambassador Session We are so excited to have you in to the studio for your complimentary ambassador session. During this session we take photos and select your favorites after. You will receive 10 of your favorite photos digitally, as a gift from us! If you are under the age of 19 please make sure to select a time that works for you and a parent to come in. Sessions Details: * Plan on being at the studio for about an hour. * You will be photographed in one outfit, but if you would like to bring in a few options we can help you pick what will be photographed best! We can't wait to see you!! Location: Moving Mountains Studios Phone Number: +1 555-555-5555 Parent or Significant Other - Name: John Doe Parent or Significant Other - Phone Number: 5555555555 Parent or Significant Other - Email*: example@example.com We are only accepting engaged couples, maternity and families. Select you session below!: Engaged Couple How would you describe your family\\/relationship?: Great We have a content creator on our team that captures footage of clients and their experience with MM. Would you want to repost content to your social media that we create from your session with us? : No thanks! I'm not very active on social media. Cancellation Policy: Please Note: Moving Mountains has a $100 cancellation fee. We ask for 48hrs notice to reschedule or cancel your appointment. Text or call 555-555-5555 Need to make changes to this event? Cancel: https:\\/\\/calendly.com\\/cancellations\\/1234abcd-5678-efgh-ijklnopqrst Reschedule: https:\\/\\/calendly.com\\/reschedulings\\/1234abcd-5678-efgh-ijkl-9opqrst<\\/p>\",\"endDate\":\"2024-09-25\",\"endTime\":\"10:00:00\",\"endUtc\":\"2024-09-25T14:00:00+00:00\",\"galleryId\":null,\"jobId\":\"ijkl9012mnop3456qrst\",\"location\":null,\"name\":\"Jane Doe and John Smith\",\"readOnly\":true,\"startDate\":\"2024-09-25\",\"startTime\":\"09:00:00\",\"startUtc\":\"2024-09-25T13:00:00+00:00\",\"timezoneId\":\"mnop1234qrst5678uvwx\",\"timezoneName\":\"America\\/New_York\",\"typeId\":\"qrst5678uvwx9012yzab\",\"channel\":\"InPerson\",\"phoneNumber\":{\"countryCode\":null,\"dialCode\":null,\"e164\":null,\"extension\":null,\"formatted\":null,\"id\":null,\"number\":null,\"telUri\":null},\"virtualUrl\":null}

You can probably use the Parse JSON module, like this:

Screenshot_2024-07-05_140702

Screenshot_2024-07-05_140714

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

Figured that was the way to do it, but kept getting errors that it wasn’t valid JSON. Turns out I was copying the exported Make data (i.e. JSON formatted) instead of copying the Data value INSIDE of Make for testing. After identifying that issue, I added the Transform to JSON step then a Parse JSON, { “json”: {{TransformStep}} }, and all is formatted nicely again for my body request!

Thanks for pointing me in the right direction.

Solution outlined below:

  1. GET request. Do not parse JSON response
  2. Text Parser Search and Replace, using Regex to find field that I need to update and mapping new updated value. Could also create more modules if needing to replace more data, or use a splitter to add new data quicker, then merge it all together before the next step.
  3. Transform Text Parser to JSON
  4. Parse JSON for PUT body
  5. PUT request with mapped ‘Parse JSON’ in body




u

2 Likes