Skip to content

Commit 2df3a1c

Browse files
arnav777devsayan-das-in
authored andcommitted
adding multistatus for cloudeventspec v2 response
1 parent 4b5ae79 commit 2df3a1c

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

  • packages/destination-actions/src/destinations/salesforce-marketing-cloud

packages/destination-actions/src/destinations/salesforce-marketing-cloud/sfmc-operations.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ interface SFMCAsyncStatus {
3939
resultMessages: string[]
4040
}
4141

42+
/**
43+
* Interface for async upsert response
44+
*/
45+
interface AsyncUpsertResponse {
46+
requestId: string
47+
resultMessages: string[]
48+
}
49+
4250
/**
4351
* Interface for poll response
4452
*/
@@ -145,7 +153,7 @@ export async function asyncUpsertRowsV2(
145153
subdomain: String,
146154
payloads: payload_dataExtension[] | payload_contactDataExtension[],
147155
dataExtensionId?: string
148-
) {
156+
): Promise<MultiStatusResponse> {
149157
if (!dataExtensionId) {
150158
throw new IntegrationError(
151159
`In order to send an event to a data extension Data Extension ID must be defined.`,
@@ -155,15 +163,25 @@ export async function asyncUpsertRowsV2(
155163
}
156164
// Use flattened rows for async API
157165
const rows = generateFlattenedRows(payloads)
158-
const response = await request(
166+
const response = await request<AsyncUpsertResponse>(
159167
`https://${subdomain}.rest.marketingcloudapis.com/data/v1/async/dataextensions/${dataExtensionId}/rows`,
160168
{
161169
method: 'PUT',
162170
json: { items: rows }
163171
}
164172
)
165-
166-
return response
173+
const multiStatusResponse = new MultiStatusResponse()
174+
for (let i = 0; i < payloads.length; i++) {
175+
multiStatusResponse.setSuccessResponseAtIndex(i, {
176+
status: 202,
177+
sent: rows[i] as Object as JSONLikeObject,
178+
body: {
179+
requestId: response.data.requestId,
180+
resultMessages: response.data.resultMessages
181+
}
182+
})
183+
}
184+
return multiStatusResponse
167185
}
168186

169187
export function upsertRows(

0 commit comments

Comments
 (0)