How to post data to kobotoolbox form using the Kobo API? - kobo

I'm working with the kobo REST API and I can get the structure's information from the form and the submitted data through the API, but when I try to send data to the form through a POST service, kobo returns the following message: "Your data for instance None has been already submitted.".
Is there any way to send POST data to a kobotoolbox form using its API?
I tried to send the data with the following POST request:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"name": "Foo" \
}' 'https://kf.kobotoolbox.org/assets/{form_id}/submissions/'
Where {form_id} is the id from my form in kobotoolbox
And the response was:
{
"detail": "Your data for instance None has been already submitted."
}

To submit data you need to POST to https://[kobocat url]/api/v1/submissions, e.g. https://kc.kobotoolbox.org/api/v1/submissions. The endpoint you tried is for retrieving submitted data.
This will work (for a form that contains a first_name and last_name question:
curl -X POST \
https://kc.kobotoolbox.org/api/v1/submissions.json \
-H 'Authorization: Token <yourAPItoken>' \
-H 'Content-Type: application/json' \
-d ' {
"id": "<kpi asset ID>",
"submission":
{
"last_name": "Suresh",
"first_name":"Ameen",
"meta": {
"instanceID": "uuid:8992c3c2-3418-4ba9-a8e2-b00e03ea36b6"
}
}
} '
<kpi asset ID> in this case refers to the unique form ID created in kobocat. This ID should be the same as the kpi asset ID, as long as you uploaded/created your form in the regular interface and deployed it.
You can find the ID by going to https://kf.kobotoolbox.org/assets/<kpi asset ID>/. In my case I get this:
{
"url": "https://kf.kobotoolbox.org/assets/aCNoKPdCX8gqcu4bHrHkUL/",
...
"deployment__identifier": "https://kc.kobotoolbox.org/<username>/forms/aCNoKPdCX8gqcu4bHrHkUL",
...
"uid": "aCNoKPdCX8gqcu4bHrHkUL",
]
}

Related

github's post pulls api throwing invalid head error for a forked head in same org

repo1: https://github.com/ORG_SPACE/MAIN_REPO
repo2(forked from repo1 in same workspace): https://github.com/ORG_SPACE/FORKED_REPO
feature branch created in forked repo: https://github.com/ORG_SPACE/FORKED_REPO/tree/FEATURE_BRANCH
Authorization details: used new finegrained PAT having pull:read&write,contents:read,Metadata:read access of both repos MAIN_REPO,FORKED_REPO
ISSUE: getting 422 error response
{
"message": "Validation Failed",
"errors": [
{
"resource": "PullRequest",
"field": "head",
"code": "invalid"
}
],
"documentation_url": "https://docs.github.com/rest/reference/pulls#create-a-pull-request"
}
while hitting below curl to raise pull request to merge 'ORG_SPACE/FORKED_REPO/tree/FEATURE_BRANCH' into 'ORG_SPACE/MAIN_REPO/tree/master'
curl --location --request POST 'https://api.github.com/repos/ORG_SPACE/MAIN_REPO/pulls' \
--header 'Authorization: Bearer MY_PAT' \
--header 'Accept: application/vnd.github+json' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "test",
"head": "ORG_SPACE:FEATURE_BRANCH",
"base": "master"
}'
tried this head value : "ORG_SPACE:FORKED_REPO/FEATURE_BRANCH" but didn't work.
raising pull request with same api working fine for both repos while head and base are in same repo.

Send whatsapp message without template

Is there a way to send a whatsapp message without template? I'm using the graph.facebook.com/v15.0 API and couldn't find any info about it
I'm trying this
curl --location --request POST 'https://graph.facebook.com/v15.0/{phoneId}/messages' \
--header 'Authorization: Bearer Token' \
--header 'Content-Type: application/json' \
--data-raw '{
"messaging_product": "whatsapp",
"to": "anyNumber",
"text": {
"body": "hello world!"
}
}'
Here's the error:
I was using the wrong payload. Thanks to #turivishal.
https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages
I was also using the wrong Bearer Token.

How To Pass Multiple Files in Binary Format in Form Data in Azure Logic App HTTP

i am trying to pass two files in multipart form in the Azure Logic App in binary format. But the upload request gets reject. When i pass the same request in postman, the request is successful. PFB the details.
Postman Request:
Header:
Postman Curl Request:
curl --location --request POST 'https://abc/kofax/claims' \
--header 'x-abchk-msgid: 0214945a-509a-48af-9df2-281352806421' \
--header 'Content-Type: multipart/mixed' \
--header 'Authorization: Bearer XXXXXXXXX' \
--form 'claimScanPDF=#"/C:/Users/ashutosh.bajpai/00000438.PDF"' \
--form 'claimScanJSON=#"/C:/Users/ashutosh.bajpai/kofax-op.json"'
Azure Logic App:
--testboundary
{
"$content-type": "multipart/mixed",
"$multipart": [
{
"body": #{concat(body('GETFILEPDF').$content)},
"headers": {
"Content-Disposition": "form-data; name:claimScanPDF; filename=#{triggerBody()?['FileNamePDF']}"
}
},
{
"body": #{concat(body('GETFILEJSON').$content)},
"headers": {
"Content-Disposition": "form-data; name:claimScanJSON; filename=#{triggerBody()?['FileNameJSON']}"
}
}
]
}
--testboundary--
i only get generic error message in response - The requested URL was rejected. Please consult with your administrator.
Please help to understand what is the difference between postman and logic app request.

Creating invoices in bulk using NetSuite REST API

Is there a way to create multiple invoices with a single POST request to the NetSuite REST API?
The API Reference doesn't mention anything - but I'm hoping there's a way to avoid sending thousands of individual requests.
I am creating a single invoice like this (some headers have been removed):
curl --location --request POST 'https://{{COMPANY_URL}}.suitetalk.api.netsuite.com/services/rest/record/v1/invoice' \
--header 'Content-Type: application/json' \
--data-raw '{
"entity": {
"id": 46
},
"item": {
"items": [
{
"item": {
"id": 134
},
"amount": 20
}
]
}
}'

Getting "The body you sent contains an unknown key." when trying to create a Contentful entry

I have created a contentful model called "User" with two fields:
id - text, unique, required
email - text, optional
When I try to create a new entry via content management API using these parameters:
Headers:
X-Contentful-Content-Type : user
Content-Type : application/vnd.contentful.management.v1+json
Method
PUT
URL
https://api.contentful.com/spaces/qilo7tiaixh8/environments/entries/
Body:
{
"id":"whatever",
"email": "peter#petervukovic.com"
}
I get the following error:
{
"requestId": "2849bbcd7ee0486bb36b47927071f37b",
"sys": {
"type": "Error",
"id": "UnknownKey"
},
"message": "The body you sent contains an unknown key.",
"details": {
"errors": [
{
"keys": [
"id",
"email"
]
}
]
}
}
I have no idea what I'm doing wrong as the examples in the official documentation aren't helpful (they assume multi-lingual content I'm not using) and there are no debugging hints.
Contentful DevRel here. 👋
I just tried it and the following CURL works for me on a user content type that defines a title field.
curl --include \
--request PUT \
--header 'Authorization: Bearer ...' \
--header 'Content-Type: application/vnd.contentful.management.v1+json' \
--header 'X-Contentful-Content-Type: user' \
--data-binary '{
"fields": {
"title": {
"en-US": "Hello Test"
}
}
}' \
https://api.contentful.com/spaces/.../environments/master/entries/\test-1
It looks like you were missing to include the fields property in your payload. About the localization part, I think it's required to provide the locale for your field values. So in my example, en-US is the default value and it is required.
For using PUT you have to define or come up with an entry id.
To create an entry without passing and defining an id have a look at the docs in Entry collection.
curl --include \
--request POST \
--header 'Authorization: Bearer ...' \
--header 'Content-Type: application/vnd.contentful.management.v1+json' \
--header 'X-Contentful-Content-Type: user' \
--data-binary '{
"fields": {
"title": {
"en-US": "Hello Test 2"
}
}
}' \
https://api.contentful.com/spaces/.../environments/master/entries/

Resources