For example, this users table
id
name
1
John Doe
2
Jane Doe
If I make an update request PUT http://{host}:{port}/users/1 and supply correct json body
{
"name": "John Roe"
}
Response (200)
{
"message": "Update Success"
}
It will return success request
And 404 Not Found for request like PUT http://{host}:{port}/users/3 with correct JSON body
And 400 Bad Request for request like PUT http://{host}:{port}/users/2 with incorrect JSON body like
Json Body:
{
"name": ""
}
ErrorResponse (400):
{
"message": "name is required"
}
But if i make a wrong request on no resource request like PUT http://{host}:{port}/users/3 and with incorrect JSON body
what do i return, is it 400 or 404 check first?
Related
Trying to migrate our calls away from the v2/ugcPosts endpoint to the new /rest/posts endpoint. I started off trying to create a text-only post as per the Text-Only Post Creation Sample Request
I copied and pasted the request body, changed the organization ID to my own, and included Authorization: Bearer {My Authorization Token}, X-Restli-Protocol-Version: 2.0.0, Content-Type: application/json, LinkedIn-Version:202207 as headers.
POST https://api.linkedin.com/rest/posts
{
"author": "urn:li:organization:***",
"commentary": "Sample text Post",
"visibility": "PUBLIC",
"distribution": {
"feedDistribution": "NONE",
"targetEntities": [],
"thirdPartyDistributionChannels": []
},
"lifecycleState": "PUBLISHED",
"isReshareDisabledByAuthor": false
}
However, when trying to post, I keep getting this 400 error.
{
"errorDetailType": "com.linkedin.common.error.BadRequest",
"code": "MISSING_REQUIRED_FIELD_FOR_DSC",
"message": "Field /adContext/dscAdAccount is required when the post is a Direct Sponsored Content, but missing in the request",
"errorDetails": {
"inputErrors": [
{
"description": "Field /adContext/dscAdAccount is required when the post is a Direct Sponsored Content, but missing in the request",
"input": {
"inputPath": {
"fieldPath": "/adContext/dscAdAccount"
}
},
"code": "MISSING_REQUIRED_FIELD_FOR_DSC"
}
]
},
"status": 400
}
I see that lifecycleState, distribution, visibility, commentary, author are all required, but adContext should be an optional field. I'm not sure what part of my request is indicating I'm trying to make a Direct Sponsored Content post - can someone take a look?
I've already tried
Removing the targetEntities and thirdPartyDistributionChannels parameters.
Removing isReshareDisabledByAuthor and the above.
Changing the feedDistribution to MAIN_FEED and NONE
Creating the post via the /v2/ugcPosts endpoint - meaning the authorization token and organization urn are correct
When I try to get all the comments below a facebook page post using the graph api explorer via
GET
https://graph.facebook.com/12.0/{post-id}?fields=comments
the answer looks like:
{
"error": {
"message": "(#200) Missing Permissions",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "AqyOUwmTl...3n5y-Br"
}
}
Why?
In case I just request the post like
GET
https://graph.facebook.com/12.0/{post-id}
I got back a valid answer:
{
"created_time": "2021-12-21T10:05:40+0000",
"message": "This is a test post.",
"id": "x0xxxxxxxxxx95_1xxxxxxxxx74"
}
This is kinda strange because I request these datas with an admin user of the facebook page and set the following permissions for the access token:
read_insights
pages_show_list
instagram_basic
publish_to_groups
pages_read_engagement
pages_read_user_content
pages_manage_posts
public_profile
Appreciate any help, thank you.
Instead of use "User token" you have to use "Page token"
I'm attempting to post images to organization linkedin pages. I'm working off of this documentation: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/ugc-post-api
So far I have the following working:
shareMediaCategory type "ARTICLE" shared to a person
shareMediaCategory type "ARTICLE" shared to an organization
shareMediaCategory type "IMAGE" shared to a person
When I attempt to post with shareMediaCategory type "IMAGE" to an organization, I get the following error response:
{
"message": "Internal Server Error",
"status": 500
}
Here is the url:
https://api.linkedin.com/v2/ugcPosts
The Headers (I have tried with and without all these headers):
Authorization:Bearer REDACTED
Content-Type:application/json
X-Restli-Protocol-Version:2.0.0
x-li-format:json
And the body:
{
"author":"urn:li:organization:2414183",
"lifecycleState":"PUBLISHED",
"specificContent":{
"com.linkedin.ugc.ShareContent":{
"shareCommentary":{
"text":"Hello"
},
"shareMediaCategory":"IMAGE",
"media":[
{
"status": "READY",
"description":{
"text":"Here is the description"
},
"media":"urn:li:digitalmediaAsset:C4E22AQFdCtnVOTxQCQ",
"title":{
"text":"This is the title"
}
}
]
}
},
"visibility":{
"com.linkedin.ugc.MemberNetworkVisibility":"PUBLIC"
}
}
The organization id is a LinkedIn test org ID: https://developer.linkedin.com/docs/guide/v2/organizations/development-testing
I can post articles to that ID, but images 500.
I've tested that the image has been uploaded successfully.
I have a consumer that has successfully created a pact file:
{
"consumer": {
"name": "CakeService"
},
"provider": {
"name": "CoolPersonService"
},
"interactions": [
{
"description": "A GET request to get a person who is cool",
"providerState": "There is a person who has IsCool set to 'true'6",
"request": {
"method": "get",
"path": "/CoolPersonService/persons/e674a2d0-57e6-471d-96dd-a91c0077283a",
"headers": {
"X-Requested-With": "XMLHttpRequest",
"CallerName": "Pact_Test#Local"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"body": {
"FirstName": "Some",
"LastName": "Name",
"IsCool": true
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
The problem is the test for the provider. It gets a 404 for
/CoolPersonService/persons/e674a2d0-57e6-471d-96dd-a91c0077283a
but if I send a GET to that route using an HTTP client, I get a 200 response and the expected data is returned.
Here's the output from the test run:
Test Name: EnsureSomethingApiHonoursPactwithConsumer
Test Outcome: Failed
Result Message:
Test method PactTests.PactTests.EnsureSomethingApiHonoursPactwithConsumer threw exception:
PactNet.PactFailureException: Pact verification failed. See output for details.
If the output is empty please provide a custom config.Outputters (IOutput) for your test framework, as we couldn't write to the console.
Result StandardOutput:
[2018-07-13 10:59:05] INFO WEBrick 1.3.1
[2018-07-13 10:59:05] INFO ruby 2.2.2 (2015-04-13) [i386-mingw32]
..........++++++
..........++++++
[2018-07-13 10:59:07] INFO
[2018-07-13 10:59:07] INFO WEBrick::HTTPServer#start: pid=109760 port=9222
[2018-07-13 10:59:07] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.
C:/redacted/PactTests/bin/Debug/pact-win32/lib/ruby/lib/ruby/2.2.0/openssl/buffering.rb:61:in `sysread'
C:/redacted/PactTests/bin/Debug/pact-win32/lib/ruby/lib/ruby/2.2.0/openssl/buffering.rb:61:in `fill_rbuff'
C:/redacted/PactTests/bin/Debug/pact-win32/lib/ruby/lib/ruby/2.2.0/openssl/buffering.rb:301:in `eof?'
C:/redacted/PactTests/bin/Debug/pact-win32/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
C:/redacted/PactTests/bin/Debug/pact-win32/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'
INFO: Reading pact at C:/redacted/PactTests/Pacts/cakeservice-coolpersonservice.json
Verifying a pact between CakeService and CoolPersonService
Given There is a person who has IsCool set to 'true'6
A GET request to get a person who is cool
with GET /CoolPersonService/persons/e674a2d0-57e6-471d-96dd-a91c0077283a
returns a response which
DEBUG: Setting up provider state 'There is a person who has IsCool set to 'true'6' for consumer 'CakeService' using provider state server at https://localhost/CoolPersonService/provider-states
I, [2018-07-13T10:59:11.805597 #102868] INFO -- request: POST https://localhost/CoolPersonService/provider-states
D, [2018-07-13T10:59:11.805597 #102868] DEBUG -- request: User-Agent: "Faraday v0.15.0"
Content-Type: "application/json"
I, [2018-07-13T10:59:23.352124 #102868] INFO -- response: Status 200
D, [2018-07-13T10:59:23.352625 #102868] DEBUG -- response: content-type: "application/json; charset=utf-8"
server: "redacted"
x-powered-by: "redacted"
date: "Fri, 13 Jul 2018 08:59:23 GMT"
connection: "close"
content-length: "84"
has status code 200 (FAILED - 1)
has a matching body (FAILED - 2)
includes headers
"Content-Type" which equals "application/json; charset=utf-8" (FAILED - 3)
Failures:
1) Verifying a pact between CakeService and CoolPersonService Given There is a person who has IsCool set to 'true'6 A GET request to get a person who is cool with GET /CoolPersonService/persons/e674a2d0-57e6-471d-96dd-a91c0077283a returns a response which has status code 200
Failure/Error: expect(response_status).to eql expected_response_status
expected: 200
got: 404
(compared using eql?)
2) Verifying a pact between CakeService and CoolPersonService Given There
is a person who has IsCool set to 'true'6 A GET request to get a person who is cool with GET /CoolPersonService/persons/e674a2d0-57e6-471d-96dd-a91c0077283a returns a response which has a matching body
>Failure/Error: expect(response_body).to match_term expected_response_body, diff_options, example
Encoding::UndefinedConversionError:
"\xC3" from ASCII-8BIT to UTF-8
3) Verifying a pact between CakeService and CoolPersonService Given There is a person who has IsCool set to 'true'6 A GET request to get a person who is cool with GET /CoolPersonService/persons/e674a2d0-57e6-471d-96dd-a91c0077283a returns a response which includes headers "Content-Type" which equals "application/json; charset=utf-8"
Failure/Error: expect(header_value).to match_header(name, expected_header_value)
Expected header "Content-Type" to equal "application/json; charset=utf-8", but was "text/html; charset=utf-8"
1 interaction, 1 failure
Failed interactions:
To re-run just this failing interaction, change the verify method to '.Verify(description: "A GET request to get a person who is cool", providerState: "There is a person who has IsCool set to 'true'6")'. Please do not check in this change! # A GET request to get a person who is cool given There is a person who has IsCool set to 'true'6
Here's the test method for the provider:
[TestMethod]
[TestCategory("Pact")]
public void EnsureSomethingApiHonoursPactwithConsumer()
{
const string serviceUri = "https://localhost/CoolPersonService";
var config = new PactVerifierConfig
{
Verbose = true
};
IPactVerifier pactVerifier = new PactVerifier(config);
pactVerifier
//.ProviderState($"{serviceUri}/provider-states")
.ProviderState($"{serviceUri}/provider-states")
.ServiceProvider("CoolPersonService", serviceUri)
.HonoursPactWith("CakeService")
.PactUri(#"C:\repos\Pact\API_CoolPersonService\PactTests\Pacts\cakeservice-coolpersonservice.json")
.Verify();
}
If you do a GET to a resource, and you get a 404, to me it sounds like the expected data is not present on the server - and that implies that the provider state has not been set up correctly.
Please read about provider states here https://docs.pact.io/getting-started/provider-states and here https://docs.pact.io/implementation-guides/ruby/provider-states#non-ruby-applications
If you do a POST to the same route and receive the response you expected from a GET, it may be that you have just created a new resource, and it is returning the body of the newly created resource.
I see that you are also having some encoding issues (Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8) I believe this has been fixed in the latest version of the underlying library (called the "pact standalone") so please ensure you have the latest version of pact-net. If you already do have the latest version of pact-net, then please raise an issue for the standalone to be upgraded.
For those still stumped by the issue, the "\xC3" from ASCII-8BIT to UTF-8 error also happens because the response by your provider couldn't be encoded e.g. your provider returns a 500 with a text/html response.
I'm applying to a job and the way they ask their applicants to send in a resume is through api. The directions ask:
Submit a POST request to our careers endpoint with a raw JSON request body:
Here is the json:
POST https://contact.website.com/jobs
{
"name": "Jane Applicant",
"email": "jane#hotmail.com",
"resume": "www.linktoresume.io",
"github": "github.com/jane",
"twitter": "#jane",
"website": "jane.com"
}
I used postman and chose post as the request then put in the correct url. I created keys and values for all of the fields they expected but I get a 404 bad request when I try to submit. Not sure what I'm doing wrong.
Ensure you've set the POST request format to JSON:
Comments aren't allowed in JSON so the body should just be
{
"name": "Jane Applicant",
"email": "jane#hotmail.com",
"resume": "www.linktoresume.io",
"github": "github.com/jane",
"twitter": "#jane",
"website": "jane.com"
}