Hi, i'm try to POST a deal retrieved from API where i've made some changes, this is the JSON i'm try to posting
{
"contact_id":"5628e7a49b79b27268000546",
"owner_id":"5576bafe1787fa3937000e67",
"owner":{
"id":"5576bafe1787fa3937000e67",
"name":"XXXXXXX",
"email":"XXXXXX"
},
"name":"Test Deal",
"text":"Lorem ipsum dolor sit amet",
"date":"2017-11-02",
"contact_info":{
"contact_name":"XXXXXX",
"company":"XXXXXX"
},
"author":"XXXXXX.",
"amount":2000,
"months":1,
"total_amount":2000,
"cost":0,
"total_cost":0,
"margin":2000,
"commission":0,
"commission_percentage":0,
"commission_type":"none",
"commission_base":"amount",
"status":"pending",
"has_related_notes":false,
"attachments":[
],
"deal_fields":[
],
"created_at":"2017-11-02T11:49:51Z",
"modified_at":"2017-11-02T11:49:51Z",
"stage":25,
"expected_close_date":"2017-11-02"
}
with this script which works perfectly for GET and POST login.
async onePageApiCall (url, requestMethod, postData = [], uid = null, key = null) {
let fullUrl = Env.get('API_ONEPAGE_ENDPOINT') + url
let timestamp = Math.round(new Date().getTime() / 1000)
let authData = [uid, timestamp, requestMethod, CryptoJs.SHA1(fullUrl).toString()]
let requestHeader
let data = null
// For POST and PUT requests we will send data as JSON
// as with regular "form data" request we won't be able
// to send more complex structures
if (requestMethod === 'POST' || requestMethod === 'PUT') {
requestHeader = {'Content-Type': 'application/json'}
let jsonData = JSON.stringify(postData)
console.log(jsonData)
data = jsonData
authData.push(CryptoJs.SHA1(jsonData).toString())
}
// Set auth headers if we are logged in
if (key !== null) {
let hash = CryptoJs.HmacSHA256(authData.join('.'), CryptoJs.enc.Base64.parse(key))
requestHeader = {
'X-OnePageCRM-UID': uid,
'X-OnePageCRM-TS': timestamp,
'X-OnePageCRM-Auth': hash
}
}
console.log(data)
return await axios({
method: requestMethod.toUpperCase(),
url: fullUrl,
headers: requestHeader,
data
})
}
i've only removed the ID from retrieved deal to save to another contact but API always respond with this error
data:
{ status: 400,
message: 'Incomplete request data',
error_name: 'incomplete_request_data',
error_message: 'Required parameter name has not been found or it has invalid format\n',
errors: {} } }
even if i try with a simple object like
{'name':'Lorem Ipsum'}
it always return an error.
hoping for your help, thanks in advance
-
Created
3 Nov 2017
-
Last post
20 May 2024
-
8
Posts
-
1.9K
Views
-
4
Users
-
1
Links