Ok I'm new to rest/rest api as of this week - I believe I've done a lot of research and although there are few examples I still come up with the same thing. It's probably something small that I'm overlooking
I've successfully updated (PUT) 1 item; however, I had to add an item to a list I have. What I'm missing or not getting is the code to add items to a list that is either blank or already has items
Currently the list has 4 Properties First Name, Last Name, Start Date, Transfer Date.
The list has 1 item John, Doe,10/10/2010, 11/11/2011 - when using powershell I can get the item to update using Invoke-WebRequest/Invoke-RestMethod (to change to Jane,Smith,10/10/2010, 11/11/2011 <= dates dont change due
to jsons crappy date format.. different post)
I have been unsuccessful in getting any more than 1 item in the list changed ... I'd like the list to have multiple entries..of course.. John, doe and Jane,smith both in the same list
$ItemId = 1 ..powerhsell code to get certificate thumbprint save to $MyThumbPrint ...powershell code to query database...save to $resultset foreach($i in $resultset) { $MyURL = https://<server>/<site>/_vti_bin/listdata.svc/testlist($itemid) $headers = @{ "X-HTTP-Method" = "Merge";"If-Match" = "*" } $items = @{ FirstName = $i.FirstName LastName = $i.LastName StartDate = '10/10/2010' EndDate = '11/11/2011' } $json = $items | ConvertTo-Json #Put Works (remove the X-HTTP-Method from the headers) #Invoke RestMethod and Invoke-WebRequest return same results $URLURL = Invoke-RestMethod -Uri = $MyURL -UseDefaultCredentials -Method Put -Body $json -ContentType 'application/json' -Headers $headers -CertificateThumbPrint $MythumbPrint # Post does not (add in the X-HTTP-Method) (returns error after first entry #error below $URLURL = Invoke-RestMethod -Uri $MyURL -UseDefaultCredentials -Method POST -Body $json -ContentType 'application/json' -Headers $headers -CertificateThumbPrint $MythumbPrint #Same Result with Invoke-WebRequest $URLURL = Invoke-WebRequest -Uri $MyURL -UseDefaultCredentials -Method POST -Body $json -ContentType 'application/json' -Headers $headers -CertificateThumbPrint $MythumbPrint
}
The error I get on the second item through item X is as follows :
Invoke-WebRequest<?xml version="1.0" encoding="utf-8" standalaone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2008/08/dataservices/metadata">
<code></code>
<message xml:lang="en-US"> An error occured while processing this request.</message>
<error>
Again I'm sure its something small... any and all help would be GREATLY appreciated.. thank you