I have narrowed down why my apex post request is not sending to an external API. For some reason the JSON data that I serialize and send is wrong but everything works when I test it using Postman.
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('apilink.com');
req.setMethod('POST');
req.setHeader('Content-Type', 'application');
req.setHeader('Authorization', 'token');
String body = '{"gift_id": "12345", "recipients": [{"email":
"[email protected]", "fist_name": "Test", "last_name": "test",
"message": "Testing post", "type": "email"}]}';
req.setBody(JSON.serialize(body));
HttpResponse response = http.send(req);
I get error code 400 which means bad data is being sent.
Any help would be awesome.
req.setHeader
,req.setMethod
, etc.? You can edit your question to add any info.JSON.serialize
twice in the code? How r u building the body string? Looks like the string body is correctly formatted in json, try sending the string directly in the request body param