You need to sign in to do that
Don't have an account?
Martin Cadman 2016
Superbadge: Data Integration Specialist
Challenge #3
After a number of mis-starts, I have passed this challenge. However, I am not convinced that my code is doing what it should (or anything!).
If I don't specifiy the full https path in my callout (and just use the named credential as I beleive I should) I get an unathorized error:
14:28:29:005 CALLOUT_REQUEST [24]|System.HttpRequest[Endpoint=callout:ProjectService, Method=POST]
14:28:29:348 CALLOUT_RESPONSE [24]|System.HttpResponse[Status=Unauthorized, StatusCode=401]
The details in the named credential appear fine (I can use them and login manually).
If I include the URL in the callout (!!!?), I appear to authorize ok - however the response 'Not Found' is the same result I get if I connect to the site and logon manually:
13:36:08:006 CALLOUT_REQUEST [24]|System.HttpRequest[Endpoint=callout:ProjectService/https://sb-integration-pms.herokuapp.com/projects, Method=POST]
13:36:08:393 CALLOUT_RESPONSE [24]|System.HttpResponse[Status=Not Found, StatusCode=404]
I'm sure I'm doing something silly here but can't spot it.
BTW
I also passed the challenge with no code to change the opportunity stage to submitted project/resubmit project. This doesn't matter but building this code does make repeated tests faster.
After a number of mis-starts, I have passed this challenge. However, I am not convinced that my code is doing what it should (or anything!).
If I don't specifiy the full https path in my callout (and just use the named credential as I beleive I should) I get an unathorized error:
14:28:29:005 CALLOUT_REQUEST [24]|System.HttpRequest[Endpoint=callout:ProjectService, Method=POST]
14:28:29:348 CALLOUT_RESPONSE [24]|System.HttpResponse[Status=Unauthorized, StatusCode=401]
The details in the named credential appear fine (I can use them and login manually).
If I include the URL in the callout (!!!?), I appear to authorize ok - however the response 'Not Found' is the same result I get if I connect to the site and logon manually:
13:36:08:006 CALLOUT_REQUEST [24]|System.HttpRequest[Endpoint=callout:ProjectService/https://sb-integration-pms.herokuapp.com/projects, Method=POST]
13:36:08:393 CALLOUT_RESPONSE [24]|System.HttpResponse[Status=Not Found, StatusCode=404]
I'm sure I'm doing something silly here but can't spot it.
BTW
I also passed the challenge with no code to change the opportunity stage to submitted project/resubmit project. This doesn't matter but building this code does make repeated tests faster.
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:ProjectService/projects');
req.setHeader('token', '0661666e-8a92-xxx-a162-a977ce6826f2');
req.setHeader('Content-Type', 'application/json');
String body='{"opportunityId":"00641000004EKmFAAW","opportunityName":"Super-Duper Big Deal","accountName":"ACME Corp, Inc.","closeDate":"2016-10-30","amount":150000}';
req.setBody(body); //array buffer
req.setMethod('POST');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug('Body:'+res.getBody());
Or
Body:Bad Request. Your JSON does not contain the correct case-sensitive keys. Please reference the sample JSON.with this code
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:ProjectService/projects');
req.setHeader('token', '0661666e-8a92-4287-a162-a977ce6826f2');
req.setHeader('Content-Type', 'JSON');
String body='{"opportunityId":"00641000004EKmFAAW","opportunityName":"Super-Duper Big Deal","accountName":"ACME Corp, Inc.","closeDate":"2016-10-30","amount":150000}';
req.setBody(body); //array buffer
req.setMethod('POST');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug('Body:'+res.getBody());
Any idea ?
setHeader('Content-Type', 'application/json') is required
401 error above - bad password in the Named Credential
404 error above - specifying the URL as well as the Named Credential is a stupid thing to do
I tried both Named Credentials and Remote site setting but getting same error
System.HttpRequest[Endpoint=https://sb-integration-pms.herokuapp.com/projects, Method=POST]
System.HttpRequest[Endpoint=callout:ProjectService, Method=POST]
I re-registerd the org and tried with new token as well but no success.
I am surprised that I have completed challege#3 even i am getting error Status=Unauthorized, StatusCode=401 while trying to connect PMS.
Any thoughts what mistake am i making?
It doesn't appear that the named credential is being used to set the endpoint in the 'ProjectCalloutService' class.
Close errors"
I have the named credential and token setup correct.
Also the code is
ServiceTokens__c serviceToken = ServiceTokens__c.getvalues('ProjectServiceToken');
String ST = serviceToken.Token__c;
req.setEndpoint('callout.ProjectService');
req.setMethod('POST');
req.setHeader('token', ST);
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
Any idea ?
Hope this will help :)
String jsonInput = '{"opportunityId": "00641000004EKmFAAW","opportunityName": "Super-Duper Big Deal","accountName": "ACME Corp, Inc.","closeDate": "2016-10-30", "amount": 150000}';
String serviceToken = ServiceTokens__c.getValues('ProjectServiceToken').Token__c;
http h = new http();
httpRequest req = new httpRequest();
req.setEndpoint('callout:ProjectService');
req.setHeader('token',serviceToken);
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
req.setMethod('POST');
req.setBody(jsonInput);
httpResponse resp = h.send(req);
system.debug(resp);
Anyone getting a 500 error here... just wait a couple hours or so and try again. Waiting seemed to work. Something must be going on in the background on Heroku to enable the program.
Thanks
Derek Emmett Brown