API3
luca at November 3rd, 2017 12:30 — #1
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
dem at November 6th, 2017 01:40 — #2
Hi Luca,
I've quickly checked you scenario get some deal from API , delete deal id, change contact it to another and make POST request. It is worked for me.
Also simple deal post with contact id is worked too:
POST /api/v3/deals.json
{"name":"new deal from api","contact_id":"59fc2b283e5a143da7180573"}
Could you please check endpoint and method, and may be something wrong with your postData
. Note that retrieving by GET from API gives you {'data': 'deal': {...}}
structure, but you should post only deal data {...}
Kind regards,
Mikhail
luca at November 6th, 2017 08:20 — #3
Hi Mikhail, thanks for your reply!
i'm still getting same error even with the adjustment you suggest.
The URL is correct and send data too, the only way it works it's by building query string like this
let url = 'deals.json?contact_id=59fc2b283e5a143da7180573&name=loremipsum'
but is not the best way to save a more complex deal,
do you have any other suggestion?
Thnaks a lot!
dem at November 6th, 2017 10:51 — #4
Hi Luca,
in my previous post I mean send request to
POST /api/v3/deals.json
with request body
{"name":"new deal from api","contact_id":"59fc2b283e5a143da7180573"}
This is same, when contact_id included in url:
POST /api/v3/deals.json?contact_id=59fc2b283e5a143da7180573
but request body should contain deal fields:
{"name":"new deal from api"}
Also it is possible to use Basic auth to send API requests. More details here: http://forum.developer.onepagecrm.com/t/using-onepage-crm-api-with-postman/302
Kind regards,
Mikhail
luca at November 7th, 2017 04:38 — #5
Hi Mikhail thanks for your reply!
I'm still trying using your guidelines for url and data to post but i'm still getting same error
data:
{ status: 400,
message: 'Incomplete request data',
error_name: 'incomplete_request_data',
error_message: 'Required parameter contact_id has not been found or it has invalid format\n',
errors: {} } } }
dem at November 8th, 2017 10:54 — #6
Hi Luca,
Error message points that something wrong with provided contact id, perhaps contact with this id is not exists in you account. Try to put existing contact from you account.
Required parameter contact_id has not been found or it has invalid format
Kind regards,
Mikhail
arun at May 15th, 2024 12:14 — #8
I am also facing the same issue. I am trying to update a deal's contact_id
using body as
**
{
"contact_id": "622a38ce78d40013c6ef2fa3"
}
**
but getting below error.
**
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<status type="integer">400</status>
<message>Incomplete request data</message>
<error-name>incomplete_request_data</error-name>
<error-message>Required parameter name has not been found or it has invalid format</error-message>
<errors>
</errors>
</hash>
I am sure that the contact_id exists but getting the error.
It seems to me that we cannot update contact_id via api calls. ( Because i tried updating other fields similarly and it works)
Please help
vladimir at May 20th, 2024 07:50 — #9
Hello arun!
The error you received tells us that you should have also specified name
parameter in your request since it's a mandatory parameter when updating a deal via API. But even if you provide it the contact_id
won't be changed, because it's disallowed to move a deal from one contact to another via API. So the contact_id
of a deal won't be changed after such a call.
Thank you,
Vladimir
Powered by Discourse, best viewed with JavaScript enabled