@@ -108,6 +108,25 @@ function getTransferStartBody (connectorId, counterPartyAddress, contractId) {
108
108
return body
109
109
}
110
110
111
+ function getContractNegotiationBody ( policyID , counterPartyAddress ) {
112
+ const body = {
113
+ '@context' : {
114
+ '@vocab' : "https://w3id.org/edc/v0.0.1/ns/"
115
+ } ,
116
+ '@type' : 'ContractRequest' ,
117
+ counterPartyAddress,
118
+ 'protocol' : 'dataspace-protocol-http' ,
119
+ 'policy' : {
120
+ '@context' : 'http://www.w3.org/ns/odrl.jsonld' ,
121
+ '@id' : policyID ,
122
+ '@type' : 'Offer' ,
123
+ 'assigner' : 'provider' ,
124
+ 'target' : 'assetId'
125
+ }
126
+ }
127
+ return body
128
+ }
129
+
111
130
/**
112
131
* Fetch call to obtain a set of contracts.
113
132
* @async
@@ -290,3 +309,29 @@ export async function transferPullFlow (connectorId, counterPartyAddress, contra
290
309
const getEDRResponse = await transferGetEDR ( getIDResponse [ '@id' ] )
291
310
return getEDRResponse
292
311
}
312
+
313
+ /**
314
+ * Post call to do a contract negotiation
315
+ * @async
316
+ * @param {string } policyID - Connector ID that has the contract.
317
+ * @param {string } counterPartyAddress - The dataspace protocol URL of the provider connector, usually in the form of <base_url>/protocol or <base_url>/api/dsp.
318
+ * @returns empty Response, expected to be a 200.
319
+ */
320
+ export async function contractNegotiation ( policyID , counterPartyAddress ) {
321
+ const url = `${ settings . connectorUrl } /v3/contractnegotiations`
322
+ const bodyContractNegotiation = getContractNegotiationBody ( policyID , counterPartyAddress )
323
+ const options = {
324
+ method : 'POST' ,
325
+ headers : { 'Content-Type' : 'application/json' } ,
326
+ body : JSON . stringify ( bodyContractNegotiation )
327
+ }
328
+ try {
329
+ const data = await fetchData ( url , options ) . then ( response => response . json ( ) )
330
+ return data
331
+ } catch ( error ) {
332
+ // Will be 2 printed errors as there is a console.log on the fetchData helper, but as is server side can help us id the error.
333
+ console . log ( 'Error on contractNegotiation!' )
334
+ console . log ( error )
335
+ return { error }
336
+ }
337
+ }
0 commit comments