Send DELETE request to an API endpoint using Nestful Sinatra - api

I want to send a DELETE request to an external API endpoint in a controller of my Sinatra application using nestful gem. I want to delete an event by sending a DELETE request to an endpoint of TeamSnap API. I have defined the following route in controller:
delete '/events/:id' do
delete 'https://api.teamsnap.com/v3/events/76674685'
end
When the API endpoint is hit with delete action, I get the following error:
*** "Delete" argument "endpoint" needs to be a number
If I send a get request to the API endpoint, I get the correct response. The get request I am using is given below:
get '/events/:id' do
get 'https://api.teamsnap.com/v3/events/76674685'
end
Can anyone confirm how can we send the DELETE request in the controller and what I am missing?
Thanks in advance!

[Solved]: I sent a DELETE request through Nestful using the following commands:
delete '/events/:id' do
request = Nestful::Request.new(endpoint, options)
request.method = 'delete'
response = request.execute
end
In the above piece of code, endpoint is "https://api.teamsnap.com/v3/events/EVENT_ID" and options is a hash which contains "Content-Type" and "Authorization" headers.

Related

API Post request with RobotFramework - Empty Param

I have the following POST request to configure in RobotFramework,
trouble is that the devs set up the request as presented in the screenshot.
This is a file id which you get from a file manager and download it.
My question is since there isn't any params, key, value like FileID etc.
What would be your best bet to send that request successfully via RobotFramework?
[screenshot][1]
The code that I have tried is:
Create Session mysession url=${test_env} verify=true
&{body}= Create Dictionary id=d67b39a6-4ea9-497f-a653-5eb2da418d23
&{header}= Create Dictionary Cache-Control=no-cache
${response}= POST On Session mysession /download data=${body} headers=${headers1}
Status Should Be OK ${response} #Check Status as OK```
Response I receive is Bad Request or Unsupported media
[1]: https://i.stack.imgur.com/kGyHo.png

Rest assured is giving 502 in return

I have simple get API
https://abc.xyz.co/index.php?route=efg/api/jkl&key=8454jdgdkjf948754&source=android&user_id=44
when i hit in browser I receive 200 OK but when i send request using rest assured it gives 502 in return.
Below is the code I am using
RestAssured.baseURI = "https://abc.xyz.co/";
RequestSpecification request = RestAssured.given();
Response response = request.queryParam("route", "efg/api/jkl").
queryParam("key","8454jdgdkjf948754").
queryParam("source","android").
queryParam("user_id","44").get("/index.php");
System.out.println(response.getStatusCode());
Someone please look into this
Note: URL shared is dummy URL but format is same as per my project
I think the problem is in base url and endpoint url:
"https://abc.xyz.co/"
"/index.php"
which gives together "https://abc.xyz.co//index.php", so one slash character "/" is redundant. Try to remove it either for base url or endpoint url and it should work.

API: Custom 404 not found error response structure

Considering this url: http://example.com/users/1/post/2/likes.
How can I correctly define structure of my 404 response, showing which item is not found? user, post or likes?
You can send an HTTP status code using the header() function, by starting the header with the status code number, followed by the message to send to the user.
header("404 " + $message);
The code that processes the parameters can determine which item isn't found, and put that into $message.

How to use SessionID using PostMan Rest client

Getting "SessionId" from response of user logged in session using POSTMAN REST client.
How to use the sessionId for other API calls of GET request?
Making a few assumptions about your data structure, store it as a variable:
//parse the response body as JSON
var data = JSON.parse(responseBody);
//create a global variable that can be reused in another call
postman.setGlobalVariable("sessionId", data.SessionId")
To use in a call to another endpoint:
http://www.example.com/{{sessionId}}

Deleting Webhooks

I have a shop with permission to read|write both orders and products. I setup some Webhooks and now I want to delete them. I am getting back 401 errors.
Starting with 4 webhooks
Trying to delete webhook 1982492
Error nil, Failed. Response code = 401. Response message = Unauthorized.
Trying to delete webhook 1982494
Error nil, Failed. Response code = 401. Response message = Unauthorized.
Trying to delete webhook 1982496
Error nil, Failed. Response code = 401. Response message = Unauthorized.
Trying to delete webhook 1982498
Error nil, Failed. Response code = 401. Response message = Unauthorized.
Ended with 4 webhooks
So, how does one delete Webhooks set on products and orders?
Webhooks (and ScriptTags) that are created by an app are automatically removed when the app is uninstalled. It looks like that might be what is happening here.
If you are doing this in response to an app/uninstalled webhook, there is no reason. It's already handled!
If you remove the endpoint that the webhook connects to, it will be deleted after 19 attempts to connect to it.
From the shopify docs (http://wiki.shopify.com/WebHook#Automatic_Retries_and_Deletion)
If an error is returned or a timeout occurs when sending a webhook,
Shopify will retry the same request for 48 hours using an exponential
back-off approach. In total 19 attempts will be made to deliver the
information.
You can also just delete the app, it will remove the webhooks
Here’s a conversation with my Shopify console to show it working correctly:
$ shopify console
using iliketurtles.myshopify.com
irb(main):001:0> include ShopifyAPI
=> Object
irb(main):002:0> w = Webhook.create topic: "orders/create", address: "http://whatever.place.com", format: "json"
=> #<ShopifyAPI::Webhook:0x007f8ff1895778 #attributes={"topic"=>"orders/create", "address"=>"http://whatever.place.com", "format"=>"json", "id"=>2026848, "created_at"=>"2012-08-10T15:11:25-04:00", "updated_at"=>"2012-08-10T15:11:25-04:00"}, #prefix_options={}, #persisted=true, #remote_errors=nil, #validation_context=nil, #errors=#<ActiveResource::Errors:0x007f8ff18948c8 #base=#<ShopifyAPI::Webhook:0x007f8ff1895778 ...>, #messages={}>>
irb(main):003:0> w.destroy
=> #<Net::HTTPOK 200 OK readbody=true>
As others have mentioned, I think your issue is permissions related.