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

creating JSON body to PATCH to Custom REST API

I have a custom connector to a REST API with different working GET operations. Besides de GET, I created also a PATCH operation to update the name of a contact person. This works well when testing the operation in the Custom connector, but how can I submit a body to this REST API from a button from my powerapp ? The body of the Request is: [ { "Operation": "Add", "Path": "/FirstName", "Value": "Sean" } ]
3 REPLIES 3
Peter3
Level: Powered On

Re: creating JSON body to PATCH to Custom REST API

Since the hint in Powerapps suggests to build the body of the API request as: ...{body: Table} I created a collection like this: Clear(ContactInfoCollection); Collect(ContactInfoCollection, {Operation: "Add", Path: "/FirstName", Value: "Peter"}) and I used that collection as my table: restservices_web4labels_com.PatchCustomerContact(100931, 008, {body:ContactInfoCollection}) Powerapps returns an error: "Incompatible type. The 'Value' column in the data source you're updating expects a 'Record' type and you're using a 'Text' type. Invalid argument. Expecting a Table value, but of a different schema." How can 1 field "Value" be a 'Record' type ? Any help is very much appreciated.
Community Support Team
Community Support Team

Re: creating JSON body to PATCH to Custom REST API

Hi @Peter3,

Could you please share more details about PATCH operation that you specified within your Custom connector?

Could you please share a bit more about the error message within your app?

Based on the error message that you provided, I think there is something wrong with the value you provided for the Value property within the body property.

The Value column within the body property of your PATCH operation is required to provide a Record value, but you provide a Text value. Please modify your formula as below:

restservices_web4labels_com.PatchCustomerContact(
   100931,
   001,
    {
      body: [
                    {
                      Operation: "Add",
                      Path: "FirstName",
                      Value: {    /* <- Modify here */
                                     "Peter"
                             }
                    }
           ]
    }
)

Or

restservices_web4labels_com.PatchCustomerContact(
   100931,
   001,
    {
      body: [
                    {
                      Operation: "Add",
                      Path: "FirstName",
                      Value: {    /* <- Modify here */
                                 PropertyName: "Peter"      /* <- PropertyName represents the property you specified within the Value column of the body property of your PATCH function */
                             }
                    }
            ]
    }
)

Please check if you have specified the Value column of the body property of the PatchCustomerContact operation as a Record type in your REST API.

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Peter3
Level: Powered On

Re: creating JSON body to PATCH to Custom REST API

Hi Kris, Thank you for the reply. In the meantime I found out that I should probably use Flow in my Powerapps project, since only then I can handle the response from the API. So I will first dive in the Flow application and hopefully find the solution there. Thanks Peter