Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2 Api] Basic changes required for api v2 to work #19

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

tobya
Copy link
Contributor

@tobya tobya commented Jul 20, 2024

This is a first go at a V2 upgrade of the library. @wivern-co-uk

This is the basic changes I needed to make to ensure that the V2 api works with my code. There may be things in the existing code that are broken that I have missed as my code doesnt touch them.

I have put some comments in the code on things that I am looking for feedback on (feedback on anything else is also welcomed)

Updates

Basically I have made the following updates

  • Endpoint has been changed.
  • Changed any relevant field names that are in the code eg _draft to isDraft
  • Create and Update item fields changed to fieldData
  • Some function parameter types changed to mixed
  • error parse code updated to new fields.
  • Added publishItem which allows a collection item to be published rather than entire site.

Issues

  • If library is released it should be released at a new Major version as it will break existing installations.
  • Non library code needs to be changed quite substantially, the layout of data returned from webflow has changed. eg Data I think used to be returned a root eg
{
  id: 12345abcdef
  name: 'this is the name'
  otherfields : 'otehr fields'
}

now the structure is

{
  id: 12345abcdef
fieldData: {
  name: 'this is the name'
  otherfields : 'otehr fields'
}
}

Setup

In order to use the V2 library you simply need to go to webflow and generate a new V2 api key and use that.

User will need to make some changes to their own code in structure and field names.

Changes

Some notes on what moving to V2 means for people with codebases. These are notes based on my experience and probably not comprehensive.

https://docs.developers.webflow.com/data/changelog/webflow-api-changed-endpoints

Field Names

  • Any field name that begins with _ has been changed.
  • All fields are now camelCase
  • Field data is now one level down below fieldData property.

Methods

Retrieving Items

$webflow->itemsAll($collectionId);
$webflow->item($collectionId, $itemId);

now return a differnt structure. Meta data is at the top level and the fields are one level below in a fieldData property. This will require changes to client code.

Publish Site

Publish site used to require that you passed an array containing a sub array 'domains' this has now changed and it just requires the user to pass a list of domain strings or domain ids

Publish Item

This is a new api end point for V2 and allows items in collections to be published without publishing the entire site.

if (isset($json->code) && isset($json->message)) {
$error = $json->message;
if (isset($json->details)) {
$error .= PHP_EOL . $json->code . ': ' . implode(PHP_EOL, $json->details) ;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to ensure that implode(PHP_EOL, $json->details) will work when details has info. I didnt get these errors.

}
throw new \Exception($error, $json->code);
throw new \Exception($error);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new json->code is a string not a number, do we want to pick an error code to return?

];
$data = (object) [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This little bit of code could probably be a little more compact

@tobya tobya changed the title Basic changes required for api v2 to work [V2 Api] Basic changes required for api v2 to work Jul 20, 2024
@wivern-co-uk
Copy link
Contributor

Thanks for filing a PR @tobya

What you think is missed to remove Draft status?

However I'll manage to check it only at the end of next week.

@tobya
Copy link
Contributor Author

tobya commented Jul 22, 2024

I think most of the basic changes are there. I would like someone else to test it a little :)

I have only used it for my requirements so there may be stuff missed.

@tobya tobya marked this pull request as ready for review July 22, 2024 06:53
@tobya
Copy link
Contributor Author

tobya commented Jul 22, 2024

Webflow support replied to me in reference to the sitepublish issue so I'll test out that fix and push.

@tobya tobya mentioned this pull request Jul 23, 2024
@tobya
Copy link
Contributor Author

tobya commented Jul 28, 2024

@wivern-co-uk I'm using this now in my own code to connect via Webflow Api V2 and it seems to be working fine. So it can probably be merged.

Any additional testing by you or other users would be good.

@wivern-co-uk
Copy link
Contributor

Any additional testing by you or other users would be good.

Sounds good, I'll let you know once there is a feedback on testing.

@tobya
Copy link
Contributor Author

tobya commented Aug 7, 2024

This seems to be working fine on my project on v2 so you can merge it if you wish to see if anyone else is looking for v2 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants