Send a timstamp in JSON via Postman - json

I'm fairly new to working with REST APIs and Postman and I'm looking for a way to include a timestamp as a string in a POST request body via Postman.
According to the Postman docs, there is a dynamic variable {{$timestamp}} which can be used in the request body. However, when I try to use it, I get a 400 back from the endpoint I am POSTing to with the message "malformed data."
Here are a couple of variations I have tried:
variation 1
[
{
"from_number": "+123456789",
"messages": [
{
"text": "Message at" {{$timestamp}},
"to_number": "+123456789"
}
]
}
]
variation 2
[
{
"from_number": "+123456789",
"messages": [
{
"text": "Message at {{$timestamp}}",
"to_number": "+123456789"
}
]
}
]
variation 3
[
{
"from_number": "+123456789",
"messages": [
{
"text": "Message at " + {{$timestamp}},
"to_number": "+123456789"
}
]
}
]
All of these have returned the same error
{
"errorMessage": "malformed data",
"error": true
}

Thanks #NimS and #JAAulde: Varation 2 is the correct answer. The problem must have been a typo.

Related

Why can't I submit a record to Zoho Sales Order API?

I'm trying to insert a record using the Zoho API, and I keep receiving a cryptic INVALID_DATA error message.
I've tried using their sample code which, of course, produces another error. And the sample code they provide for running in Postman also produces an error.
Their docs are lacking and inconsistent, and nobody is getting back to me on their message boards, and I'm getting desperate as I need to have this done today. Can anyone see what I'm doing wrong?
This is what I'm submitting via Postman
{
"data": [
{
"Owner": {
"id": "3938209039489388001"
},
"Contact_Name": {
"id": "398129039938498309"
},
"Subject": "Test",
"Product_Details": [
{
"product": {
"id": "1234567"
},
"quantity": 1
}
]
}
]
}
This is the error response
{
"data": [
{
"code": "INVALID_DATA",
"details": {
"api_name": "product",
"index": 0,
"parent_api_name": "Product_Details"
},
"message": "invalid data",
"status": "error"
}
]
}
The solution was to POST a product first, then grab that product ID and insert it under Product_Details. This is not documented, so I assumed the product would be created automatically, which it wasn't.

Google fit API add multiple data type based on scope

I am using google fit API with multiple user scopes. How can I add multiple data type for each source. If possible, why I cannot add this as a datasource.
{
"dataStreamName":"MyDataSource",
"type":"derived",
"application":{
"detailsUrl":"http://example.com",
"name":"Foo Example App",
"version":"1"
},
"dataType":[
{
//1st data type
"name":"com.google.step_count.delta",
"field":[
{
"name":"steps",
"format":"int"
}
]
},
{
//2nd data type
"name":"com.google.calories.bmr",
"field":[
{
"name":"calories",
"format":"float"
}
]
}
],
"device":{
"manufacturer":"Example Manufacturer",
"model":"ExampleTablet",
"type":"tablet",
"uid":"1000001",
"version":"1.0"
}
}
And I got a response of
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"dataType\" at 'data_source': Proto field is not repeating, cannot start list.",
"errors": [
{
"message": "Invalid JSON payload received. Unknown name \"dataType\" at 'data_source': Proto field is not repeating, cannot start list.",
"reason": "invalid"
}
],
"status": "INVALID_ARGUMENT"
}
}
But when I only add one scope which is like this
{
"dataStreamName":"MyDataSource",
"type":"derived",
"application":{
"detailsUrl":"http://example.com",
"name":"Foo Example App",
"version":"1"
},
"dataType":{
"name":"com.google.step_count.delta",
"field":[
{
"name":"steps",
"format":"integer"
}
]
},
"device":{
"manufacturer":"Example Manufacturer",
"model":"ExampleTablet",
"type":"tablet",
"uid":"1000001",
"version":"1.0"
}
}
It returns me 200 which is successful. Did I miss something or is what I am trying to do possible? Thanks.
Google fit API reference
https://developers.google.com/fit/rest/v1/reference/users/dataSources/create
I believe the nesting your trying to do has to go at the dataField level rather than the dataType level.
dataType.field[]
I think this because I noticed that 'field[]' is a collection while dataType is not.

Invalid OpenAPI JSON file - Expected type object but found type string for security definition

I'm getting a validation error for the following openApi.json file, which I'm trying to configure in order to use JWT authentication to my Endpoints service on Google Cloud. I'm following this guide - https://cloud.google.com/endpoints/docs/openapi/service-account-authentication#configure_auth. The error can be easily reproduced by pasting and validating my sample using the Swagger online parser. The error message is:
Swagger schema validation failed.
Expected type object but found type string at #/paths//my/api/get/responses/200/description/securityDefinitions/mySecurityDefinition/x-google-jwks_uri/x-google-issuer/type/flow/authorizationUrl/security/0
JSON_OBJECT_VALIDATION_FAILED
I'd like to understand why I get the message Expected type object but found type string. The error message looks like it's maybe complaining about the security definition, but I'm not seeing why.
openapi.json
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "my-app-hostname.appspot.com"
},
"host": "my-app-hostname.appspot.com",
"basePath": "/api",
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"security" : [
"mySecurityDefinition"
],
"securityDefinitions": {
"mySecurityDefinition": {
"authorizationUrl": "",
"flow": "implicit",
"type": "oauth2",
"x-google-issuer": "myServiceAccountEmailAddress",
"x-google-jwks_uri": "https://www.googleapis.com/robot/v1/metadata/x509/myServiceAccountEmailAddress"
}
},
"paths": {
"/my/api": {
"get": {
"responses": {
"200": {
"description": "A successful response"
}
}
}
}
}
}
What am I doing wrong? If I change the 1st object in the security array to this, then it doesn't validate, but the parser gives no error message:
"security" : [
{
"mySecurityDefinition": [ ]
}
],

Generate POSTMAN in webpage with JSON or something

I have a restAPI code from a programmer from JNE, company stands for delivery service.
They say that this API can be run in POSTMAN (Google Chrome Application)
It works fine in the POSTMAN, where in this application I just need to insert the request URL (which I have got from the JNE company) and two header of keys and values as follow;
KEY VALUE
----------------------------------------------
username mycompany
api key 4534645756864234523424
The method for this is POST and when I posted it, it gives me the results as how expected.
My problem now is, how can I run this code in my page, so that I don't need to run this in postman.
I am just this day going to learn JSON if anybody can help me out with this.
[UPDATE QUESTION 1]
{
"version":1,
"collections":
[
{
"id":"c8b12431-8586-cbdd-aef7-056ec177509a",
"name":"asdasdadasdasdasd",
"timestamp":1415593872130,
"requests":
[
{
"collectionId":"c8b12431-8586-cbdd-aef7-056ec177509a",
"id":"d1b2ed66-781d-d02e-c4eb-0416dd3e07a1",
"name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
"description":"",
"url":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
"method":"POST",
"headers":"username: mycompany\napi_key:089a12ffb8cd5009bdfa4ba5bdb9ee26\n",
"data":
[
{
"key":"username",
"value":"mycompany",
"type":"text"
},
{
"key":"api_key",
"value":"dsfsdfsdfs98d98sdfsdf9898dsfs",
"type":"text"
}
],
"dataMode":"params",
"timestamp":0,
"responses":[],
"version":2
}
]
}
],
"environments":[],
"headerPresets":[],
"globals":[]
}
From the update question above; my first question is: ]
In what format I have to save this file: JSON? or WHAT?
Should I save this file in one file with my webpage? or Can I save it as external file?
From the code above, I get the result as follow:
{
"detail": [
{
"code": "CGK10000",
"label": "JAKARTA"
},
{
"code": "CGK10100",
"label": "JAKARTA BARAT"
},
{
"code": "CGK10300",
"label": "JAKARTA PUSAT"
},
{
"code": "CGK10200",
"label": "JAKARTA SELATAN"
},
{
"code": "CGK10500",
"label": "JAKARTA TIMUR"
},
{
"code": "CGK10400",
"label": "JAKARTA UTARA"
}
]
}
If you have a look to the "label" it is generated from the key of the last string in the: "name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
The result of the label from the last string of jak, is what I want to insert in a dropdown html tag, in where the user will choose that (the name of the location).
[Update with complete code]
POST /tracing/mycompany/origin/key/jak HTTP/1.1
Host: api.jne.co.id:8889
Content-Type: application/json
username: mycompany
api_key: 089a12ffb8cd5009bdfa4ba5bdb9ee26
{
"version":1,
"collections":
[
{
"id":"c8b12431-8586-cbdd-aef7-056ec177509a",
"name":"asdasdadasdasdasd",
"timestamp":1415593872130,
"requests":
[
{
"collectionId":"c8b12431-8586-cbdd-aef7-056ec177509a",
"id":"d1b2ed66-781d-d02e-c4eb-0416dd3e07a1",
"name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jakarta",
"description":"",
"url":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jakarta",
"method":"POST",
"headers":"username: mycompany\napi_key:089a12ffb8cd5009bdfa4ba5bdb9ee26\n",
"data":
[
{
"key":"username",
"value":"mycompany",
"type":"text"
},
{
"key":"api_key",
"value":"089a12ffb8cd5009bdfa4ba5bdb9ee26",
"type":"text"
}
],
"dataMode":"params",
"timestamp":0,
"responses":[],
"version":2
}
]
}
],
"environments":[],
"headerPresets":[],
"globals":[]
}
I have saved this file as jne.json and jne.html but the browser just show the full code insted show the result as how the postman does. I think there are many things I am missing here.
The POST request would look something like the following
POST /tracing/mycompany/origin/key/jak HTTP/1.1
Host: api.jne.co.id:8889
Content-Type: application/json
username: mycompany
api_key: 089a12ffb8cd5009bdfa4ba5bdb9ee26
{
... your JSON ...
}
You can save JSON with the .json file extension. If your request is always the same you can save this file with your webpage, but normally an HTTP request is constructed before sending (that means you normally send different requests).
To fill the dropdown list you just have to parse the JSON response.

Asana- Invalid Field

I'm POST'ing the following JSON to asana's "tasks" endpoint.
{
"data": {
"options": {
"fields": [
"name",
"notes"
]
},
"workspace": <valid number>,
"assignee": <valid number>
}
}
It's giving me a "Invalid field" error every time. I've read through the API a few times now and this JOSN looks exactly how the API says it should. Any ideas?
Asana API for those of you who want to help out: Asana API Documentation
(I work for Asana)
The "options" field is a sibling of the "data" field, not a child. This is mentioned in the docs, but perhaps we aren't providing clarifying examples to make it more obvious.
If you change your request to look like this:
{
"options": {
"fields": [
"name",
"notes"
]
},
"data": {
"workspace": <valid number>,
"assignee": <valid number>
}
}
things should work.