cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

@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 II
Dual Super User II

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!

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.

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!

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.

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.

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"
                            }
                        }
                    }
                }
            }
        }
    }
}

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

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.

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!

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

@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

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
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Microsoft Ignite

Microsoft Power Platform: 2021 Release Wave 1 Plan

Power Platform release plan for the 2021 release wave 1 describes all new features releasing from April through September 2021.

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (18,732)