Forum - “Update Bib Record” API not working with JSON?

  • This topic has 5 replies, 1 voice, and was last updated 1 week, 5 days ago by Josh Weisman.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #34074
    Anonymous
    Inactive

    Has anyone been able to update bib (or holdings) records using the JSON API? I have a test case that keeps failing with my JSON client, so I decided to try a simple test in the console with curl: First, retrieve a bib record with a get request in XML format, and then send the record back (unmodified) with a put request. Second, retrieve the same bib record with a get request in JSON format, and then send the record back (unmodified) with a put request. Below are the results of my tests.

    This works (fetching and updating an XML bib object):

    Code:
    curl -H "Authorization: apikey $ALMA_API_KEY" -H ‘Accept: application/xml’ -H ‘Content-Type: application/xml’ -X GET ‘https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/9930179940001701’ > 9930179940001701.xml

    curl -H "Authorization: apikey $ALMA_API_KEY" -H ‘Accept: application/xml’ -H ‘Content-Type: application/xml’ -X PUT ‘https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/9930179940001701’ -d @9930179940001701.xml
    <successful xml response truncated for brevity>

    But this does *not* work (fetching and updating a JSON bib object):

    Code:
    curl -H "Authorization: apikey $ALMA_API_KEY" -H ‘Accept: application/json’ -H ‘Content-Type: application/json’ -X GET ‘https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/9930179940001701&#8217; > 9930179940001701.json

    curl -H "Authorization: apikey $ALMA_API_KEY" -H ‘Accept: application/json’ -H ‘Content-Type: application/json’ -X PUT ‘https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/9930179940001701&#8217; -d @9930179940001701.json
    {"errorsExist":true,"errorList":{"error":[{"errorCode":"402203","errorMessage":"Input parameters mmsId 9930179940001701 is not valid.n(Tracking ID: E01-1808190506-IVA32-AWAE1370915987)"}]},"result":null}

    The only thing that I’m varying in the two tests is the format. What am I missing?

    Jeff

    #35618
    Anonymous
    Inactive

    Hi Jeff,
    Please open a support case – this looks like a real problem.

    Thanks,
    Tamar
    Alma API team

    #35621
    Anonymous
    Inactive

    Will do… Thanks Tamar.

    Incidentally, I also noticed that the JSON-formatted Bib and Holdings objects contain a possibly spurious encoding declaration in the "anies" field. The MARC XML in this field always begin with a

    Code:
    <?xml version="1.0" encoding="UTF-16"?>

    declaration (regardless of the encoding the user agent requests in the Accept header). However, it looks like the MARC XML string is actually encoded in UTF-8, so the presence of the encoding="UTF-16" declaration is causing strange parsing behavior (some XML parsing libraries throw errors… other silently insert erroneous byte-order markers… etc.)

    I’ll open a separate case for this issue.

    Jeff

    #35649
    Anonymous
    Inactive

    hello,

    The standard approach is to use the following

    For XML you should use Content-Type: application/xml
    For JSON you should use Content-Type: application/json

    However the standard doesn’t always work as expected which is why you might need to change the mime type. Try text/json or some other combination and see if that works.

    regards,

    Brent

    PS, Here are some examples from major vendors that I found where the mime-type was very different to what is expected:

    curl -I http://ajax.googleapis.com:80/ajax/services/search/web?q=json


    > Content-Type: text/html

    curl -I https://www.flickr.com/services/rest/?method=flickr.test.echo&format=json&api_key=f82254c1491d894f1204d8408f645a93


    > Content-Type: text/xml

    #35661
    Anonymous
    Inactive

    Hi,
    JSON is not supported in POST/PUT Bib/Holding.
    We updated the documentation to indicate this more clearly.

    Thanks,
    Tamar

    #70703
    Josh Weisman
    Keymaster

    For those working with Node, the xmldom parser can work with the XML string in the JSON version. See this gist for an example.

    For those working with other languages whose XML parsers are more strict and can’t work with the UTF-16 declaration in the JSON version, you can either use the XML version which includes the correct UTF-8 declaration, or remove the UTF-16 declaration from the string manually before parsing.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.