I want to send different JSONs to an endpoint:
{{URL_API}}/products/{sku}
I need to update several information related to different products so i need to specify the product within the endpoint, i mean, i.e:
If you access this particular endpoint: {{URL_API}}/products/ you will get all the products but i need to specify the product that i want to update:
{{URL_API}}/products/99RE345GT
Take a look at this, i want to send a JSON like this:
{
"sku": "99RE345GT",
"price": "56665.0000",
"status": 1,
"group_prices": [
{
"group": "CLASS A",
"price": 145198.794
},
{
"group": "CLASS B",
"price": 145198.794
},
{
"group": "CLASS C",
"price": 145198.794
}
]
}
AND another one like this (both JSONs share the same structure BUT with different information):
{
"sku": "98PA345GT",
"price": "17534.0000",
"status": 1,
"group_prices": [
{
"group": "CLASS A",
"price": 145198.794
},
{
"group": "CLASS B",
"price": 145198.794
},
{
"group": "CLASS C",
"price": 145198.794
}
]
}
How can i do that?.I have already generated more than 200 JSONs for every product..
So, i have to update 200 products so i generated one JSON for every product, do you get me?
Following my example i would need to edit (somehow) the endpoint for every product and send a JSON, i.e:
since the first JSON has the SKU: 99RE345GT it should perform a http method: PUT over this enpoint:
{{URL_API}}/products/99RE345GT
Then, since the second JSON has the SKU: 98PA345GT it should perform a http method: PUT over this enpoint:
{{URL_API}}/products/98PA345GT
I have never done something like this before.. i read something about CSV + POSTMAN runner but i did not understand the way.
EDIT
I was working on a file (Excel file) and i did this:
So now i have all the different JSON for every product.
EDIT#2. It fails when it validates de Request_URL
I did this:
1)I created a new collection
2)I put this Request_url: {{URL_API}}/products/{{sku}}
3)I saved the changes and then, i went to the Collector Runner:
4)After cliking on the run button. i got this error message:
Invalid URL:
Have you tried adding those data sets to a CSV?
https://learning.postman.com/docs/postman/collection-runs/working-with-data-files/
If you have 2 column headers in a CSV file, one with sku and the other with requestBody - Add that variable value to the request body of the PUT request instead of the JSON.
sku,requestBody
99RE345GT, {JSON Payload}
98PA345GT, {...}
Add a couple of values under those headings to start with, once you prove that it works in the collection Runner.
Once you're happy, add the rest into the file. You may need to do some parsing of the JSON in the Pre-request Script but it should work.
Alternatively, use this template in the PUT request body and this create a CSV withe same column heading as the values in the {{...}} syntax. The values in the datafile will resolve to the values in the request body.
{
"sku": "{{sku}}",
"price": "{{price}}",
"status": {{status}},
"group_prices": [
{
"group": "{{groupA}}",
"price": {{groupAPrice}}
},
{
"group": "{{groupB}}",
"price": {{groupBPrice}}
},
{
"group": "{{groupC}}",
"price": {{groupCPrice}}
}
]
}
The CSV might look like this:
sku,price,status,groupA,groupAPrice,...
99RE345GT,1234,1,Group A, 555
98PA345GT,1235,1,Group A, 666
Related
Background: I work for a company that basically sells passes. Every order that is placed by the customer will contain N number of passes.
Issue: I have these JSON event-transaction files coming into a S3 bucket on a daily basis from DocumentDB (MongoDB). This JSON file is associated to the relevant type of event (insert, modify or delete) for every document key (which is an order in my case). The example below illustrates a "Insert" type of event that came through to the S3 bucket:
{
"_id": {
"_data": "11111111111111"
},
"operationType": "insert",
"clusterTime": {
"$timestamp": {
"t": 11111111,
"i": 1
}
},
"ns": {
"db": "abc",
"coll": "abc"
},
"documentKey": {
"_id": {
"$uuid": "abcabcabcabcabcabc"
}
},
"fullDocument": {
"_id": {
"$uuid": "abcabcabcabcabcabc"
},
"orderNumber": "1234567",
"externalOrderId": "12345678",
"orderDateTime": "2020-09-11T08:06:26Z[UTC]",
"attraction": "abc",
"entryDate": {
"$date": 2020-09-13
},
"entryTime": {
"$date": 04000000
},
"requestId": "abc",
"ticketUrl": "abc",
"tickets": [
{
"passId": "1111111",
"externalTicketId": "1234567"
},
{
"passId": "222222222",
"externalTicketId": "122442492"
}
],
"_class": "abc"
}
}
As we see above, every JSON file might contain N number of passes and every pass is - in turn - is associated to an external ticket id, which is a different column (as seen above). I want to use Pentaho Kettle to read these JSON files and load the data into the DW. I am aware of the Json input step and Row Normalizer that could then transpose "PassID 1", "PassID 2", "PassID 3"..."PassID N" columns into 1 unique column "Pass" and I would have to have to apply a similar logic to the other column "External ticket id". The problem with that approach is that it is quite static, as in, I need to "tell" Pentaho how many Passes are coming in advance in the Json input step. However what if tomorrow I have an order with 10 different passes? How can I do this dynamically to ensure the job will not break?
If you want a tabular output like
TicketUrl Pass ExternalTicketID
---------- ------ ----------------
abc PassID1Value1 ExTicketIDvalue1
abc PassID1Value2 ExTicketIDvalue2
abc PassID1Value3 ExTicketIDvalue3
And make incoming value dynamic based on JSON input file values, then you can download this transformation Updated Link
I found everything work dynamic in JSON input.
I was thinking about the possibility of executing a specific http method (POST or PUT) in POSTMAN without specifying it.
I mean; imagine if there was a field in a JSON file called: METHOD within 2 possible states: 'I' corresponding to INSERT OR POST and the another one: 'U' related to UPDATE or PUT
Something like this: (please, do note the field called "method"):
[
{
"sku": "95LB645R34ER",
"method": 'I'
"payload": {
"price": "147000",
"tax_percentage": "US-21",
"store_code": "B2BUSD",
"markup_top": "1.62",
"status": "1",
"group_prices": [
{
"group": "CLASS A",
"price": "700038.79",
"website": "B2BUSD"
}
]
}
},
{
"sku": "95TYS34344ER",
"method": 'U'
"payload": {
"price": "69978",
"tax_percentage": "US-21",
"store_code": "B2BUSD",
"markup_top": "9.99",
"status": "1",
"group_prices": [
{
"group": "CLASS B",
"price": "88888.79",
"website": "B2BUSD"
}
]
}
}
]
I would like to run that JSON using the Collection Runner but i have no idea how to do the trick. I mean, everytime i generate a collection i have to specify the HTTP METHOD otherwise it wont know what to do.
I want the program to adjust that by looking at the JSON file, if "method":'I' then, perform a POST or if "method":'U' execute a PUT method. Do you get me?
I've been reading the documentation but i did not find something like that or maybe i did not understand. I'm not an expert on POSTMAN :(
Can you help me?
EDIT:
Alright, i did this:
In the request UI, use the {{METHOD}} syntax where you would see the HTTP method. This is an editable field as it allows you to add custom HTTP methods.
In the file, use the METHOD key and any HTTP verb as the value. Ensure that it's part of each object in the datafile as you will need it for each iteration.
I'm trying to send several PUT request to a specific endpoint.
I am using a CSV file within the columns and values, the name of the different columns reference the different variables inside the body, do you get me?
This is the endpoint:
{{URL_API}}/products/{{sku}} --sku is the id of the product, i created that variable because i use it to pass the reference
This is the body that i use:
{
"price":"{{price}}",
"tax_percentage":"{{tax_percentage}}",
"store_code":"{{store_code}}",
"markup_top":"{{markup_top}}",
"status":"{{status}}",
"group_prices": [
{
"group":"{{class_a}}",
"price":"{{price_a}}",
"website":"{{website_a}}"
}
]
}
I don't want to use the body anymore.. sometimes some products have more tan 1 group of prices, i mean:
"group_prices": [
{
"group":"{{class_a}}",
"price":"{{price_a}}",
"website":"{{website_a}}"
},
{
"group":"{{class_b}}",
"price":"{{price_b}}",
"website":"{{website_b}}"
}
Is it possible to create something like this in the CSV file?
sku,requestBody
99RE345GT, {JSON Payload}
How should i declare the {JSON Payload}?
Can you help me?
EDIT:
This is the CSV file i used:
sku,price,tax_percentage,store_code,markup_top,status,class_a,price_a,website_a
95LB645R34ER,147000,US-21,B2BUSD,1.62,1,CLASS A,700038.79,B2BUSD
I want to pass the JSON within the CSV file, i mean
sku,requestBody
95LB645R34ER,{"price":"147000","tax_percentage":"US-21","store_code":"B2BUSD","markup_top":"1.62","status":"1","group_prices":
[{ "group":"CLASS A","price":"700038.79","website":"B2BUSD"}]}
Is it okay?Should i specify anything on the request body or not? I read the documentation posted in POSTMAN website but i did not find an example like this.
As you're using JSON data as a payload, I would use a JSON file rather than a CSV file in the Collection Runner. Use this as a template and save it as data.json, it's in the correct format accepted in the Runner.
[
{
"sku": "95LB645R34ER",
"payload": {
"price": "147000",
"tax_percentage": "US-21",
"store_code": "B2BUSD",
"markup_top": "1.62",
"status": "1",
"group_prices": [
{
"group": "CLASS A",
"price": "700038.79",
"website": "B2BUSD"
}
]
}
},
{
"sku": "MADEUPSKU",
"payload": {
"price": "99999",
"tax_percentage": "UK-99",
"store_code": "BLAH",
"markup_top": "9.99",
"status": "5",
"group_prices": [
{
"group": "CLASS B",
"price": "88888.79",
"website": "BLAH"
}
]
}
}
]
In the pre-request Script of the request, add this code. It's creating a new local variable from the data under the payload key in the data file. The data needs to be transformed into a string so it's using JSON.stringify() to do this.
pm.variables.set("JSONpayload", JSON.stringify(pm.iterationData.get('payload'), null, 2));
In the Request Body, add this:
{{JSONpayload}}
In the Collection Runner, select the Collection you would like to run and then select the data.json file that you previously created. Run the Collection.
I have access to a specific endpoint and i want to send several request to it at once but i am not 100% sure how to do that. I need to update several information related to different products so i need to specify the product within the endpoint, i mean, i.e:
If you access this particular endpoint: {{URL_API}}/products/ you will get all the products but i need to specify the product that i want to update:
{{URL_API}}/products/99RE345GT
Take a look at this, i want to send a JSON like this:
{
"sku": "99RE345GT",
"price": "56665.0000",
"status": 1,
"group_prices": [
{
"group": "CLASS A",
"price": 145198.794
},
{
"group": "CLASS B",
"price": 145198.794
},
{
"group": "CLASS C",
"price": 145198.794
}
]
}
AND another one like this (both JSONs share the same structure BUT with different information):
{
"sku": "98PA345GT",
"price": "17534.0000",
"status": 1,
"group_prices": [
{
"group": "CLASS A",
"price": 145198.794
},
{
"group": "CLASS B",
"price": 145198.794
},
{
"group": "CLASS C",
"price": 145198.794
}
]
}
How can i do that?.I have already generated more than 200 JSONs for every product..
So, i have to update 200 products so i generated one JSON for every product, do you get me?
Following my example i would need to edit (somehow) the endpoint for every product and send a JSON, i.e:
since the first JSON has the SKU: 99RE345GT it should perform a http method: PUT over this enpoint:
{{URL_API}}/products/99RE345GT
Then, since the second JSON has the SKU: 98PA345GT it should perform a http method: PUT over this enpoint:
{{URL_API}}/products/98PA345GT
I have never done something like this before.. i read something about CSV + POSTMAN runner but i did not understand the way.
Can you help me?
EDIT:
NEW UPDATE, if i use GET it throws "200" but i have to perform a PUT method:
without having access to your API docs or any indication which information is changing, i've made the following assumptions:
the PUT endpoint requires the SKU id in the endpoint
price, status, class A price, class B price, class C price are variables that are changing
first up create your request like so... identifying the variables.
next create your CSV file, making sure to use field/column names that match the variables.
final step, open Collection Runner and click Select File. once you've selected your CSV file, the iterations field will update with the number of rows in the file.
from there you just run your request and Postman will iterate through your file updating the products using the info in your CSV file.
first time poster here.
I uploaded a JSON file to Parse, one of my "columns" is an array of Pointers, but it's not pointing to the objectId field, like so:
{ "Tags": [
{
"__type": "Pointer",
"className": "TAGS_Categories",
"TAGS": "Tag1"
},
{
"__type": "Pointer",
"className": "TAGS_Categories",
"TAGS": "Tag2"
},
{
"__type": "Pointer",
"className": "TAGS_Categories",
"TAGS": "Tag3"
}
]
}
But after I imported the file to Parse, this is what appears under "Tags":
[{},{},{}]
My questions are:
1) is the data somehow hidden and it's just not appearing on the website's spreadsheet?
2) if it's truly gone, what would the best way to fix my JSON file so that it will appear?
Help :-(
When uploading content you need to follow the required data format. Pointers are connected by a combination of the class name and the object id for the item to connect to. Without the object id the item in the data store can't be found (a name lookup will not be performed).
You need to update your JSON payload to include the object ids.
Each item must have the fields:
{"__type":"Pointer","className":"XXXX","objectId":"YYYYYYYYYY"}