AnsweredAssumed Answered

POST failing using Insert from URL

Question asked by smanus on Dec 9, 2018
Latest reply on Dec 9, 2018 by smanus

Hi all-

 

I'm trying to test a simple POST to a 3rd party API that works okay in curl but is giving me a 400 Bad Request Server error when I try from within FM16.  Here's the curl that works fine:

 

curl -v -H "API-AUTHENTICATION:ddff8e2165fa4d6988e064dccd3d75a3:a6740b4d02d741559a7c702c93d4b69c90d4afcc6e4b4aac89c6e0a11e3048ee" -H "Content-type: application/json" -X POST -d '{"comments":"Here on time","finalized":true,"finalized_date":"2016-08-01 14:55:32","misc_amount":0,"overrides_po_costs":false,"purchase_order":"/resources/PurchaseOrder/457/","shipping_and_handling":0,"shipping_terms":"","tax":0,"vendor_invoice_no":"678933"}' 'https://yolopizza.revelup.com/resources/PurchaseOrderInvoice/'

 

Here's my FM script:

 

Set Error Capture [ Off ]

Set Variable [ $$post; Value:JSONSetElement ( "{}" ; ["comments"; "Here on time"; JSONString] ; ["finalized"; True; JSONBoolean] ;

["finalized_date"; "2016-08-01 14:55:32"; JSONString] ; ["misc_amount"; "0.00"; JSONNumber] ;
["overrides_po_costs"; False; JSONBoolean] ;
["purchase_order"; "/resources/PurchaseOrder/457/"; JSONString] ; ["shipping_and_handling"; "0.00"; JSONNumber] ; ["shipping_terms"; ""; JSONString] ;

["tax"; "0.00"; JSONNumber] ; ["vendor_invoice_no"; "678933"; JSONString] ) ]

Set Variable [ $call; Value:"https://yolopizza.revelup. com/resources/PurchaseOrderInvoice/" ]

Set Variable [ $api_key; Value:"ddff8e2165fa4d6988e064dccd3d75a3" ]

Set Variable [ $api_secret; Value:"a6740b4d02d741559a7c702c93d4b69c90d4afcc6e4b4aac89c6e0a11e3048e e" ]

Set Variable [ $header; Value:"API-AUTHENTICATION:" & $api_key & ":" & $api_secret ]

Insert from URL [ $$RESPONSE; $call; cURL options: "-v -H " & $header & " -H Content- type:application/json --dump-header $$httpHeader --trace-ascii $$httpTrace -d " & $$post ]
[ Select; No dialog ]

 

 

Here's the end of the trace that shows the data being sent but being rejected:

 

=> Send data, 17 bytes (0x11)

0000: {"comments":"Here

== Info: upload completely sent off: 17 out of 17 bytes

<= Recv SSL data, 5 bytes (0x5)

0000: .....

<= Recv header, 26 bytes (0x1a)

0000: HTTP/1.1 400 Bad Request

<= Recv header, 15 bytes (0xf)

0000: Server: nginx

<= Recv header, 37 bytes (0x25)

0000: Date: Sun, 09 Dec 2018 14:29:03 GMT

<= Recv header, 32 bytes (0x20)

0000: Content-Type: application/json

<= Recv header, 28 bytes (0x1c)

0000: Transfer-Encoding: chunked

<= Recv header, 24 bytes (0x18)

0000: Connection: keep-alive

<= Recv header, 31 bytes (0x1f)

0000: Vary: Accept-Language, Cookie

<= Recv header, 29 bytes (0x1d)

0000: X-Frame-Options: SAMEORIGIN

<= Recv header, 22 bytes (0x16)

0000: Content-Language: en

<= Recv header, 93 bytes (0x5d)

0000: Set-Cookie: tree_state="{}"; expires=Tue, 08-Jan-2019 14:29:03 G

0040: MT; Max-Age=2592000; Path=/

<= Recv header, 2 bytes (0x2)

0000:

<= Recv data, 23 bytes (0x17)

0000: d

0003: {"error": ""}

0012: 0

0015:

== Info: Curl_http_done: called premature == 0

== Info: Connection #0 to host yolopizza.revelup.com left intact

 

Anyone understand what my problem might be?

 

Thanks!

Outcomes