4 replies [Last post]
Aron Roberts
Offline
Joined: 03/07/2011

On Wed, Sep 7, 2011 at 2:48 PM, Chris Hoffman
wrote:
> I'm wondering about using REST calls to send object updates, e.g., to migrate in repeating data if we can't get Talend to do all we want it to do.  Looking at the common REST API for update
>  https://wiki.collectionspace.org:8444/display/collectionspace/Common+Services+REST+API+documentation#CommonServicesRESTAPIdocumentation-Updateanobject%2Fprocedure%2Frecordinstance
>
> How would I invoke this via curl?

Via an HTTP PUT request; e.g.

curl -i -u admin@core.collectionspace.org:Administrator -X PUT -H
"Content-Type: application/xml"
http://localhost:8180/cspace-services/collectionobjects/your_csid_here
-T a_file_containing_one_update_payload.xml

Your XML file containing your update payload can be 'sparse'; that
is, it can simply contain your repeatable group of materials fields,
but no other fields. And you can re-use it with each update request.
So basically you could request a list of records, parse out their
CSIDs (which will be in a element in each list item), and feed
that list of CSIDs to a script that invokes 'curl' much like it does
above.

> Ideally, as with the imports service, I'd have an XML file containing blocks that update something like materials (which repeats) for 1000 objects.  Or would I have to do this one object at a time (using a shell script for instance to parse through a list)?  Or is this a dead end and I should stop thinking about this? ;-)

The latter - you'd need a script or program to loop over repeated
PUT requests, one request per record.

Aron

>
> Thanks,
> Chris
> _______________________________________________
> Soa-tech mailing list
> Soa-tech@lists.collectionspace.org
> http://lists.collectionspace.org/mailman/listinfo/soa-tech_lists.collect...
>

_______________________________________________
Soa-tech mailing list
Soa-tech@lists.collectionspace.org
http://lists.collectionspace.org/mailman/listinfo/soa-tech_lists.collect...

 
Aron Roberts
Offline
Joined: 03/07/2011
invoking object update via REST

A postscript: if the changes you want to make to the 'materials'
repeatable group aren't a uniform and outright replacement, that is,
inserting a fixed set of materials values into each record you're
updating, replacing whatever is there already, this will involve a bit
more scripting.

As I understand it, when you send a repeatable structure in an update
(PUT) request, whatever you're sending in your update payload replaces
the corresponding repeatable structure *outright* in the existing
record. Stated another way, there is no 'merge' or 'append' behavior
where you can, for instance, insert a few new values at the end of the
set of existing values in that repeatable structure, or replace 'just
row 3' in a set of 10 values. For that reason, in a 'selective
update' scenario, you'd need to retrieve each record you want to
update, examine the existing materials repeatable group, and use some
logic to determine how to build that group in the update request.

On Wed, Sep 7, 2011 at 3:16 PM, Aron Roberts wrote:
> On Wed, Sep 7, 2011 at 2:48 PM, Chris Hoffman
> wrote:
>> I'm wondering about using REST calls to send object updates, e.g., to migrate in repeating data if we can't get Talend to do all we want it to do.  Looking at the common REST API for update
>>  https://wiki.collectionspace.org:8444/display/collectionspace/Common+Services+REST+API+documentation#CommonServicesRESTAPIdocumentation-Updateanobject%2Fprocedure%2Frecordinstance
>>
>> How would I invoke this via curl?
>
>  Via an HTTP PUT request; e.g.
>
> curl -i -u admin@core.collectionspace.org:Administrator -X PUT -H
> "Content-Type: application/xml"
> http://localhost:8180/cspace-services/collectionobjects/your_csid_here
> -T a_file_containing_one_update_payload.xml
>
>  Your XML file containing your update payload can be 'sparse'; that
> is, it can simply contain your repeatable group of materials fields,
> but no other fields.  And you can re-use it with each update request.
> So basically you could request a list of records, parse out their
> CSIDs (which will be in a element in each list item), and feed
> that list of CSIDs to a script that invokes 'curl' much like it does
> above.
>
>> Ideally, as with the imports service, I'd have an XML file containing blocks that update something like materials (which repeats) for 1000 objects.  Or would I have to do this one object at a time (using a shell script for instance to parse through a list)?  Or is this a dead end and I should stop thinking about this? ;-)
>
>  The latter - you'd need a script or program to loop over repeated
> PUT requests, one request per record.
>
> Aron
>
>>
>> Thanks,
>> Chris
>> _______________________________________________
>> Soa-tech mailing list
>> Soa-tech@lists.collectionspace.org
>> http://lists.collectionspace.org/mailman/listinfo/soa-tech_lists.collect...
>>
>

_______________________________________________
Soa-tech mailing list
Soa-tech@lists.collectionspace.org
http://lists.collectionspace.org/mailman/listinfo/soa-tech_lists.collect...

Chris Hoffman
Offline
Joined: 03/09/2011
invoking object update via REST

Thanks, Aron and Richard. Yes, I'd read in the REST API doc that for multi-valued fields (I'll try to use that phrase now), what you send replaces what is there. Knowing that, we just wouldn't send something like materials when we did the first import of data. We'd populate materials via update only.
Chris

On Sep 7, 2011, at 3:28 PM, Aron Roberts wrote:

> A postscript: if the changes you want to make to the 'materials'
> repeatable group aren't a uniform and outright replacement, that is,
> inserting a fixed set of materials values into each record you're
> updating, replacing whatever is there already, this will involve a bit
> more scripting.
>
> As I understand it, when you send a repeatable structure in an update
> (PUT) request, whatever you're sending in your update payload replaces
> the corresponding repeatable structure *outright* in the existing
> record. Stated another way, there is no 'merge' or 'append' behavior
> where you can, for instance, insert a few new values at the end of the
> set of existing values in that repeatable structure, or replace 'just
> row 3' in a set of 10 values. For that reason, in a 'selective
> update' scenario, you'd need to retrieve each record you want to
> update, examine the existing materials repeatable group, and use some
> logic to determine how to build that group in the update request.
>
> On Wed, Sep 7, 2011 at 3:16 PM, Aron Roberts wrote:
>> On Wed, Sep 7, 2011 at 2:48 PM, Chris Hoffman
>> wrote:
>>> I'm wondering about using REST calls to send object updates, e.g., to migrate in repeating data if we can't get Talend to do all we want it to do. Looking at the common REST API for update
>>> https://wiki.collectionspace.org:8444/display/collectionspace/Common+Ser...
>>>
>>> How would I invoke this via curl?
>>
>> Via an HTTP PUT request; e.g.
>>
>> curl -i -u admin@core.collectionspace.org:Administrator -X PUT -H
>> "Content-Type: application/xml"
>> http://localhost:8180/cspace-services/collectionobjects/your_csid_here
>> -T a_file_containing_one_update_payload.xml
>>
>> Your XML file containing your update payload can be 'sparse'; that
>> is, it can simply contain your repeatable group of materials fields,
>> but no other fields. And you can re-use it with each update request.
>> So basically you could request a list of records, parse out their
>> CSIDs (which will be in a element in each list item), and feed
>> that list of CSIDs to a script that invokes 'curl' much like it does
>> above.
>>
>>> Ideally, as with the imports service, I'd have an XML file containing blocks that update something like materials (which repeats) for 1000 objects. Or would I have to do this one object at a time (using a shell script for instance to parse through a list)? Or is this a dead end and I should stop thinking about this? ;-)
>>
>> The latter - you'd need a script or program to loop over repeated
>> PUT requests, one request per record.
>>
>> Aron
>>
>>>
>>> Thanks,
>>> Chris
>>> _______________________________________________
>>> Soa-tech mailing list
>>> Soa-tech@lists.collectionspace.org
>>> http://lists.collectionspace.org/mailman/listinfo/soa-tech_lists.collect...
>>>
>>

_______________________________________________
Soa-tech mailing list
Soa-tech@lists.collectionspace.org
http://lists.collectionspace.org/mailman/listinfo/soa-tech_lists.collect...

Richard Millet
Offline
Joined: 03/07/2011
invoking object update via REST

Please remember that multi-valued fields (apka* repeatable fields) do not
support sparse updates. If you want to update a multi-valued field, you
need to first get the previous set of values, modify this set locally, and
send the entire set back in the update payload.

* APKA - Also Poorly Known As

Chris Hoffman
Offline
Joined: 03/09/2011
invoking object update via REST

Thanks, Aron. I'm glad to know this is possible! I still hope to figure out how to do this all in the import service, but we'll probably find times when we need to do this.
Chris

On Sep 7, 2011, at 3:16 PM, Aron Roberts wrote:

> On Wed, Sep 7, 2011 at 2:48 PM, Chris Hoffman
> wrote:
>> I'm wondering about using REST calls to send object updates, e.g., to migrate in repeating data if we can't get Talend to do all we want it to do. Looking at the common REST API for update
>> https://wiki.collectionspace.org:8444/display/collectionspace/Common+Ser...
>>
>> How would I invoke this via curl?
>
> Via an HTTP PUT request; e.g.
>
> curl -i -u admin@core.collectionspace.org:Administrator -X PUT -H
> "Content-Type: application/xml"
> http://localhost:8180/cspace-services/collectionobjects/your_csid_here
> -T a_file_containing_one_update_payload.xml
>
> Your XML file containing your update payload can be 'sparse'; that
> is, it can simply contain your repeatable group of materials fields,
> but no other fields. And you can re-use it with each update request.
> So basically you could request a list of records, parse out their
> CSIDs (which will be in a element in each list item), and feed
> that list of CSIDs to a script that invokes 'curl' much like it does
> above.
>
>> Ideally, as with the imports service, I'd have an XML file containing blocks that update something like materials (which repeats) for 1000 objects. Or would I have to do this one object at a time (using a shell script for instance to parse through a list)? Or is this a dead end and I should stop thinking about this? ;-)
>
> The latter - you'd need a script or program to loop over repeated
> PUT requests, one request per record.
>
> Aron
>
>>
>> Thanks,
>> Chris
>> _______________________________________________
>> Soa-tech mailing list
>> Soa-tech@lists.collectionspace.org
>> http://lists.collectionspace.org/mailman/listinfo/soa-tech_lists.collect...
>>

_______________________________________________
Soa-tech mailing list
Soa-tech@lists.collectionspace.org
http://lists.collectionspace.org/mailman/listinfo/soa-tech_lists.collect...