Skip to content

HTTP PUT

Type: http-put  ·  Package: HTTP Activities v1.0.5  ·  Output: ZoanHttpResponse

Sends a PUT request, usually to fully replace an existing resource. You send the whole object with its new values; the API replaces the resource with what you send.

Same as POST but with the PUT method: sends body to the url of a specific resource (which usually includes its id) and returns a ZoanHttpResponse.

  • Body: with the default contentType (application/json), body is converted to JSON; with any other contentType, it is sent as text. Always UTF-8. See body and Content-Type.
  • Status codes: 2xx succeeds; any other code makes the activity fail — see what makes the activity fail.
  • Timeouts: 30 s to connect and, by default, 5 min for the whole request (timeout parameter). When they run out, the activity fails with a normal error that Try / Catch and Retry catch — see timeouts.
  • Idempotent: sending the same PUT twice leaves the resource the same, so it is safe to retry with Retry.
ParameterTypeDefaultDescription
urlstring—Absolute URL of the resource to replace (usually includes its id).
bodyobject—The complete resource with its new values: dictionary or list (→ JSON) or text (for other contentType values). With a JSON contentType, a text is sent as a JSON string; if you have JSON in a text, use parseJson(text).
ParameterTypeDefaultDescription
contentTypestring"application/json"Media type of the body, without parameters (application/json, text/xml…). charset=utf-8 is added for you.
headersDictionary—Extra headers (name → value), in the JSON editor. Content headers are ignored. See headers.
authorizationDictionary—Authentication in the JSON editor: bearer, basic or apikey. See authentication.
timeoutint300Seconds to wait for the whole request (connection, sending and answer); maximum 3600, decimals allowed (0.5). Since version 1.0.5. See timeouts.

Returns a ZoanHttpResponse with .StatusCode (2xx, typically 200 or 204), .Ok (always true in an output you receive), .Body (JSON → dictionary/list; anything else → text; empty → "") and .Headers.

MessageCause and fix
The server answered HTTP 404 (Not Found) to the PUT request.The server answered with a non-2xx code (404 missing resource, 400 incomplete data, 401/403, 5xx). Handle the expected ones with Try / Catch.
The format of value 'application/json; charset=utf-8' is invalid.contentType has parameters. Keep only the media type.
No such host is known. (or another system network error)There was no response. error.Type is "HttpRequestException"; use Retry for intermittent outages.
The PUT request to api.example.com did not finish within 300 s (timeout). Raise 'timeout' if the service takes longer.The server did not answer within timeout. error.Type is \"TimeoutException\": catch it with Try / Catch or retry with Retry; if the API is slow by nature, raise timeout. If connecting fails, the message says Could not connect to … within 30 s.
An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.url is not absolute. Include https://.
'url' is required.The url expression evaluated to null.

Replace a customer’s data and confirm the result:

HTTP PUT
url = "https://api.erp.com/customers/" + customerId
body = new Dictionary<string, object> { ["name"] = newName, ["taxId"] = taxId, ["active"] = false }
authorization = { "type": "bearer", "token": credential("erp-api")["value"] }
→ output: resp
Log message = "Customer " + customerId + " updated (HTTP " + resp.StatusCode + ")"