0

I have created a WorkFlow using Power Automate which fires when a SharePoint site list item is created, it performs the following actions:

  1. Collects the values of some of the fields in the newly created list item.
  2. Save the values in variables
  3. Creates a sub-site using the values in the variables
  4. Updates the list item with the URL of the newly created sub-site.

The problem occurs trying to update the list item, (step 4). The list 'Project List' has the following columns:

Title - Single line text field
Subject - Single line of text
ProjectId - Unique number field
ProjectSite - Hyperlink field

Here's the code in the step which is trying to update the list item:

    {
    "inputs": {
        "host": {
            "connectionName": "shared_sharepointonline",
            "operationId": "HttpRequest",
            "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
        },
        "parameters": {
            "dataset": "https://mysite.sharepoint.com/sites/VIIProjects",
            "parameters/method": "POST",
            "parameters/uri": "_api/web/lists/GetByTitle('Project List')/items(@{triggerOutputs()?['body/ID']})",
            "parameters/headers": {
                "Accept ": "application/json;odata=verbose ",
                "Content-Type ": "application/json;odata=verbose ",
                "IF-MATCH": "*",
                "X-HTTP-METHOD ": "MERGE"
            },
            "parameters/body": "{ '__metadata':
            { 
                'type':'SP.Data.Project_x0020_ListListItem' }, 
                'ProjectSite':{'__metadata':{type:'SP.FieldUrlValue'}, 
                    'Description':'@{variables('SiteTitle')}',
                    'Url':'https://mysite.sharepoint.com@{variables('SiteURL')}'
            }
            } "
        },
        "authentication": "@parameters('$authentication')"
    }
}

This step receives the following error:

{
  "status": 400,
  "message": "Cannot handle the data at position 113.\r\nclientRequestId: b6d8145e-fce7-4d46-96d5-cd6e110a95ad\r\nserviceRequestId: 86eb819f-d0ea-2000-59b2-7e44fa52ac23",
  "source": "https://mysite.sharepoint.com/sites/VIIProjects/_api/web/lists/GetByTitle('Project%20List')/items(4)",
  "errors": [
    "-1",
    "Microsoft.SharePoint.Client.InvalidClientQueryException"
  ]
}

If I browse to mysite.sharepoint.com/sites/VIIProjects/_api/web/lists/GetByTitle('Project%20List')/items(4) I can see the following:

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="https://mysite.sharepoint.com/sites/VIIProjects/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag="&quot;1&quot;">
  <id>71408e64-5cfa-4099-a02b-e35e16a66ab5</id>
  <category term="SP.Data.Project_x0020_ListListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <link rel="edit" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject" type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/FirstUniqueAncestorSecurableObject" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments" type="application/atom+xml;type=feed" title="RoleAssignments" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/RoleAssignments" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentFiles" type="application/atom+xml;type=feed" title="AttachmentFiles" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/AttachmentFiles" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentType" type="application/atom+xml;type=entry" title="ContentType" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/ContentType" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/GetDlpPolicyTip" type="application/atom+xml;type=entry" title="GetDlpPolicyTip" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/GetDlpPolicyTip" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsHtml" type="application/atom+xml;type=entry" title="FieldValuesAsHtml" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/FieldValuesAsHtml" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsText" type="application/atom+xml;type=entry" title="FieldValuesAsText" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/FieldValuesAsText" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesForEdit" type="application/atom+xml;type=entry" title="FieldValuesForEdit" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/FieldValuesForEdit" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/File" type="application/atom+xml;type=entry" title="File" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/File" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Folder" type="application/atom+xml;type=entry" title="Folder" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/Folder" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/LikedByInformation" type="application/atom+xml;type=entry" title="LikedByInformation" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/LikedByInformation" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ParentList" type="application/atom+xml;type=entry" title="ParentList" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/ParentList" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Properties" type="application/atom+xml;type=entry" title="Properties" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/Properties" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Versions" type="application/atom+xml;type=feed" title="Versions" href="Web/Lists(guid'0f5bf3fe-2f8a-41ab-9499-48345eb514f2')/Items(4)/Versions" />
  <title />
  <updated>2020-10-09T10:55:13Z</updated>
  <author>
    <name />
  </author>
  <content type="application/xml">
    <m:properties>
      <d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
      <d:Id m:type="Edm.Int32">4</d:Id>
      <d:ServerRedirectedEmbedUri m:null="true" />
      <d:ServerRedirectedEmbedUrl></d:ServerRedirectedEmbedUrl>
      <d:ContentTypeId>0x010023C27C491F3F834B84F6AD1AC5A271BA</d:ContentTypeId>
      <d:Title>1004 - Swansea Nuclear Medicine Website</d:Title>
      <d:ComplianceAssetId m:null="true" />
      <d:cocz>Create an informational website for Swansea Nuclear Medicine</d:cocz>
      <d:vnml m:type="Edm.Double">1004</d:vnml>
      <d:ProjectSite m:null="true" />
      <d:ID m:type="Edm.Int32">4</d:ID>
      <d:Modified m:type="Edm.DateTime">2020-10-09T08:26:56Z</d:Modified>
      <d:Created m:type="Edm.DateTime">2020-10-09T08:26:56Z</d:Created>
      <d:AuthorId m:type="Edm.Int32">6</d:AuthorId>
      <d:EditorId m:type="Edm.Int32">6</d:EditorId>
      <d:OData__UIVersionString>1.0</d:OData__UIVersionString>
      <d:Attachments m:type="Edm.Boolean">false</d:Attachments>
      <d:GUID m:type="Edm.Guid">f9213fe6-b6a8-403b-8f5d-a8d8e35618ee</d:GUID>
    </m:properties>
  </content>
</entry>

Could someone point me in the right direction please.

Many Thanks.

2
  • One question, can't you use "PATCH" method when you updating a list item? I just tested with "PATCH" and it worked. If you would like, I can post a screenshot on that Commented Oct 9, 2020 at 14:29
  • Hi Matiur, thanks for your suggestion, I had already tried that. I've now found the solution, the problem was being caused by spaces after the header keys, see my answer below.
    – SteveP
    Commented Oct 9, 2020 at 14:32

1 Answer 1

0

Well after many attempts I finally got it to work. The problem was being caused by the paremeters/headers keys (Accept, Content-Type, and X-HTTP-METHOD), if you look at the keys they have a space after them before the closing double quotes, delete the space and it then works.

Before - Not Working

   {
    "inputs": {
        "host": {
            "connectionName": "shared_sharepointonline",
            "operationId": "HttpRequest",
            "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
        },
        "parameters": {
            "dataset": "https://mysite.sharepoint.com/sites/VIIProjects",
            "parameters/method": "POST",
            "parameters/uri": "_api/web/lists/GetByTitle('Project List')/items(@{triggerOutputs()?['body/ID']})",
            "parameters/headers": {
                "Accept ": "application/json;odata=verbose ",
                "Content-Type ": "application/json;odata=verbose ",
                "IF-MATCH": "*",
                "X-HTTP-METHOD ": "MERGE"
            },
            "parameters/body": "{ '__metadata':
            { 
                'type':'SP.Data.Project_x0020_ListListItem' }, 
                'ProjectSite':{'__metadata':{type:'SP.FieldUrlValue'}, 
                    'Description':'@{variables('SiteTitle')}',
                    'Url':'https://mysite.sharepoint.com@{variables('SiteURL')}'
            }
            } "
        },
        "authentication": "@parameters('$authentication')"
    }
}

After - Working

   {
    "inputs": {
        "host": {
            "connectionName": "shared_sharepointonline",
            "operationId": "HttpRequest",
            "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
        },
        "parameters": {
            "dataset": "https://mysite.sharepoint.com/sites/VIIProjects",
            "parameters/method": "POST",
            "parameters/uri": "_api/web/lists/GetByTitle('Project List')/items(@{triggerOutputs()?['body/ID']})",
            "parameters/headers": {
                "Accept": "application/json;odata=verbose",
                "Content-Type": "application/json;odata=verbose",
                "IF-MATCH": "*",
                "X-HTTP-METHOD": "MERGE"
            },
            "parameters/body": "{ '__metadata':
            { 
                'type':'SP.Data.Project_x0020_ListListItem' }, 
                'ProjectSite':{'__metadata':{type:'SP.FieldUrlValue'}, 
                    'Description':'@{variables('SiteTitle')}',
                    'Url':'https://mysite.sharepoint.com@{variables('SiteURL')}'
            }
            } "
        },
        "authentication": "@parameters('$authentication')"
    }
}

Hopefully this will help someone else with a similar problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.