According to the documentation for HTTPPost and HTTPPost2, you should be able to retrieve the HTTP status code from the response payload, but I can't seem to get this to work. I can only retrieve the response body. Here's a request that I've tried with both functions:
%%[
var @httpPostCallStatus, @httpPost2CallStatus, @httpPost2Response
HTTPPost('https://httpbin.org/post', 'text/html', 'hello', @httpPostCallStatus)
HTTPPost2('https://httpbin.org/post', 'text/html', 'hello', true, @httpPost2CallStatus, @httpPost2Response)
]%%
HTTPPost call status: %%=v(@httpPostCallStatus)=%%
HTTPPost2 call status: %%=v(@httpPost2CallStatus)=%%
HTTPPost2 reponse: %%=v(@httpPost2Response)=%%
This returns the following:
HTTPPost call status: {
"args": {},
"data": "hello",
"files": {},
"form": {},
"headers": {
"Content-Length": "5",
"Content-Type": "text/html",
"Host": "httpbin.org",
"Singularityheader": "appId=796*ctrlguid=1485623992*acctguid=c6f9028b-9792-49f7-a36f-01b2bd8101dc*btid=68226*guid=c4b32254-2d88-4188-8196-a3e17dde6485*exitguid=104*unresolvedexitid=0*cidfrom=251*etypeorder=HTTP*cidto={[UNRESOLVED][3609894]}"
},
"json": null,
"origin": "136.147.128.1",
"url": "https://httpbin.org/post"
}
HTTPPost2 call status: {
"args": {},
"data": "hello",
"files": {},
"form": {},
"headers": {
"Content-Length": "5",
"Content-Type": "text/html",
"Host": "httpbin.org",
"Singularityheader": "appId=796*ctrlguid=1485623992*acctguid=c6f9028b-9792-49f7-a36f-01b2bd8101dc*btid=68226*guid=c4b32254-2d88-4188-8196-a3e17dde6485*exitguid=106*unresolvedexitid=0*cidfrom=251*etypeorder=HTTP*cidto={[UNRESOLVED][3609894]}"
},
"json": null,
"origin": "136.147.128.1",
"url": "https://httpbin.org/post"
}
HTTPPost2 reponse: System.Data.DataRow[]
Am I doing something wrong here, or is the documentation simply incorrect?
Best Answer
You have to set the variable to get the HTTP status code from the response payload.
Result: 200
Also, you can get the status directly by running the HTTPPost2 function.
Result: 200