I fetch data from Sharepoint using perl on a linuxmachine. This worked real good as long as I only had to read data from there.
Now that I also have to change data on Sharepoint I'm stuck.
Sharepoint throws:
A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'application/atom+xml;type=entry, application/atom+xml, application/json;odata=verbose' matches the content type 'application/json'.
It's almost the same problem as this one, except that my Content-type seems to be correct and the error still gets thrown:
ODataContentTypeException : Content Type 'application/json;odata=verbose'
After wasting two days with trying and googling I now hope that someone here can help me.
This is my code:
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use LWP::Authen::Ntlm;
use JSON;
use Data::Dumper;
# config
my $host = "mysite.local";
my $user = 'domain\spadmin';
my $pass = "sucKmYducK";
my $resource = "business/mytestsite";
my $listid = "1bd8d1bc-e797-41ae-97c0-e3876406d0fe";
my $itemindex = 20;
# globals
my $digest;
# create useragent
my $ua = LWP::UserAgent->new( keep_alive => 1);
$ua->credentials("$host:443", "", $user, $pass);
$ua->default_header('Accept' => "application/json;odata=verbose");
$ua->timeout( 10 );
# get digest
my $response = $ua->post( "https://$host/$resource/_api/contextinfo" );
if ($response->is_success)
{
my $json = decode_json $response->decoded_content;
$digest = $json->{d}->{GetContextWebInformation}->{FormDigestValue};
}
else
{
die $response->status_line;
}
# post data
my $msg = '{"__metadata":{"type":"SP.Data.DocLibItem"},"Title":"This is my testtitle"}';
$ua->default_header
(
'Accept' => "application/json;odata=verbose",
'Content-type' => "application/json;odata=verbose",
'Content-length' => length( $msg ),
'X-HTTP-Method' => "MERGE",
'X-RequestDigest' => $digest,
'IF-MATCH' => "*"
);
my $response = $ua->post
(
"https://$host/$resource/_api/lists('$listid')/items($itemindex)",
{
data => $msg
}
);
my $json = decode_json $response->decoded_content;
print Dumper( $json );
if ($response->is_success)
{
print "place to be :)\n";
}
else
{
die $response->status_line;
}