Can't create category via WP REST API - wordpress

I am attempting to create categories via the WordPress REST API but getting the following error:
{
"code": "rest_cannot_create",
"message": "Sorry, you are not allowed to create terms in this taxonomy.",
"data": {
"status": 401
}
}
The REST API user I'm using is an administrator. I've confirmed that I'm authenticating correctly because I can create pages via the REST API.
Here is the JSON I'm submitting to https://hostname.net/wp-json/wp/v2/categories
{
"description":"",
"name": "Test",
"slug": "test",
"parent": 51,
"meta": []
}
I've confirmed that the category with id 51 exists (created that via the UI). The content-type header is set to application/json.
What is the correct syntax to create a new category via the WP REST API?

Related

Can't create stack from template using Openstack Heat API

I'm trying to create a stack from a template using the Heat API. I'm using the API reference here as a guide. I have the following json in a file called single-server-template.json:
{
"stack_name": "api-test",
"template": {
"heat_template_version": "rocky",
"description": "Testing Heat API\n",
"resources": {
"server1": {
"type": "OS::Nova::Server",
"properties": {
"name": "Server1",
"image": "Ubuntu 22.04 (Jammy)",
"flavor": "alt.st1.small",
"key_name": "my_key",
"networks": "Internal"
}
}
}
}
}
I'm sending it with this: curl -X POST -H "X-Auth-Token:$OS_TOKEN" -d #single-server-template.json https://$OS_HOST_URL:8004/v1/$OS_PROJECT_ID/stacks
I've been at it for hours but no matter what I send I get a 400 error:
{"code": 400, "title": "Bad Request", "explanation": "The server could not comply with the request since it is either malformed or otherwise incorrect.", "error": {"type": "HTTPBadRequest", "traceback": null, "message": "The server could not comply with the request since it is either malformed or otherwise incorrect."}}
Things I've tried:
confirmed my environment vars are filled in correctly before sending
confirmed that the template itself is valid by spinning it up from the UI console
confirmed that other endpoints that require auth work as expected
screaming and/or crying
Can anyone confirm that what I've got is correct, or test it against your own openstack instance? The only other thing I can think of is that maybe my openstack provider has an issue with their API

Linked In API article thumbnails

I'm trying to migrate existing code that fetches organization posts from ugcPosts API to new versioned call of the Posts API(version 202210) and I'm facing issues with getting thumbnails for articles. Response that I get from Posts API doesn't contain thumbnail URL but instead it contains thumbnail URN(old ugcPost API returned thumbnail URL as a part of the post). Here is an example of an article post that I get from API
{
"isReshareDisabledByAuthor": false,
"createdAt": 1666603988797,
"lifecycleState": "PUBLISHED",
"lastModifiedAt": 1666603988797,
"visibility": "PUBLIC",
"publishedAt": 1666603988797,
"author": "urn:li:organization:1111",
"id": "urn:li:share:2222",
"distribution": {
"feedDistribution": "MAIN_FEED",
"thirdPartyDistributionChannels": []
},
"content": {
"article": {
"description": "some description",
"thumbnail": "urn:li:image:3333",
"source": "https://example.com",
"title": "some title"
}
},
"commentary": "some comment",
"lifecycleStateInfo": {
"isEditedByAuthor": false
}
}
I tried to use Images API to fetch thumbnail URL using a call
GET https://api.linkedin.com/rest/images/urn:li:image:3333
Unfortunately Linked In API responds with code 400 and message Invalid asset owner urn type provided: urn:li:article:4444
I don't get why it happens. Token that I'm using has enough permissions to fetch organization posts(token's scope contains permissions w_member_social, r_liteprofile, r_1st_connections_size, w_organization_social, r_member_social, r_organization_social, rw_organization_admin). Article id that presents in error message isn't anyhow connected to post id. It's also not clear why that asset is referenced as urn:li:article while the post itself is described as urn:li:share. To me it looks like Linked In API bug or am I doing something wrong?
Turns out there was a bug in Linked In API which was confirmed by their support. At this moment same calls work fine with version 202210

Getting a 400 Error when doing a simple text post

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

Integrating Contact Form 7 with third-party app

I am trying to send information from user submissions (Contact Form 7) to third-party app. I am using this plugin
https://wordpress.org/support/plugin/cf7-to-api/
The third-party app provided an access token and this example of creation request for me
curl -X "POST" "https://api.example.com/initial-params" \
-H 'Content-Type: application/json' \
-H 'X-Landing-Page-Access-Token: your-value-here ' \
-d $'{
"move": {
"date": "2018-09-01"
},
"consumer": {
"givenName": "Mike",
"phone": "234234242",
"email": "mike#example.com",
"familyName": "Simon"
},
"origin": {
"zip": 3245,
"beds": 8
},
"destination": {
"zip": 12342
}
}'
and this is their documentation
An end consumer enters details onto a landing page. Once all details have been entered, the landing page POSTs to our API's Initial Params endpoint. Our app stores the parameters and generates a unique identifier. Once the API call to create Initial Params succeeds, the landing page automatically redirects to the survey web app with the identifier set as a URL parameter (e.g., ?identifier=xxx... )
- Important : Our survey web app must have received this import in order for follow-up
messaging to work if the consumer drops off. As a result, it is recommended to automatically
redirect to our survey web app after the Initial Params have been created as opposed to
requiring a button click.
When our survey web app loads, it queries our API to retrieve the parameters. With the
parameter information, it then initializes the survey web app and API to the state specified in the
Initial Parameters. Each screen that has input completely satisfied is automatically skipped. The consumer finishes the process on our survey web app. One this identifier has been generated, the landing page can redirect to our survey web app. This identifier should be passed along to our survey web app via the identifier URL parameter, which will in turn allow the provided consumer details to be loaded inside our app. Example link: https://api.example.com/?identifier=xxx
This is a creation response example the third-party app also provided
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Wed, 18 Jul 2018 16:55:04 GMT
Server: nginx
Content-Length: 380
Connection: Close
{
"status": [
{
"type": "ok"
}
],
"identifier":
"some-unique-identifier",
"serverTime": "247.334 ms"
}
So, I used this https://api.example.com/initial-params as the URL to post to, added the access token using this piece of code in functions.php
add_filter( 'qs_cf7_api_get_args', 'add_http_header' );
function add_http_header( $args ) {
$args['headers']['X-Landing-Page-Access-Token'] = 'example-access-token';
return $args;
}
and I used this in the JSON template
-d $'{
"move": {
"date": "[date]"
},
"consumer": {
"givenName": "[givenName]",
"phone": "[phone]",
"email": "[email]",
"familyName": "[familyName]"
},
"origin": {
"zip": [zip1]
},
"destination": {
"zip": [zip2]
}
}'
My questions are:
How can I check the result I get from them, to see if they are receiving the info and generating the identifier?
How to redirect to their landing page with the identifier in the end when a form is submitted? That identifier is a variable and is unique each time, which means somehow I have to redirect to a variable after submission.
Any help is much appreciated.
Thank you!

Triggering smart campaign and getting 603

I am trying to use Marketo smart campaign to send email data.
What I do is:
1) get or create Lead with addresse email
2) trigger smart campaign I've created with this lead_id and a couple of tokens I created on the folder containing the campaign.
That is, I am sending POST to https://.mktorest.com/rest/v1/campaigns/5826/trigger.json?access_token= with body
{
"input": {
"leads": [
{
"id": 2034349
}
],
"tokens": [
{
"name": "{{my.subject}}",
"value": "subj"
},
{
"name": "{{my.message}}",
"value": "the text"
}
]
}
}
And I get the response:
{u'errors': [{u'message': u'Access denied', u'code': u'603'}], u'requestId': u'c8f5#14c79fae723', u'success': False}
I was trying token names without "{{" and "}}", without "my." - the same result. The campaign exist and has this ID.
What's wrong here?
The role of the Marketo API user that you're using needs the "Execute Campaign" permission, and your current user is probably missing that permission. Unfortunately you can't edit the existing role. You'll need to create a new role, check that permission, and possibly also create a new API User.

Resources