Getting 404 error in Rest Api guest-cart. [GET] V1/guest-carts/{cart-id} - rest

I am trying to get my created guest cart through the REST api after i create it with POST /guest-cart/ and use the returned ID.
when i try to get the created cart with
/rest/all/V1/guest-carts/{Cart-id}
It returns a 404 error
{ "message": "No such entity with %fieldName = %fieldValue", "parameters": { "fieldName": "cartId", "fieldValue": null },
This is also true when i try it with swagger
curl -X GET "http://website.com/default/rest/all/V1/guest-carts/{cart-id}" -H "accept: application/json" -H "Authorization: Bearer {token}"
in both cases I send it with the Authorization and content-type header
I tried making the call in Swagger and Postman
I expect to recieve an empty Guest-cart

See if you can get a response from the items call using GET - in your case, the response should have no items.
/V1/guest-carts/{cartId}/items
If this doesnt work, you may have other issues. Cart ID typically expires after 1 hour, so get a new Cart ID for this and future tests. Look into your Magento logs to see if any errors show up with additional info.

Related

Postman - submit token

I'm new with Postman,(until today never used it)
I want this API request to run through Postman (pretty output)
curl -X GET http://localhost/api/myapi/subnets/ --header "token: token"
Through Postman i can easily get this token:
http://localhost/api/myapi/user/
Output:
{
"code": 200,
"success": true,
"data": {
"token": "token",
"expires": "2019-09-13 19:29:55"
},
"time": 0.013
}
But i don't know how to pass --header "token:token" part to Postman
I tried a couple of suggestion from Stack Overflow but none seems to work.
In the header section you can add the header param you want:
just write in the "key" column.
The Authorization section is an easy way to add the common "Authorization" header. All others header should be added by "Headers" section.
The request in my image is the same of your curl command.
Found it on this link: https://www.quora.com/How-can-I-convert-cURL-code-to-Postman
http://localhost/api/myapi/subnets/?Authorization= token

Request Sync always returns 404 : "Error: Requested entity was not found."

I'm having a hard time implementing requestSync. It always returns
"error": {
"code": 404,
"message": "Requested entity was not found.",
"status": "NOT_FOUND"
}
I use Node.js/Express for the backend. The linking/unlinking with the Google Home app work and my actions work as well. It's really the requestSync part that fails.
The closest ticket I've found, though not exactly the same, is this one.
Things I've tried
agentUserId is a string, but if I pass it a number it returns a 400 with the message "Invalid value at 'agent_user_id'".
tried sending agent_user_id instead of agentUserId, this returns a 404 the same error as when I send a agentUserId
tried removing the "async:true" part of the body. did not notice a difference.
during SYNC, hardcoded the value of the agentUserId to eliminate possibility that I'm sending the wrong one. I use that same agentUserId during requestSync and this fails.
tried linking/unlinking multiple times in the google home app
another interesting thing to note : when opening up the "Test Suite" from the actions on google console, I put in that same agentUserId + service account key, and it registers it well : I'm able to see my devices listed correctly. Which leads me to believe that my agentUserId is correct (this may be a false assumption)
I'm 100% sure HomeGraph is enabled as I can see data on the charts in the "Overview" section of the HomeGraph API part of the console.
This is what the curl looks like (same as from the example)
curl -i -s -X POST -H "Content-Type: application/json" -d "{agent_us
er_id: \"1\"}" "https://homegraph.googleapis.com/v1/devices:requestSyn
c?key=API_KEY"
(my agentUserId is 1 in this case)
And this is what it looks like in code :
const res = await fetch(
`https://homegraph.googleapis.com/v1/devices:requestSync?key=${config.googleApiKey}`,
{
method: 'POST',
body: JSON.stringify({
agentUserId: String(userId),
async: true,
}),
headers: { 'Content-Type': 'application/json' },
},
);
Regardless of what I do, the result is always :
"error": {
"code": 404,
"message": "Requested entity was not found.",
"status": "NOT_FOUND"
}
I don't know where else to look to identify this problem. Any pointers would help. Thank you
Finally found the answer.
It wasn't too far from the one I had posted above. Although my problem is that when I generated an API key, the google home cloud console opened the wrong project by default. I had the wrong API key all along.

How to use postman to send a request to timekit api

I don't know much about how to use an API, and I am just trying to get a basic understanding so I can use the Timekit.io API in a JS app I am going to build, so to start I though I should try and use postman to learn how to send a request. In the Timekit documentation for finding a time from a resource ie: a persons calendar they say to use this curl command.
curl --request POST \
--url https://api.timekit.io/v2/findtime \
--header 'Content-Type: application/json' \
--user :live_api_key_7nzvc7wsBQQISLeFSVhROys9V1bUJ1z7 \
--data '{
"resource_ids": ["78a4d873-2a68-41c6-bdd4-c0ca5b35efd3"],
"filters": { "or": [
{"specific_day_and_time":{"day":"Monday","start":9,"end":13}},
{"specific_day_and_time":{"day":"Wednesday","start":10,"end": 16}}
]},
"future": "2 days",
"length": "30 minutes"
}'
I am trying to figure out what I put into postman itself so I get the correct Json values. So far I have selected a POST request with the url https://api.timekit.io/v2/findtime and a header with the key Content-Type and value application/json I have no idea where to put the user,data,rsource_ids,filters,future & length Here is a screenshot of my post man setup.
--user sets the authentication. If an authentication type is not specified, then it will default to Basic Authentication. In Postman, click the "Authentication" tab and from the "Type" dropdown, select "Basic Auth". You can then input the username and password into the appropriate fields. With the --user flag, the value should be <username>:<password>. So your case, there is no username specified, so I guess you don't need to input it, just use the api key for the password.
--data is the JSON request body. You can input this entire value (within the single quotes ') into the "Body" tab. Select the "Body" tab, and within the tab, select the "raw" radio button, and from the dropdown to the right, select "JSON (application/json)". Now just put the entire JSON into the text area.
{
"resource_ids": ["78a4d873-2a68-41c6-bdd4-c0ca5b35efd3"],
"filters": {
"or": [
{ "specific_day_and_time":{ "day":"Monday", "start":9, "end":13 } },
{ "specific_day_and_time":{ "day":"Wednesday", "start":10, "end": 16 } }
]
},
"future": "2 days",
"length": "30 minutes"
}
You could just drop the curl request straight into Postman via the Import feature, this would populate the whole request in the application for you.
In the top left of the application UI, select the Import button and then select the 'raw' text option (it’s the last one) - paste the curl request text into the text box. Once imported, that should do the rest for you, if it’s a valid format.

Return different MIME types based on Accept header parameter on Amazon AWS API Gateway

Could you explain how to setup Amazon AWS API Gateway to return different documents based on the request HTTP Accept header?
Two examples:
curl --request GET 'http://api.sample.com/v1/hello' --header 'Accept: text/HTML'
<html><body>Hello, World!</body></html>
curl --request GET 'http://api.sample.com/v1/hello' --header 'Accept: application/JSON'
{data:"Hello, World!"}
If you want API Gateway to act as a template rendering engine I don't think that will work but you could let your Lambda know which content-type the requester is looking for by passing the Accept header to your Lambda and let Lambda decide what to return.
You will need a mapping template(under Method Execution -> Integration Request -> Mapping Templates) for each Content-Type(data the requester is sending) you want to support.
A sample mapping template which takes the input from the request and transforms it into the JSON event so Lambda can work with it:
{
"headers": {
// maybe there is an easier way for Lambda to get this but I couldn't find it in the context object so I believe APIG needs to send it like this
"Accept": "$input.params('Accept')"
},
"message": "$input.params('message')"
}
Then in your lambda you can check the Accept header and send back a response based on that:
module.exports.handler = function(event, context) {
var msg = event.message.toUpperCase()
if(event.headers.Accept === 'text/html') {
return context.succeed('<html><body><h1>Transformed Message: ' + msg + '</h1></body></html>');
}
// all other requests get JSON...
context.succeed({transformedMessage: msg});
};
And the last step is back in API Gateway - under Method Execution -> Method RESPONSE -> Add Response. The Model can just be empty but set the Content-Type to text/html. This will tell API Gateway to let whatever you send back from Lambda pass through to any requests where Accept: text/html
EDIT: This answer assumed you are using Lambda as the backend but really the same idea could be applied to almost any backend service that you're using.

POST multiple worklogs in one JIRA Rest request

I have the following data, hoping to insert two worklogs at once into the same issue using the rest url:
curl -u jogbra:jogbra -X POST -k --data #data_holiday.txt -H "Content-Type: application/json" https://jira.myworkplace/jira/rest/api/2/issue/4371/worklog
data_holiday.txt contains:
{
"comment": "Christmas Day",
"started": "2015-12-25T08:50:09.423+0000",
"timeSpent": "8h 0m"
},
{
"comment": "Labor Day",
"started": "2015-09-07T08:50:09.423+0000",
"timeSpent": "8h 0m"
}
It only gets the first holiday (with or without the comma).
End goal is to automate the population of holidays. I don't see a way of making more than one worklog with one request, so should I resort to using a loop to call curl? If I do that, do I need to create one data file for each holiday?
I see from this post that google has solved this batch request issue with a "batch" endpoint. How would I accomplish this in jira?
Sorry, but in JIRA only one worklog per on request: https://docs.atlassian.com/jira/REST/latest/#d2e795