cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ishraqiyun77
Level: Powered On

Flow is removing duplicate objects in body JSON in custom connector

Building a custom connector to another web app that we use. Basically, the JSON looks like this according to their documentation:

{
  "workspace": {
    "title": "string",
    "creator_role": "string",
    "custom_fields": [
      {
        "custom_field_id": 0,
        "value": "string"
      }
] } }

However, there are multiple "custom_fields", so it should be more like this:

{
  "workspace": {
    "title": "string",
    "creator_role": "string",
    "custom_fields": [
      {
        "custom_field_id": 0,
        "value": "string"
      },
      {
        "custom_field_id": 0,
        "value": "string"
      },
      {
        "custom_field_id": 0,
        "value": "string"
      }
    ]
  }
}

And would eventually be something like this:

{
  "workspace": {
    "title": "Test Title",
    "creator_role": "admin",
    "custom_fields": [
      {
        "custom_field_id": 123,
        "value": "Test Custom Field 1"
      },
      {
        "custom_field_id": 456,
        "value": "Test Custom Field 2"
      },
      {
        "custom_field_id": 789,
        "value": "Test Custom Field 3"
      }
    ]
  }
}

However when I drop in the second code snippet, it removes the duplicate "custom_fields". How do I prevent this?

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: Flow is removing duplicate objects in body JSON in custom connector

@ishraqiyun77 

 

I tried doing just that and it works fine for me. Please see the screenshots below:MicrosoftTeams-image (159).png

 

MicrosoftTeams-image (158).png

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

12 REPLIES 12
Dual Super User
Dual Super User

Re: Flow is removing duplicate objects in body JSON in custom connector

Hi @ishraqiyun77 

 

You should be defining the schema for JSON appropriately for that. Define the "Custom_Fields" as an array. You might want to refer to the below JSON schema for this:

{
    "type": "object",
    "properties": {
        "workspace": {
            "type": "object",
            "properties": {
                "title": {
                    "type": "string"
                },
                "creator_role": {
                    "type": "string"
                },
                "custom_fields": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "custom_field_id": {
                                "type": "integer"
                            },
                            "value": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

ishraqiyun77
Level: Powered On

Re: Flow is removing duplicate objects in body JSON in custom connector

That helps me out a ton! Would you be able to point me in the direction of the Microsoft resource of how to properly format JSON for connectors? I was under the wrong impression definitely of what it was requesting.

Dual Super User
Dual Super User

Re: Flow is removing duplicate objects in body JSON in custom connector

Hi @ishraqiyun77 

 

I would suggest you have a look at this blog:

https://blog.mastykarz.nl/what-know-building-microsoft-flow-custom-connectors/

 

The entire process of creating custom connectors and the JSON formatting has been explained well here. 

 

edit: you can use the JSON Parse data operation action to get the format for any JSON resposne. Just click "Use sample payload to generaet Schema" and add a sample output here. 

ssdc.png

 

 

Hope this Helps!

ishraqiyun77
Level: Powered On

Re: Flow is removing duplicate objects in body JSON in custom connector

Ok, perhaps I'm doing something wrong...

Just using your snippet below results in the following:

Capture.PNGCapture1.PNG

It is really non-descript what parameters these correspond with.

Dual Super User
Dual Super User

Re: Flow is removing duplicate objects in body JSON in custom connector

Hi @ishraqiyun77 

 

Can you please share what you have passed in the body part over there? I am guessing this is happening because you have passed the same key for all the body items.

ishraqiyun77
Level: Powered On

Re: Flow is removing duplicate objects in body JSON in custom connector

Hi @yashag2255 

This is the JSON I am passing in:

{
    "type": "object",
    "properties": {
        "workspace": {
            "type": "object",
            "properties": {
                "title": {
                    "type": "string"
                },
                "creator_role": {
                    "type": "string"
                },
                "custom_fields": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "custom_field_id": {
                                "type": "integer"
                            },
                            "value": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}
ishraqiyun77
Level: Powered On

Re: Flow is removing duplicate objects in body JSON in custom connector

Also, even taking the JSON snippet from here:

https://blog.mastykarz.nl/what-know-building-microsoft-flow-custom-connectors/

Results in pretty much the same behavior:

{
  "properties": {
    "file": {
      "title": "File contents",
      "type": "string",
      "format": "binary"
    }
  }
}

image.png

It seems like it should be populating these fields for one of the properties, but that isn't happening.

Capture.PNG

And to point out, when I do something like this:

{
  "workspace": {
    "title": "string",
    "creator_role": "string",
    "custom_fields": [
      {
        "custom_field_id": 0,
        "value": "string"
      }
] } }

 This works as expected. It just removes the duplicate custom_field_id and value which I need in there. So a bit confused on how to approach this.

image.png

ishraqiyun77
Level: Powered On

Re: Flow is removing duplicate objects in body JSON in custom connector

Also, another clarification, I am doing this all by adding an Action and then under Request, I am clicking the "+ Import from sample". Perhaps there is a different way I should be doing this, but that much is not clear to me.

Dual Super User
Dual Super User

Re: Flow is removing duplicate objects in body JSON in custom connector

Hi @ishraqiyun77 

 

Please see the screenhots below:MicrosoftTeams-image (151).png

 

MicrosoftTeams-image (152).png

 

I did a test on my end and you need to pass below schema while creating your request in custom connector.
{
  "workspace": {
    "title": "Test Title",
    "creator_role": "admin",
    "custom_fields": [
      {
        "custom_field_id": 123,
        "value": "Test Custom Field 1"
      },
      {
        "custom_field_id": 456,
        "value": "Test Custom Field 2"
      },
      {
        "custom_field_id": 789,
        "value": "Test Custom Field 3"
      }
    ]
  }
}
It will create 4 parameters each for title,creator's role,  custom_field_id and value. I tried to pass custom_fields as an array while testing out this and it returned me the correct response.
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
ishraqiyun77
Level: Powered On

Re: Flow is removing duplicate objects in body JSON in custom connector

Ok, again, it seems like I am missing something. This is what I get when I "+ Import from sample" using that snippet:

Capture.PNG

It removes the duplicates. I need to send like 25 custom_field_id and value objects in that array.

 

This is what the Test Operations looks like. Again, they are not there for me to pass values into.

Capture1.PNG

Yeah, I can modify the body and manually add them back in before the test, but I don't know how this helps me when finalizing the connector and actually using it in a flow. Those additional 25 or so custom_fields will likely not be available.

Capture2.PNG

So I am missing something...

Dual Super User
Dual Super User

Re: Flow is removing duplicate objects in body JSON in custom connector

@ishraqiyun77 

 

I tried doing just that and it works fine for me. Please see the screenshots below:MicrosoftTeams-image (159).png

 

MicrosoftTeams-image (158).png

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

ishraqiyun77
Level: Powered On

Re: Flow is removing duplicate objects in body JSON in custom connector

Ok, I was trying to do this all in the Custom Connect as opposed to inside the Flow itself. Now it seems to work and make sense. Thanks for the help!

Helpful resources

Announcements
firstImage

New Ranks and Rank Icons in April

Read the announcement for more information!

firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,931)