web Requests
The Notecard can perform requests and obtain responses from 3rd party APIs and
services with the web
API requests.
Caveats When Performing Web Requests:
The Notecard must be in
continuous
mode and connected to Notehub to perform any of the requests below. For example:{ "req": "hub.set", "product": "com.your-company.your-name:your_product", "mode": "continuous" }
The endpoint to the 3rd party API or service must be configured as a proxy Route in Notehub as a "Proxy for Device Web Requests" type.
The Notecard can only accept valid JSON in response to a GET, POST, or PUT request unless you override the default
content
argument ofapplication/json
with the appropriate MIME type.
For more information on these requirements, see the Web Transactions Guide.
web.get
Performs a simple HTTP or HTTPS GET
request against an external endpoint,
and returns the response to the Notecard.
route
string
Alias for a Proxy Route in Notehub.
name
string (optional)
A web URL endpoint relative to the host configured in the Proxy Route. URL
parameters may be added to this argument as well (e.g. /getLatest?id=1
).
content
string (optional)
The MIME type of the body or payload of the response. Default is
application/json
.
seconds
(Added in v1.5.6)
integer (optional)
If specified, overrides the default 90 second timeout.
async
(Added in v5.1.1)
boolean (optional)
If true
, the Notecard performs the web request asynchronously, and returns
control to the host without waiting for a response from Notehub.
Response Members
result
integer
The HTTP Status Code.
body
JSON object
The JSON response body from the external service, if any. The maximum response size from the service is 8192 bytes.
payload
base64 string
A base64-encoded binary payload from the external service, if any. The maximum response size from the service is 8192 bytes.
{ "result": 200, "body": { "temp": 75, "humidity": 49 } }
web.post
Performs a simple HTTP or HTTPS POST
request against an external endpoint,
and returns the response to the Notecard.
route
string
Alias for a Proxy Route in Notehub.
name
string (optional)
A web URL endpoint relative to the host configured in the Proxy Route. URL
parameters may be added to this argument as well (e.g. /addReading?id=1
).
body
JSON object (optional)
The JSON body to send with the request.
payload
base64 string (optional)
A base64-encoded binary payload. A web.post
may have either a body
or a
payload
, but may NOT have both. Be aware that Notehub will decode the payload
as it is delivered to the endpoint.
Learn more about sending large payloads with the Notecard.
content
string (optional)
The MIME type of the body or payload of the response. Default is
application/json
.
seconds
(Added in v1.5.6)
integer (optional)
If specified, overrides the default 90 second timeout.
total
(Added in v3.2.1)
integer (optional)
When sending large payloads to Notehub in fragments across several web.post
requests, the total size, in bytes, of the binary payload across all fragments.
offset
(Added in v3.2.1)
integer (optional)
When sending payload fragments, the number of bytes of the binary payload to offset from 0 when reassembling on the Notehub once all fragments have been received.
status
(Added in v3.2.1)
string (optional)
A 32-character hex-encoded MD5 sum of the payload or payload fragment. Used by Notehub to perform verification upon receipt.
max
(Added in v3.2.1)
integer (optional)
The maximum size of the response from the remote server, in bytes. Useful if a memory-constrained host wants to limit the response size. Default (and maximum value) is 8192.
verify
(Added in v3.2.1)
boolean (optional)
true
to request verification from Notehub once the payload or payload
fragment is received. Automatically set to true
when status
is supplied.
async
(Added in v5.1.1)
boolean (optional)
If true
, the Notecard performs the web request asynchronously, and returns
control to the host without waiting for a response from Notehub.
Response Members
result
integer
The HTTP Status Code.
body
JSON object
The JSON response body from the external service, if any. The maximum response size from the service is 8192 bytes.
payload
base64 string
A base64-encoded binary payload from the external service, if any. The maximum response size from the service is 8192 bytes.
status
string
If a payload
is returned in the response, this is a 32-character hex-encoded
MD5 sum of the payload or payload fragment. Useful for the host to check for any
I2C/UART corruption.
{ "result": 201 }
web.put
Performs a simple HTTP or HTTPS PUT
request against an external endpoint,
and returns the response to the Notecard.
route
string
Alias for a Proxy Route in Notehub.
name
string (optional)
A web URL endpoint relative to the host configured in the Proxy Route. URL
parameters may be added to this argument as well (e.g. /updateReading?id=1
).
body
JSON object (optional)
The JSON body to send with the request.
payload
base64 string (optional)
A base64-encoded binary payload. A web.put
may have either a body
or a
payload
, but may NOT have both. Be aware that Notehub will decode the payload
as it is delivered to the endpoint.
Learn more about sending large payloads with the Notecard.
content
string (optional)
The MIME type of the body or payload of the response. Default is
application/json
.
seconds
(Added in v1.5.6)
integer (optional)
If specified, overrides the default 90 second timeout.
total
(Added in v3.2.1)
integer (optional)
When sending large payloads to Notehub in fragments across several web.put
requests, the total size, in bytes, of the binary payload across all fragments.
offset
(Added in v3.2.1)
integer (optional)
When sending payload fragments, the number of bytes of the binary payload to offset from 0 when reassembling on the Notehub once all fragments have been received.
status
(Added in v3.2.1)
string (optional)
A 32-character hex-encoded MD5 sum of the payload or payload fragment. Used by Notehub to perform verification upon receipt.
max
(Added in v3.2.1)
integer (optional)
The maximum size of the response from the remote server, in bytes. Useful if a memory-constrained host wants to limit the response size. Default (and maximum value) is 8192.
verify
(Added in v3.2.1)
boolean (optional)
true
to request verification from Notehub once the payload or payload
fragment is received. Automatically set to true
when status
is supplied.
async
(Added in v5.1.1)
boolean (optional)
If true
, the Notecard performs the web request asynchronously, and returns
control to the host without waiting for a response from Notehub.
Response Members
result
integer
The HTTP Status Code.
body
JSON object
The JSON response body from the external service, if any. The maximum response size from the service is 8192 bytes.
payload
base64 string
A base64-encoded binary payload from the external service, if any. The maximum response size from the service is 8192 bytes.
status
string
If a payload
is returned in the response, this is a 32-character hex-encoded
MD5 sum of the payload or payload fragment. Useful for the host to check for any
I2C/UART corruption.
{ "result": 204 }
web.delete (Added in v1.5.6)
Performs a simple HTTP or HTTPS DELETE
request against an external endpoint,
and returns the response to the Notecard.
route
string
Alias for a Proxy Route in Notehub.
name
string (optional)
A web URL endpoint relative to the host configured in the Proxy Route. URL
parameters may be added to this argument as well (e.g. /deleteReading?id=1
).
content
string (optional)
The MIME type of the body or payload of the response. Default is
application/json
.
seconds
(Added in v1.5.6)
integer (optional)
If specified, overrides the default 90 second timeout.
async
(Added in v5.1.1)
boolean (optional)
If true
, the Notecard performs the web request asynchronously, and returns
control to the host without waiting for a response from Notehub.
Response Members
result
integer
The HTTP Status Code.
body
JSON object
The JSON response body from the external service, if any. The maximum response size from the service is 8192 bytes.
payload
base64 string
A base64-encoded binary payload from the external service, if any. The maximum response size from the service is 8192 bytes.
status
string
If a payload
is returned in the response, this is a 32-character hex-encoded
MD5 sum of the payload or payload fragment. Useful for the host to check for any
I2C/UART corruption.
{ "result": 204 }