API2
rjhillyer at April 28th, 2014 11:11 — #1
I am getting a 400 Bad Request intermittently in my API Call. I am making a call to app.onepagecrm.com/api/actions/" + ActionID + ".json" using a PUT. This works with all OnePage users except one, and it works for his account sometimes, but sometimes it returns a 400 Bad Request.
Any ideas?
rjhillyer at April 28th, 2014 11:16 — #2
Found a few Bad Requests for other Users too. Also Intermittent
pete_onepagecrm at April 28th, 2014 15:53 — #3
Hi Bob, thanks for getting in touch.
Can you tell me, are you only seeing these errors when you try to update an action, or are you also getting them when using other resources?
rjhillyer at April 28th, 2014 18:00 — #4
Looks like it is only on update an action. Set a note seems to work. I do have code that says if NextActionName length > 140, then truncate it, but I am wondering if 140 is still the cut-off for length. It sure would be nice to have a few more codes such as password incorrect, length too long, etc. ?
pete_onepagecrm at April 29th, 2014 07:09 — #5
Hi Bob, the 400 Bad request errors should have some data included in the body.
For example, if I try to update an action with action text that's > 140 chars, my request body will look like this:
{
"status": 108,
"message": "Invalid request data",
"error_name": "invalid_request_data"
}
There's a distinction between the HTTP code (400) and the OnePageCRM API code (108).
There's a list of these codes here - http://developer.onepagecrm.com/api2/index.html#response-codes
Are you getting an error like this in your response body? If so can you let me know the code you're getting and that will help us get to the bottom of this.
rjhillyer at April 29th, 2014 17:41 — #6
OK. I will have to code to capture this error. I'll let you know. Thanks Pete
pete_onepagecrm at May 6th, 2014 03:45 — #7
Bob, have you had any luck getting to the bottom of this?
Let me know if there's anything else I can do for you.
rjhillyer at May 12th, 2014 15:07 — #8
I tried to capture the response body. Using .Net C#.
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
I can't read the response driectly, because it throws the error. So I have to look in the error object.
It is a System.Web.WebException object. I can't find that json response in there. Not sure where to look. Any ideas?
pawelsmolinski at May 13th, 2014 04:37 — #9
WebException object contains Response method which can be used to fetch error response details. See more: http://msdn.microsoft.com/en-us/library/system.net.webexception(v=vs.110).aspx
rjhillyer at May 13th, 2014 12:43 — #10
Which item in the response method contains the response body in the format that Pete suggested it could appear? Where do I get the status number (108)?
pete_onepagecrm at May 14th, 2014 06:59 — #11
@rjhillyer , what are you getting from the Response method?
rjhillyer at May 14th, 2014 11:55 — #12
This one I did for a not found rather than a text>140 chars. But I can't see a status number for this eiither
Sorry for the long reply:
- ex.Response {System.Net.HttpWebResponse} System.Net.WebResponse {System.Net.HttpWebResponse}
- [System.Net.HttpWebResponse] {System.Net.HttpWebResponse} System.Net.HttpWebResponse
- base {System.Net.HttpWebResponse} System.Net.WebResponse {System.Net.HttpWebResponse}
+ base {System.Net.HttpWebResponse} System.MarshalByRefObject {System.Net.HttpWebResponse}
ContentLength -1 long
ContentType "application/json; charset=utf-8" string
+ Headers {Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=300
Vary: Accept-Encoding,Accept-Encoding
Status: 404 Not Found
X-OnePageCRM-BuildID: 14699:e7c12c1c99ac
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
X-OnePageCRM-Error: resource_not_found
X-UA-Compatible: IE=Edge,chrome=1
X-Request-Id: ba4b3a4a7cc383bffc404fe65b98b946
X-Runtime: 0.143106
X-Rack-Cache: invalidate, pass
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 14 May 2014 14:50:59 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Server: nginx
X-Powered-By: Phusion Passenger
} System.Net.WebHeaderCollection
IsFromCache false bool
IsMutuallyAuthenticated false bool
+ ResponseUri {https://app.onepagecrm.com/api/notes.json} System.Uri
SupportsHeaders true bool
+ Non-Public members
CharacterSet "utf-8" string
ContentEncoding "" string
ContentLength -1 long
ContentType "application/json; charset=utf-8" string
- Cookies {System.Net.CookieCollection} System.Net.CookieCollection
Count 0 int
IsReadOnly true bool
IsSynchronized false bool
+ SyncRoot {System.Net.CookieCollection} object {System.Net.CookieCollection}
+ Non-Public members
- Headers {Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=300
Vary: Accept-Encoding,Accept-Encoding
Status: 404 Not Found
X-OnePageCRM-BuildID: 14699:e7c12c1c99ac
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
X-OnePageCRM-Error: resource_not_found
X-UA-Compatible: IE=Edge,chrome=1
X-Request-Id: ba4b3a4a7cc383bffc404fe65b98b946
X-Runtime: 0.143106
X-Rack-Cache: invalidate, pass
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 14 May 2014 14:50:59 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Server: nginx
X-Powered-By: Phusion Passenger
} System.Net.WebHeaderCollection
+ base {Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=300
Vary: Accept-Encoding,Accept-Encoding
Status: 404 Not Found
X-OnePageCRM-BuildID: 14699:e7c12c1c99ac
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
X-OnePageCRM-Error: resource_not_found
X-UA-Compatible: IE=Edge,chrome=1
X-Request-Id: ba4b3a4a7cc383bffc404fe65b98b946
X-Runtime: 0.143106
X-Rack-Cache: invalidate, pass
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 14 May 2014 14:50:59 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Server: nginx
X-Powered-By: Phusion Passenger
} System.Collections.Specialized.NameValueCollection {System.Net.WebHeaderCollection}
- AllKeys {string[21]} string[]
[0] "Transfer-Encoding" string
[1] "Connection" string
[2] "Keep-Alive" string
[3] "Vary" string
[4] "Status" string
[5] "X-OnePageCRM-BuildID" string
[6] "Pragma" string
[7] "X-Frame-Options" string
[8] "Access-Control-Allow-Origin" string
[9] "X-OnePageCRM-Error" string
[10] "X-UA-Compatible" string
[11] "X-Request-Id" string
[12] "X-Runtime" string
[13] "X-Rack-Cache" string
[14] "Cache-Control" string
[15] "Content-Type" string
[16] "Date" string
[17] "Expires" string
[18] "P3P" string
[19] "Server" string
[20] "X-Powered-By" string
Count 21 int
- Keys {System.Collections.Specialized.NameObjectCollectionBase.KeysCollection} System.Collections.Specialized.NameObjectCollectionBase.KeysCollection
Count 21 int
+ Non-Public members
+ Static members
+ Non-Public members
IsMutuallyAuthenticated false bool
+ LastModified {14/05/2014 8:54:46 AM} System.DateTime
Method "POST" string
+ ProtocolVersion {1.1} System.Version
- ResponseUri {https://app.onepagecrm.com/api/notes.json} System.Uri
AbsolutePath "/api/notes.json" string
AbsoluteUri "https://app.onepagecrm.com/api/notes.json" string
Authority "app.onepagecrm.com" string
DnsSafeHost "app.onepagecrm.com" string
Fragment "" string
Host "app.onepagecrm.com" string
HostNameType Dns System.UriHostNameType
IsAbsoluteUri true bool
IsDefaultPort true bool
IsFile false bool
IsLoopback false bool
IsUnc false bool
LocalPath "/api/notes.json" string
OriginalString "https://app.onepagecrm.com/api/notes.json" string
PathAndQuery "/api/notes.json" string
Port 443 int
Query "" string
Scheme "https" string
- Segments {string[3]} string[]
[0] "/" string
[1] "api/" string
[2] "notes.json" string
UserEscaped false bool
UserInfo "" string
+ Static members
+ Non-Public members
Server "nginx" string
StatusCode NotFound System.Net.HttpStatusCode
StatusDescription "Not Found" string
SupportsHeaders true bool
+ Non-Public members
+ base {System.Net.HttpWebResponse} System.MarshalByRefObject {System.Net.HttpWebResponse}
ContentLength -1 long
ContentType "application/json; charset=utf-8" string
- Headers {Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=300
Vary: Accept-Encoding,Accept-Encoding
Status: 404 Not Found
X-OnePageCRM-BuildID: 14699:e7c12c1c99ac
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
X-OnePageCRM-Error: resource_not_found
X-UA-Compatible: IE=Edge,chrome=1
X-Request-Id: ba4b3a4a7cc383bffc404fe65b98b946
X-Runtime: 0.143106
X-Rack-Cache: invalidate, pass
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 14 May 2014 14:50:59 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Server: nginx
X-Powered-By: Phusion Passenger
} System.Net.WebHeaderCollection
+ base {Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=300
Vary: Accept-Encoding,Accept-Encoding
Status: 404 Not Found
X-OnePageCRM-BuildID: 14699:e7c12c1c99ac
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
X-OnePageCRM-Error: resource_not_found
X-UA-Compatible: IE=Edge,chrome=1
X-Request-Id: ba4b3a4a7cc383bffc404fe65b98b946
X-Runtime: 0.143106
X-Rack-Cache: invalidate, pass
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 14 May 2014 14:50:59 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Server: nginx
X-Powered-By: Phusion Passenger
} System.Collections.Specialized.NameValueCollection {System.Net.WebHeaderCollection}
- AllKeys {string[21]} string[]
[0] "Transfer-Encoding" string
[1] "Connection" string
[2] "Keep-Alive" string
[3] "Vary" string
[4] "Status" string
[5] "X-OnePageCRM-BuildID" string
[6] "Pragma" string
[7] "X-Frame-Options" string
[8] "Access-Control-Allow-Origin" string
[9] "X-OnePageCRM-Error" string
[10] "X-UA-Compatible" string
[11] "X-Request-Id" string
[12] "X-Runtime" string
[13] "X-Rack-Cache" string
[14] "Cache-Control" string
[15] "Content-Type" string
[16] "Date" string
[17] "Expires" string
[18] "P3P" string
[19] "Server" string
[20] "X-Powered-By" string
Count 21 int
- Keys {System.Collections.Specialized.NameObjectCollectionBase.KeysCollection} System.Collections.Specialized.NameObjectCollectionBase.KeysCollection
Count 21 int
+ Non-Public members
+ Static members
+ Non-Public members
IsFromCache false bool
IsMutuallyAuthenticated false bool
- ResponseUri {https://app.onepagecrm.com/api/notes.json} System.Uri
AbsolutePath "/api/notes.json" string
AbsoluteUri "https://app.onepagecrm.com/api/notes.json" string
Authority "app.onepagecrm.com" string
DnsSafeHost "app.onepagecrm.com" string
Fragment "" string
Host "app.onepagecrm.com" string
HostNameType Dns System.UriHostNameType
IsAbsoluteUri true bool
IsDefaultPort true bool
IsFile false bool
IsLoopback false bool
IsUnc false bool
LocalPath "/api/notes.json" string
OriginalString "https://app.onepagecrm.com/api/notes.json" string
PathAndQuery "/api/notes.json" string
Port 443 int
Query "" string
Scheme "https" string
- Segments {string[3]} string[]
[0] "/" string
[1] "api/" string
[2] "notes.json" string
UserEscaped false bool
UserInfo "" string
+ Static members
+ Non-Public members
SupportsHeaders true bool
+ Non-Public members
pete_onepagecrm at May 15th, 2014 08:45 — #13
@rjhillyer It looks like C# might ignore the custom response if it gets a 404 error.
We're not C# experts here, but I found this link which might help?
rjhillyer at May 22nd, 2014 14:01 — #14
Well, that article seems to apply more to sending out special codes.
I did some more searching and found a way to capture your response.
try {
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
catch (WebException ex) {
using (var stream = ex.Response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
string customError = reader.ReadToEnd();
}
}
catch (Exception exInner) { }
pete_onepagecrm at May 23rd, 2014 05:55 — #15
That's great Bob, thanks for letting me know.
Did you find the code causing the trouble yet?
rjhillyer at May 23rd, 2014 13:14 — #16
I have to upload it now to capture. Should get something by Monday hopefully.
rjhillyer at May 29th, 2014 13:57 — #17
The upload finally was able to proceed.
At long last. Here is the code being returned:
The remote server returned an error: (400) Bad Request., Custom Error: {"status":108,"message":"Invalid request data","error_name":"invalid_request_data"}
rjhillyer at May 29th, 2014 13:59 — #18
So does this mean for sure that my next action text is > 140 chars, or could there be something else?
pete_onepagecrm at May 30th, 2014 05:51 — #19
Hi Bob, good detective work. An error like this can indicate that the action text is > 140 chars.
It could also indicate that the action_id isn't correct.
rjhillyer at May 30th, 2014 10:39 — #20
Oh, that's interesting. OK, let me show you some of the steps I am taking.
1) the very LAST thing I do to the action text before sending it on is this:
if (strNewAction.Length > 140) { strNewAction = strNewAction.Substring(0, 137) + "..."; }
so I really doubt I am breaking the 140 rule
2) I have a client and I use an identifier to search my database for the CID, the assignee_ID, and login credentials of the assignee. Then I do a GET from actions.json based on the CID in question using the login credentials of the assignee. I go through the actions and if the "done" is false, I then see if the assignee_ID of the action matches the one from my database. If it does, then I take that "action_id", "name," and "date", change the "name" and possibly the "date", and then do a PUT to actions/.json. If there is no action found that is marked "done" and belongs to the assignee_ID, then I do a POST to actions.json for that CID, date, name, and make the assignee_ID from my database.
My code works most of the time, but sometimes gets the error we have been talking about. My thoughts are that maybe A) I may have the assignee_ID wrong in my database in some cases, B) some sort of post issue.
Since I keep the action text to 140 characters (and I have tested text equal to 140) and since I take the action_ID right from the existing actions, it makes me wonder if I might just be getting the assignee_ID wrong, but if that was the case, then it should just overwrite any action assigned to that assignee_ID and if there was no action for that assignee, it would just post one.
Still not sure what this could be
next page →
Powered by Discourse, best viewed with JavaScript enabled