@@ -3,7 +3,11 @@ import {
3
3
composeNextState ,
4
4
http , // Important: this is the OLD axios-based http.
5
5
} from '@openfn/language-common' ;
6
- import { expandReferences } from '@openfn/language-common/util' ;
6
+ import {
7
+ expandReferences ,
8
+ logResponse ,
9
+ request ,
10
+ } from '@openfn/language-common/util' ;
7
11
8
12
const { axios } = http ;
9
13
export { axios } ;
@@ -56,23 +60,19 @@ export function addContact(params, callback) {
56
60
57
61
const url = `${ host } /api/${ apiVersion || 'v2' } /contacts.json` ;
58
62
59
- const config = {
60
- url,
61
- data : resolvedParams ,
63
+ return request ( 'POST' , url , {
64
+ body : resolvedParams ,
62
65
headers : { Authorization : `Token ${ token } ` } ,
63
- } ;
64
-
65
- return http
66
- . post ( config ) ( state )
67
- . then ( response => {
68
- console . log ( 'Contact added with uuid:' , response . data . uuid ) ;
69
- const nextState = {
70
- ...composeNextState ( state , response . data ) ,
71
- response,
72
- } ;
73
- if ( callback ) return callback ( nextState ) ;
74
- return nextState ;
75
- } ) ;
66
+ } ) . then ( response => {
67
+ logResponse ( response ) ;
68
+ console . log ( 'Contact added with uuid:' , response . body . uuid ) ;
69
+ const nextState = {
70
+ ...composeNextState ( state , response . data ) ,
71
+ response,
72
+ } ;
73
+ if ( callback ) return callback ( nextState ) ;
74
+ return nextState ;
75
+ } ) ;
76
76
} ;
77
77
}
78
78
@@ -103,7 +103,15 @@ export function upsertContact(params, callback) {
103
103
data : resolvedParams ,
104
104
headers : { Authorization : `Token ${ token } ` } ,
105
105
} ;
106
+ const response = request ( 'POST' , url , {
107
+ body : resolvedParams ,
108
+ headers : { Authorization : `Token ${ token } ` } ,
109
+ } ) . then ( response => {
110
+ logResponse ( response ) ;
111
+ console . log ( 'Contact added with uuid:' , response . body . uuid ) ;
112
+ return response
106
113
114
+ } )
107
115
return http
108
116
. post ( config ) ( state )
109
117
. then ( resp => {
0 commit comments