On Jul 30, 2017 7:09 AM, <general-requ...@developer.marklogic.com> wrote:
> Send General mailing list submissions to > general@developer.marklogic.com > > To subscribe or unsubscribe via the World Wide Web, visit > http://developer.marklogic.com/mailman/listinfo/general > or, via email, send a message with subject or body 'help' to > general-requ...@developer.marklogic.com > > You can reach the person managing the list at > general-ow...@developer.marklogic.com > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of General digest..." > > > Today's Topics: > > 1. Client API - 8000 - POST /v1/documents - Unexpected 400 > (Florent Georges) > 2. Re: Client API - 8000 - POST /v1/documents - Unexpected 400 > (Florent Georges) > 3. Re: Client API - 8000 - POST /v1/documents - Unexpected 400 > (Erik Hennum) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sun, 30 Jul 2017 11:41:19 +0200 > From: Florent Georges <li...@fgeorges.org> > Subject: [MarkLogic Dev General] Client API - 8000 - POST > /v1/documents - Unexpected 400 > To: MarkLogic Developer Discussion <general@developer.marklogic.com> > Message-ID: > <CADyR_r1WhEBoR5dViio3DB6iDNhw1S_TeMZ0aDTjsU_jdKVvKg@mail. > gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hi, > > I am trying to use the POST /v1/documents endpoint on 8000 to insert > several documents at once. From the chapter "Reading and Writing Multiple > Documents" in the REST Guide, in section "Specifying an Explicit Document > URI" [1], the following pseudo header in each part should be enough to set > the URI for each document: > > Content-Disposition: attachment;filename=/your/uri > > But I get a 400 with the message: "REST-REQUIREDPARAM: (err:FOER0000) > Required parameter: missing required extension parameter". > > Any idea why? > > [1]https://docs.marklogic.com/guide/rest-dev/bulk#id_84006 > > Below a complete repro that can be played in QConsole (and later an example > using PUT instead, which does work): > > 'use strict'; > > const rn = '\r\n'; > const bnd = '.ml.rockzzz.'; > var body = rn; > > // first part > body += '--' + bnd + rn; > body += 'Content-Type: application/json' + rn; > body += 'Content-Disposition: attachment; filename="/test/multi-one.json"' > + rn; > body += rn; > body += JSON.stringify({ hello: 'one!' }); > body += rn; > > // second part > body += '--' + bnd + rn; > body += 'Content-Type: application/json' + rn; > body += 'Content-Disposition: attachment; filename="/test/multi-two.json"' > + rn; > body += rn; > body += JSON.stringify({ hello: 'two!' }); > body += rn; > > // after the last part > body += '--' + bnd + '--' + rn; > > xdmp.httpPost( > 'http://localhost:8000/v1/documents', { > authentication : { > method : 'digest', > username : 'admin', > password : 'admin' > }, > headers: { > "Content-type": 'multipart/related; boundary=' + bnd, > Accept: "application/json" > }, > data: body > }); > > Here is the example using PUT, and indeed working fine: > > 'use strict'; > > xdmp.httpPut( > 'http://localhost:8000/v1/documents?uri=/test/single.json', { > authentication : { > method : 'digest', > username : 'admin', > password : 'admin' > }, > headers: { > "Content-type": 'application/json', > Accept: "application/json" > }, > data: JSON.stringify({ hello: 'world!' }) > }); > > Any idea what I did wrong? > > Regards, > > -- > Florent Georges > H2O Consulting > http://h2o.consulting/ > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: http://developer.marklogic.com/pipermail/general/ > attachments/20170730/ebabcd53/attachment-0001.html > > ------------------------------ > > Message: 2 > Date: Sun, 30 Jul 2017 14:56:03 +0200 > From: Florent Georges <li...@fgeorges.org> > Subject: Re: [MarkLogic Dev General] Client API - 8000 - POST > /v1/documents - Unexpected 400 > To: MarkLogic Developer Discussion <general@developer.marklogic.com> > Message-ID: > <CADyR_r3_VknJ5ZLLXDGY7FYgqY4d=2ZnpiNxAA > -ogxonwt3...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hi, > > Actually, I made a mistake in the Content-Type of the overall request, I > used "multipart/related" instead of "multipart/mixed" as mentioned in the > doc. But when I fix it, I get a 500 with the following error message: > > XDMP-AS: (err:XPTY0004) $meta-type as xs:string -- Invalid coercion: () as > xs:string . See the MarkLogic server error log for further detail. > > It seems it all goes down to $content-type being the empty sequence in the > following call in document-model-update.xqy (in ML 9.0-1.1): > > let $document-next := > if ($part-type ne "document-metadata") then () > else docmodupd:parse-metadata-map($curr-uri,$content-type,$body) > > But then, it is beyond my knowledge... > > Regards, > > -- > Florent Georges > H2O Consulting > http://h2o.consulting/ > > > On 30 July 2017 at 11:41, Florent Georges wrote: > > > Hi, > > > > I am trying to use the POST /v1/documents endpoint on 8000 to insert > > several documents at once. From the chapter "Reading and Writing > Multiple > > Documents" in the REST Guide, in section "Specifying an Explicit Document > > URI" [1], the following pseudo header in each part should be enough to > set > > the URI for each document: > > > > Content-Disposition: attachment;filename=/your/uri > > > > But I get a 400 with the message: "REST-REQUIREDPARAM: (err:FOER0000) > > Required parameter: missing required extension parameter". > > > > Any idea why? > > > > [1]https://docs.marklogic.com/guide/rest-dev/bulk#id_84006 > > > > Below a complete repro that can be played in QConsole (and later an > > example using PUT instead, which does work): > > > > 'use strict'; > > > > const rn = '\r\n'; > > const bnd = '.ml.rockzzz.'; > > var body = rn; > > > > // first part > > body += '--' + bnd + rn; > > body += 'Content-Type: application/json' + rn; > > body += 'Content-Disposition: attachment; filename="/test/multi-one. > json"' > > + rn; > > body += rn; > > body += JSON.stringify({ hello: 'one!' }); > > body += rn; > > > > // second part > > body += '--' + bnd + rn; > > body += 'Content-Type: application/json' + rn; > > body += 'Content-Disposition: attachment; filename="/test/multi-two. > json"' > > + rn; > > body += rn; > > body += JSON.stringify({ hello: 'two!' }); > > body += rn; > > > > // after the last part > > body += '--' + bnd + '--' + rn; > > > > xdmp.httpPost( > > 'http://localhost:8000/v1/documents', { > > authentication : { > > method : 'digest', > > username : 'admin', > > password : 'admin' > > }, > > headers: { > > "Content-type": 'multipart/related; boundary=' + bnd, > > Accept: "application/json" > > }, > > data: body > > }); > > > > Here is the example using PUT, and indeed working fine: > > > > 'use strict'; > > > > xdmp.httpPut( > > 'http://localhost:8000/v1/documents?uri=/test/single.json', { > > authentication : { > > method : 'digest', > > username : 'admin', > > password : 'admin' > > }, > > headers: { > > "Content-type": 'application/json', > > Accept: "application/json" > > }, > > data: JSON.stringify({ hello: 'world!' }) > > }); > > > > Any idea what I did wrong? > > > > Regards, > > > > -- > > Florent Georges > > H2O Consulting > > http://h2o.consulting/ > > > > > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: http://developer.marklogic.com/pipermail/general/ > attachments/20170730/fd881afa/attachment-0001.html > > ------------------------------ > > Message: 3 > Date: Sun, 30 Jul 2017 14:09:14 +0000 > From: Erik Hennum <erik.hen...@marklogic.com> > Subject: Re: [MarkLogic Dev General] Client API - 8000 - POST > /v1/documents - Unexpected 400 > To: MarkLogic Developer Discussion <general@developer.marklogic.com> > Message-ID: > <DFDF2FD50BF5AA42ADAF93FF2E3CA1850C829736@EXCHG10-BE02. > marklogic.com> > Content-Type: text/plain; charset="iso-8859-1" > > Hi, Florent: > > I'm wondering whether a CRLF is required before the initial boundary. > That seems to be implied but not explicitly stated by: > > https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html > > A couple of suggestions for investigating: > > * Confirm that the constructed multipart/mixed is parseable using > xdmp.multipartDecode() > > https://docs.marklogic.com/xdmp.multipartDecode > > * Write the two documents individually, read both document back in a > single request that accepts multipart/mixed, and compare the REST API > response to the constructed multipart/mixed > > https://docs.marklogic.com/REST/GET/v1/documents > > If that doesn't discover the issue, maybe setting the content-length in > the part might help (though the standard explicitly requires no headers in > the part). > > > Hoping that's useful, > > > Erik Hennum > > > ________________________________ > From: general-boun...@developer.marklogic.com [general-bounces@developer. > marklogic.com] on behalf of Florent Georges [li...@fgeorges.org] > Sent: Sunday, July 30, 2017 5:56 AM > To: MarkLogic Developer Discussion > Subject: Re: [MarkLogic Dev General] Client API - 8000 - POST > /v1/documents - Unexpected 400 > > Hi, > > Actually, I made a mistake in the Content-Type of the overall request, I > used "multipart/related" instead of "multipart/mixed" as mentioned in the > doc. But when I fix it, I get a 500 with the following error message: > > XDMP-AS: (err:XPTY0004) $meta-type as xs:string -- Invalid coercion: () as > xs:string . See the MarkLogic server error log for further detail. > > It seems it all goes down to $content-type being the empty sequence in the > following call in document-model-update.xqy (in ML 9.0-1.1): > > let $document-next := > if ($part-type ne "document-metadata") then () > else docmodupd:parse-metadata-map($curr-uri,$content-type,$body) > > But then, it is beyond my knowledge... > > Regards, > > -- > Florent Georges > H2O Consulting > http://h2o.consulting/ > > > On 30 July 2017 at 11:41, Florent Georges wrote: > Hi, > > I am trying to use the POST /v1/documents endpoint on 8000 to insert > several documents at once. From the chapter "Reading and Writing Multiple > Documents" in the REST Guide, in section "Specifying an Explicit Document > URI" [1], the following pseudo header in each part should be enough to set > the URI for each document: > > Content-Disposition: attachment;filename=/your/uri > > But I get a 400 with the message: "REST-REQUIREDPARAM: (err:FOER0000) > Required parameter: missing required extension parameter". > > Any idea why? > > [1]https://docs.marklogic.com/guide/rest-dev/bulk#id_84006 > > Below a complete repro that can be played in QConsole (and later an > example using PUT instead, which does work): > > 'use strict'; > > const rn = '\r\n'; > const bnd = '.ml.rockzzz.'; > var body = rn; > > // first part > body += '--' + bnd + rn; > body += 'Content-Type: application/json' + rn; > body += 'Content-Disposition: attachment; filename="/test/multi-one.json"' > + rn; > body += rn; > body += JSON.stringify({ hello: 'one!' }); > body += rn; > > // second part > body += '--' + bnd + rn; > body += 'Content-Type: application/json' + rn; > body += 'Content-Disposition: attachment; filename="/test/multi-two.json"' > + rn; > body += rn; > body += JSON.stringify({ hello: 'two!' }); > body += rn; > > // after the last part > body += '--' + bnd + '--' + rn; > > xdmp.httpPost( > 'http://localhost:8000/v1/documents', { > authentication : { > method : 'digest', > username : 'admin', > password : 'admin' > }, > headers: { > "Content-type": 'multipart/related; boundary=' + bnd, > Accept: "application/json" > }, > data: body > }); > > Here is the example using PUT, and indeed working fine: > > 'use strict'; > > xdmp.httpPut( > 'http://localhost:8000/v1/documents?uri=/test/single.json', { > authentication : { > method : 'digest', > username : 'admin', > password : 'admin' > }, > headers: { > "Content-type": 'application/json', > Accept: "application/json" > }, > data: JSON.stringify({ hello: 'world!' }) > }); > > Any idea what I did wrong? > > Regards, > > -- > Florent Georges > H2O Consulting > http://h2o.consulting/ > > > > > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: http://developer.marklogic.com/pipermail/general/ > attachments/20170730/c6986420/attachment.html > > ------------------------------ > > _______________________________________________ > General mailing list > General@developer.marklogic.com > Manage your subscription at: > http://developer.marklogic.com/mailman/listinfo/general > > > End of General Digest, Vol 157, Issue 42 > **************************************** >
_______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general