Hi there,

for quite a while I'm retrieving data from Sharepoint using perl on my linuxmachine.

Now I also have to change data on SP.

I added some logic to retrieve the digesttoken (needed for posting) but altough it looked promising at the beginning now I'm stuck with that really annoying error:

"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'."

I've already spent days searching the web for a solution, but was unsuccessful so far.

Maybe there is a monk out there who can help me out.

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; }

tia

tiMb


In reply to Changing data in Sharepointlist via LWP/JSON - OData.ODataContentTypeException :( by timb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.