You need to sign in to do that
Don't have an account?
smita bhargava
status code=400 issue
I am learning the basics of rest api integration.
I am using two sfdc developer orgnzs. flipkart(is the source) and hdfc(is the destination).
I am calling a webservice defined in destination from source to check if an account name already exists.
I am using OAUTH2.0 authentication and I have access token generated.
code in destination side.
when I check debug logs I am getting statuscode=400 (bad request).
Can any one tell me where is the issue and how to resolve it?
smita
I am using two sfdc developer orgnzs. flipkart(is the source) and hdfc(is the destination).
I am calling a webservice defined in destination from source to check if an account name already exists.
I am using OAUTH2.0 authentication and I have access token generated.
code in destination side.
code in destination side =================== @RestResource(UrlMapping='/RestMapping1/*') global class RestObject { @HTTPGet webservice static void SearchByAccountName() { String account_name=RestContext.request.params.get('accName'); system.debug('account Name found in destination = '+account_Name); } } code in source side ============== Public PageReference SearchByAccountName() { if (accesstoken != NULL) { HTTP h = new HTTP(); HTTPRequest req = new HTTPrequest(); req.setMethod('GET'); req.setHeader('Authorization','Bearer '+accesstoken); req.setHeader('Content-Type','application/json; charset=UTF-8'); req.setHeader('Accept','application/json'); acc=[select Name from Account where Name LIKE '%Sunshine%' LIMIT 1]; req.setEndpoint('https://ap2.salesforce.com/services/apexrest/RestMapping1?accName='+acc.Name); HTTPResponse resp; try { resp=h.send(req); string json=resp.getBody(); system.debug('json = '+json); } catch(system.CallOutException ex) { }
when I check debug logs I am getting statuscode=400 (bad request).
Can any one tell me where is the issue and how to resolve it?
smita
You need to encode the parameter value in url (Line number 37) EncodingUtil.urlEncode(acc.Name, 'UTF-8')
All Answers
did you check what your query is returning at line 35?
I checked the query in dev console. It is returning a sngle record. Here is the result from debug logs
Endpoint=https://ap2.salesforce.com/services/apexrest/RestMapping1?accName=sunshine Hospitals, Method=GET]
System.HttpResponse[Status=Unknown Version, StatusCode=400] 08:25:40.0 (797210626)|HEAP_ALLOCATE|[222]|Bytes:77
You need to encode the parameter value in url (Line number 37) EncodingUtil.urlEncode(acc.Name, 'UTF-8')
Thanks that worked