cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper IV
Helper IV

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
Highlighted
Dual Super User III
Dual Super User III

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
Highlighted
Dual Super User III
Dual Super User III

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!

Highlighted
Helper IV
Helper IV

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.

Highlighted
Dual Super User III
Dual Super User III

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!

Highlighted
Helper IV
Helper IV

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.

Highlighted
Dual Super User III
Dual Super User III

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.

Highlighted
Helper IV
Helper IV

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"
                            }
                        }
                    }
                }
            }
        }
    }
}
Highlighted
Helper IV
Helper IV

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

Highlighted
Helper IV
Helper IV

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.

Highlighted
Dual Super User III
Dual Super User III

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!
Highlighted
Helper IV
Helper IV

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...

Highlighted
Dual Super User III
Dual Super User III

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

Highlighted
Helper IV
Helper IV

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

Microsoft Ignite 2020

Check out the announcement of Power Platform content at Microsoft Ignite!

thirdImage

Experience what's new for Power Automate

Join us for an in-depth look at the new Power Automate features and capabilities at the free Microsoft Business Applications Launch Event.

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (6,414)