How to upload data in power apps table using python

32 views Asked by At

I've a requirement to insert new data in a table.

I tried below code:

product_record_id="7ec1fc08-fcdb-ee11-904d-00224803f3ee"
LookupTo="LookupTableName"
#Update table code
# Define the data to be posted
 data_to_post = [
                        {
                        "id": product_id,
                        "[email protected]": f"/{LookupTo}({product_record_id})"
                        }
                        # Add more dictionaries for additional records if needed
                        ]

   # Make the POST request
   response = requests.post(post_url, json=data_to_post, headers=headers)

  # Check if the request was successful
   if response.status_code == 201:  # 201 indicates success for POST request
        print("Data successfully posted.")
   else:
        print("Error:", response.status_code)
        print("Response:", response.text)

After getting response from postman i get below values for lookup table and i've made changes regarding that as shown above:

"value": [
        {
            "@odata.etag": "W/\"992\"",
            "_owningbusinessunit_value": "",
            "id": "7ec1fc08-fcdb-ee11-904d-00224803f3ee",
            "statecode": 0,
            "statuscode": 1,
            "entityname": "Product",
            
        }

But above python code is throwing below error:

InnerException : Microsoft.OData.ODataException: A property 'Product_value' which only has property annotations in the payload but no property value is declared to be of type 'Edm.Guid'. In OData, only navigation properties and named streams can be represented as properties without values.\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithoutValue(IODataJsonLightReaderResourceState resourceState, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass9_0.b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func2 readPropertyAnnotationValue, Action2 handleProperty)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n

As I'm new to this any help will be thankful.

0

There are 0 answers